Does anyone know how you would get a list of which parts in assembly are being paired together with an iMate?
I've got this code to list them out, but I want to be able to see that I've got one iMate matched up for the one housing, but that i then need to import 5x more of the part to fill up all the iMates... but I can't tell what's being consumed or not.
Dim oAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition = oAssyDoc.ComponentDefinition
Dim oOcc As ComponentOccurrence
Dim ICount As Integer
'strip color overrides at the assembly level
For Each oOcc In oAsmCompDef.Occurrences
ICount = oOcc.iMateDefinitions.Count
Logger.Info("Component Name: {0} || {1}", oOcc.Name, ICount)
For i = 1 To ICount
Logger.Info("iMate ReferenceComponent: {0}", oOcc.iMateDefinitions.Item(i).ReferenceComponent)
Logger.Info("iMate Name: {0}", oOcc.iMateDefinitions.Item(i).Name)
Next
Logger.Info("")
Next
Logger.Info("Assy iMate Name: {0}", oAssyDoc.ComponentDefinition.iMateDefinitions.Item(1).Name)
Solved! Go to Solution.
Solved by Michael.Navara. Go to Solution.
Get information if the iMate is used or not is relatively easy, but there is small inconvenience.
You can use IsConsumed property of the iMate definition object.
Dim oAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAsmCompDef As AssemblyComponentDefinition = oAssyDoc.ComponentDefinition
Dim oOcc As ComponentOccurrence
Dim ICount As Integer
'strip color overrides at the assembly level
For Each oOcc In oAsmCompDef.Occurrences
ICount = oOcc.iMateDefinitions.Count
Logger.Info("Component Name: {0} || {1}", oOcc.Name, ICount)
For i = 1 To ICount
Logger.Info("iMate ReferenceComponent: {0}", oOcc.iMateDefinitions.Item(i).ReferenceComponent)
Logger.Info("iMate Name: {0}", oOcc.iMateDefinitions.Item(i).Name)
Logger.Info("iMate is used {0}", oOcc.iMateDefinitions(i).IsConsumed) ' Not recognized by IntelliSense
Next
Logger.Info("")
Next
Logger.Info("Assy iMate Name: {0}", oAssyDoc.ComponentDefinition.iMateDefinitions.Item(1).Name)
Explanation:
What do you really get from oOcc.iMateDefinitions are proxy representations of iMateDefinitions, not the original definitions defined in the part. Every proxy representation of iMate has IsConsumed property, but IntelliSense can't recognize it.
That should get me what I need to finish up the tool I'm building. Thanks! 😁
Just out of curiosity, WHY would Intellisense not recognize it as a property that can be accessed on the iMateDefinition?? Is it a bug?
No this is not a bug.
It is because in .NET (underlying framework for iLogic) every class (DerivedClass) can be inherited only from one parent class (BaseClass). Every DerivedClass has all properties and methods as the BaseClass and can add more.
In this case the inheritance looks as follows:
iMateDefinition
-> InsertiMateDefinition
-> InsertiMateDefinitionProxy
-> MateiMateDefinition
-> MateiMateDefinitionProxy
... and so on
There is no class, which can be used as a BaseClass for this proxy iMateDefinitions and can declare method IsConsumed. This is why the IntelliSense can't recognize this method.
In general it can be declared in interface and can be implemented in derived classes, but this is another story and it depends on how the COM Interop is generated.
But in this case you can use capability of VB.NET (iLogic) compiler. This compiler is not too strict (vs C# for example) and allows you to write method name and its arguments and compile it as late-binding. At runtime the framework looks for the method of given name which can accept given parameters and try to execute it. If the method exists it works, but if not, runtime exception is thrown.
Can't find what you're looking for? Ask the community or share your knowledge.