Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using last element of pattern as a Component for the next pattern

2 REPLIES 2
Reply
Message 1 of 3
tm21915
236 Views, 2 Replies

Using last element of pattern as a Component for the next pattern

tm21915
Contributor
Contributor

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.

 

 

 

 

0 Likes

Using last element of pattern as a Component for the next pattern

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.

 

 

 

 

2 REPLIES 2
Message 2 of 3
WCrihfield
in reply to: tm21915

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes

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

EESignature

(Not an Autodesk Employee)

Message 3 of 3
tm21915
in reply to: WCrihfield

tm21915
Contributor
Contributor

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.

0 Likes

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.

Post to forums  

Autodesk Design & Make Report