Exception on AnalyzeInterference

Exception on AnalyzeInterference

Anonymous
Not applicable
757 Views
7 Replies
Message 1 of 8

Exception on AnalyzeInterference

Anonymous
Not applicable

Hi,

 

Just going through this and the below line is causing an exception in the tryAnalizeInterference method. I have put a counter and up to 5 objects no issues however beyond 5 it trips with the following exception.. Any idea what might be causing it?

 

Exception thrown: 'System.Runtime.InteropServices.COMException' in mscorlib.dll
DebugPluginLocally2.exe Error: 0 : Processing failed. System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor.AssemblyComponentDefinition.AnalyzeInterference(ObjectCollection Set1, Object Set2)
   at SamplePlugin1.SampleAutomation.tryAnalizeInterference(Document doc, NameValueMap map) 

 

adoc.ComponentDefinition.AnalyzeInterference(objs);
 private void tryAnalizeInterference(Document doc, NameValueMap map=null)
                {
                        LogTrace("Processing " + doc.FullFileName);

                        try
                        {
                                if (doc.DocumentType != DocumentTypeEnum.kAssemblyDocumentObject) return;

                                var objs = _app.TransientObjects.CreateObjectCollection();

                                foreach (var item in doc.SelectSet)
                                {
                                        if (item is ComponentOccurrence co) objs.Add(co);
                                }

                                var adoc = doc as AssemblyDocument;

                                if (adoc == null) return;

                                if (objs.Count == 0)
                                {
                                        var count = 0;

                                        foreach (var item in adoc.ComponentDefinition.Occurrences)
                                        {
                                                if (item is ComponentOccurrence co)
                                                {
                                                        objs.Add(item);
                                                        LogTrace($"count={count},       {co.Name}");
                                                        count++;
                                                }

                                                if (count > 200) break;
                                        }
                                }

                                var interfs = adoc.ComponentDefinition.AnalyzeInterference(objs);

                                if (interfs.Count == 0) return;

                                var hs1 = adoc.HighlightSets.Add();
                                hs1.Color = _app.TransientObjects.CreateColor(255, 0, 0);

                                var hs2 = adoc.HighlightSets.Add();
                                hs2.Color = _app.TransientObjects.CreateColor(0, 255, 0);

                                foreach (var interf in interfs)
                                {
                                        hs1.Clear();
                                        hs2.Clear();

                                        hs1.AddItem(interf);
                                }
                        }
                        catch (Exception e)
                        {
                                LogError("Processing failed. " + e);
                        }
                }
0 Likes
Accepted solutions (1)
758 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

I have tested the code below with the latest samples from here and the exception is only relevant to the 'InkJet printer' assembly where it has about 115 component occurences. Tried with other assysand no issues thus far but the other only have less than 21 compoccurs...

So it seems the issue is with the inkjet printer assy, unfortunately i dont have the source code to step in to 😞

 

private void tryAnalizeInterference(Document doc, NameValueMap map=null)
{
        LogTrace("Processing " + doc.FullFileName);

        try
        {
                if (doc.DocumentType != DocumentTypeEnum.kAssemblyDocumentObject) return;

                var objs = _app.TransientObjects.CreateObjectCollection();

                foreach (var item in doc.SelectSet)
                {
                        if (item is ComponentOccurrence co) objs.Add(co);
                }

                var adoc = doc as AssemblyDocument;

                if (adoc == null) return;

                if (objs.Count == 0)
                {
                        var count = 0;

                        foreach (var item in adoc.ComponentDefinition.Occurrences)
                        {
                                if (item is ComponentOccurrence co)
                                {
                                        objs.Add(item);
                                        LogTrace($"count={count},       {co.Name}");
                                        count++;
                                }

                                if (count > 200) break;
                        }
                }

                var interfs = adoc.ComponentDefinition.AnalyzeInterference(objs);

                if (interfs.Count == 0) return;

                var hs1 = adoc.HighlightSets.Add();
                hs1.Color = _app.TransientObjects.CreateColor(255, 0, 0);

                var hs2 = adoc.HighlightSets.Add();
                hs2.Color = _app.TransientObjects.CreateColor(0, 255, 0);

                foreach (var interf in interfs)
                {
                        var item = interf as InterferenceResult;

                        hs1.AddItem(item.OccurrenceOne);
                        hs2.AddItem(item.OccurrenceTwo);
                }
        }
        catch (Exception e)
        {
                LogError("Processing failed. " + e);
        }
}

 

