Hello, I am doing my master thesis with iLogic and i come across problem I dont know how to solve and I am really stuck. Any help would be valuable.
The idea is to copy element using data from the list (stored inputs by the client).
So i made first pattern, took last element and intended to use it for second pattern, However I am getting this error.
Error on line 101 in rule: Prvi Red_Copy_Copy_Copy, in document: Column details.iam
Unable to cast COM object of type 'System.__ComObject' to class type 'Autodesk.iLogic.Types.ComponentOrPattern'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
Does that means variable i am trying to use as element to be copied in second pattern is not correct data type? Attached is whole code and explanation what m I trying to achieve.
It would mean a lot any suggestion how this could be done, or direction how to solve problem.
Hello, I am doing my master thesis with iLogic and i come across problem I dont know how to solve and I am really stuck. Any help would be valuable.
The idea is to copy element using data from the list (stored inputs by the client).
So i made first pattern, took last element and intended to use it for second pattern, However I am getting this error.
Error on line 101 in rule: Prvi Red_Copy_Copy_Copy, in document: Column details.iam
Unable to cast COM object of type 'System.__ComObject' to class type 'Autodesk.iLogic.Types.ComponentOrPattern'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
Does that means variable i am trying to use as element to be copied in second pattern is not correct data type? Attached is whole code and explanation what m I trying to achieve.
It would mean a lot any suggestion how this could be done, or direction how to solve problem.
Hi @tm21915. Yes, you are attempting to use the wrong data type in the second position within that second 'Patterns.AddRectangular() method'. It is asking for a 'ComponentOrPattern' type object there, which is something unique to the iLogic ApplicationAddIn, but you provided a OccurrencePatternElement type object. That method itself is one that is also unique to the iLogic AddIn, and even though there is an equivalent method within Inventor's API (OccurrencePatterns.AddRectangularPattern ), it requires different types of inputs, designed to make the process easier, but that is not always the case. Your earlier line likely worked OK because a String is one of the Types that can be used as a constructor for the ComponentOrPattern type. I do not use that iLogic snippet method method that much, in favor of the API method, but you could try this 2 line edit to replace line 101 in your posted code:
oParentComps = ComponentOrPattern(Components.Item(lastElement.Occurrences.Item(1).Name))
Dim rectPattern2 = Patterns.AddRectangular("RectPatternName2", oParentComps, list(1) + 1, list(0), Nothing, "X Axis", columnNaturalDirection := True)
Using the API method may be a bit easier to understand, but may also require a few more lines of code, and actual references to objects, rather than just the String names of things.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @tm21915. Yes, you are attempting to use the wrong data type in the second position within that second 'Patterns.AddRectangular() method'. It is asking for a 'ComponentOrPattern' type object there, which is something unique to the iLogic ApplicationAddIn, but you provided a OccurrencePatternElement type object. That method itself is one that is also unique to the iLogic AddIn, and even though there is an equivalent method within Inventor's API (OccurrencePatterns.AddRectangularPattern ), it requires different types of inputs, designed to make the process easier, but that is not always the case. Your earlier line likely worked OK because a String is one of the Types that can be used as a constructor for the ComponentOrPattern type. I do not use that iLogic snippet method method that much, in favor of the API method, but you could try this 2 line edit to replace line 101 in your posted code:
oParentComps = ComponentOrPattern(Components.Item(lastElement.Occurrences.Item(1).Name))
Dim rectPattern2 = Patterns.AddRectangular("RectPatternName2", oParentComps, list(1) + 1, list(0), Nothing, "X Axis", columnNaturalDirection := True)
Using the API method may be a bit easier to understand, but may also require a few more lines of code, and actual references to objects, rather than just the String names of things.
Wesley Crihfield
(Not an Autodesk Employee)
Thank you for your response.
I m not sure I understood, If I change 101 line of code i still get Error message
Error on Line 101 : 'ComponentOrPattern' is a type and cannot be used as an expression.
Thank you for your response.
I m not sure I understood, If I change 101 line of code i still get Error message
Error on Line 101 : 'ComponentOrPattern' is a type and cannot be used as an expression.
Can't find what you're looking for? Ask the community or share your knowledge.