Variable in .Item property? Is it possible?

Variable in .Item property? Is it possible?

tm21915
Contributor Contributor
755 Views
4 Replies
Message 1 of 5

Variable in .Item property? Is it possible?

tm21915
Contributor
Contributor

Hello,

 

Is it possible to use variable when calling Item? I am getting Error "Expecting object to be local"

DO you maybe know how to solve this? Help would be really valuable

Dim patternName As String = Nothing
patternName = baseNamePattern & ":" & currentIndexPattern.ToString()
	
oDoc = ThisDoc.Document	
Dim oPattern As RectangularOccurrencePattern = oDoc.ComponentDefinition.OccurrencePatterns.Item(patternName)  

 

0 Likes
Accepted solutions (2)
756 Views
4 Replies
Replies (4)
Message 2 of 5

Andrii_Humeniuk
Advisor
Advisor

Hi @tm21915 . Yes, you can. Check whether the name of the pattern was entered correctly.

Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oPattern As RectangularOccurrencePattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("Component Pattern 1:1")
MessageBox.Show(oPattern.Name, "Title")

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 5

tm21915
Contributor
Contributor
Accepted solution

Aha thank you for reply, but in this case I am just entering string, the name of the pattern, as I understand

what I would like to do is call pattern name that variable is holding in this case variable patternName. Is that possible?

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @tm21915.  Here is the official online help page for that specific item in question.

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=OccurrencePatterns_Item 

The Item property of the OccurrencePatterns API object will accept either an Integer that represents the index of the item, or a String, representing the name of the item.  But if no item can be found with the specified index number or name, then it will throw an error.  As suggested before, you may simply have to make sure that the name you are trying to supply there is correct first.  Usually something simple like a MsgBox(), or MessageBox.Show(), or Logger.Info() line is sufficient to inform you about what the code has encountered at that point in the code.  We may have to see the whole code to be a bit more sure about what the problem might be, if the correct name is being supplied there.

For instance, we can't tell what 'baseNamePattern' or 'currentIndexPattern' represent in your code, because they are not fully defined within that bit of code.  And the 'ThisDoc' reference might possibly be pointing to the wrong document, if we were to see the whole code, especially if it was being used within a loop of other referenced documents in a much larger code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

tm21915
Contributor
Contributor

Thank you for your response and help. The problem was, since it is used in loop, variable that wasn't defined right.

 

Thank you a lot for your help 

0 Likes