0 Likes
Message 3 of 8

Anonymous
Not applicable

The code below was tested against the latest samples from here. It seems only the Inkjet printer assembly is causing the exception. What exactly is causing it?

private void tryAnalizeInterference(Document doc, NameValueMap map=null)
{
        LogTrace("Processing " + doc.FullFileName);

        try
        {
                if (doc.DocumentType != DocumentTypeEnum.kAssemblyDocumentObject) return;

                var objs = _app.TransientObjects.CreateObjectCollection();

                foreach (var item in doc.SelectSet)
                {
                        if (item is ComponentOccurrence co) objs.Add(co);
                }

                var adoc = doc as AssemblyDocument;

                if (adoc == null) return;

                if (objs.Count == 0)
                {
                        var count = 0;

                        foreach (var item in adoc.ComponentDefinition.Occurrences)
                        {
                                if (item is ComponentOccurrence co)
                                {
                                        objs.Add(item);
                                        LogTrace($"count={count},       {co.Name}");
                                        count++;
                                }

                                if (count > 200) break;
                        }
                }

                var interfs = adoc.ComponentDefinition.AnalyzeInterference(objs);

                if (interfs.Count == 0) return;

                var hs1 = adoc.HighlightSets.Add();
                hs1.Color = _app.TransientObjects.CreateColor(255, 0, 0);

                var hs2 = adoc.HighlightSets.Add();
                hs2.Color = _app.TransientObjects.CreateColor(0, 255, 0);

                foreach (var interf in interfs)
                {
                        var item = interf as InterferenceResult;

                        hs1.AddItem(item.OccurrenceOne);
                        hs2.AddItem(item.OccurrenceTwo);
                }
        }
        catch (Exception e)
        {
                LogError("Processing failed. " + e);
        }
}
0 Likes
Message 4 of 8

Anonymous
Not applicable

samples from here

0 Likes
Message 5 of 8

HideoYamada
Advisor
Advisor
Accepted solution

Hello,

 

I opened "Inkjet Printer Prototype.iam" and run your last code.

It doesn't cause exception.

The log output was...

 

 

Processing <<My working directory>>\Inkjet Printer Prototype\Workspace\Inkjet Printer Prototype.iam
count=0, Printer Frame:1
count=1, Main Roller:1
count=2, Cartridge Rail:1
count=3, Cartridge Stop:1
count=4, Main Roller Cap L:1
count=5, Main Roller Cap R:1

...Omission...

count=110, JIS B 1122 - C-Z ST3.5 x 13 - C - Z:1
count=111, JIS B 1122 - C-Z ST3.5 x 13 - C - Z:2
count=112, JIS B 1122 - C-Z ST3.5 x 13 - C - Z:3
count=113, JIS B 1122 - C-Z ST3.5 x 13 - C - Z:4
count=114, Paper Holder Stage 2:1

 

Is something different with you?

 

My system is...

* Windows 10 Pro ver. 1903 Japanese

* Inventor Pro 2020.1 + Japanese Language Pack

 

=====

Freeradical

 Hideo Yamada

 

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 6 of 8

HideoYamada
Advisor
Advisor

Oh, should I select something before executing the code?

=====
Freeradical
 Hideo Yamada
https://www.freeradical.jp
0 Likes
Message 7 of 8

Anonymous
Not applicable

yeah, you need to select an assembly file, or perhaps a part file, check my code mate, just finished a bottle of strong wine, so cannot pinpoint, but the issue was only with the Inkjet printer, oh yeah, iam file. down load it from the link i mentioned.

0 Likes
Message 8 of 8

Anonymous
Not applicable

Hi Hideo,

 

Thanks so much for investigating....

for some reason i didnt get a notification for your replies hence the late response!

All seems to be working well this morning on the same code and same input file however different windows session and inventor session so one of them may have cleared up the issues.

 

next time i will do those two steps before i sound the alaram.

 

thanks bud!

0 Likes