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: 

Browser item order error

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
488 Views, 4 Replies

Browser item order error

Anonymous
Not applicable

I am using iLogic to find a part based on it's location in the Browser using the following code:

ThisDoc.Document.ComponentDefinition.Occurrences.Item(2).Name

 This has worked well until I attempted to use it in my current assembly. The order of the browser items behave as if they are static. If I move the item up or down the Browser list it remains the same item number. Has anyone ran into this issue?

0 Likes

Browser item order error

I am using iLogic to find a part based on it's location in the Browser using the following code:

ThisDoc.Document.ComponentDefinition.Occurrences.Item(2).Name

 This has worked well until I attempted to use it in my current assembly. The order of the browser items behave as if they are static. If I move the item up or down the Browser list it remains the same item number. Has anyone ran into this issue?

4 REPLIES 4
Message 2 of 5
clutsa
in reply to: Anonymous

clutsa
Collaborator
Collaborator

What are you trying to accomplish with your code? What you're calling an issue other's may not. If you know the name of the part you're looking for you could use

partVar = ThisDoc.Document.ComponentDefinition.Occurrences.Itembyname("NameHere")

I think you're looking to do something like this

Dim doc = ThisDoc.Document
Dim BrowserPane = doc.BrowserPanes("Model")
Dim TopNode = BrowserPane.TopNode
Dim topComp As ComponentOccurrence
EndFound = False
For Each node In TopNode.BrowserNodes
	If EndFound = True Then 
		'MessageBox.Show(node.BrowserNodeDefinition.Label, "Title")
		topComp = doc.ComponentDefinition.Occurrences.ItemByName(node.BrowserNodeDefinition.Label)
		Exit For
	End If
	If node.BrowserNodeDefinition.Label = "End of Features" Then EndFound = True
Next
If Not topComp Is Nothing Then MessageBox.Show("TopComp = " & topComp.Name, "Title")
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State
0 Likes

What are you trying to accomplish with your code? What you're calling an issue other's may not. If you know the name of the part you're looking for you could use

partVar = ThisDoc.Document.ComponentDefinition.Occurrences.Itembyname("NameHere")

I think you're looking to do something like this

Dim doc = ThisDoc.Document
Dim BrowserPane = doc.BrowserPanes("Model")
Dim TopNode = BrowserPane.TopNode
Dim topComp As ComponentOccurrence
EndFound = False
For Each node In TopNode.BrowserNodes
	If EndFound = True Then 
		'MessageBox.Show(node.BrowserNodeDefinition.Label, "Title")
		topComp = doc.ComponentDefinition.Occurrences.ItemByName(node.BrowserNodeDefinition.Label)
		Exit For
	End If
	If node.BrowserNodeDefinition.Label = "End of Features" Then EndFound = True
Next
If Not topComp Is Nothing Then MessageBox.Show("TopComp = " & topComp.Name, "Title")
If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State
Message 3 of 5
Anonymous
in reply to: clutsa

Anonymous
Not applicable

Thanks Clusta. 

I am using iLogic to suppress parts/assemblies, create custom ilogic parts, and changing members in iPart/iAssemblies.  The method I was originally using to locate parts/assemblies in the model was to first “Normalize” the name in the assembly Browser.  This allowed the  code to search for a static name in the assembly. However our document management software does not allow that. It syncs the Bowser Name to a concatenation of the Part number and Description. So now I am searching be location in the Browser (My_Variable#) to get the parts Browser Name:

My_Variable3 = ThisDoc.Document.ComponentDefinition.Occurrences.Item(3).Name

If(Parameter("AIR_INLET") = "3 OCLOCK" Or Parameter("AIR_INLET") = "6 OCLOCK")
    i = iPart.FindRow(My_Variable3, "Part Number", "=", 101034182)
    Parameter("GAS_VALVE_POSITION") = 0

Else
    i = iPart.FindRow(My_Variable3, "Part Number", "=", 101034183)
    Parameter("GAS_VALVE_POSITION") = 180
    
End If

The problem is the Browser list somehow became static (now out of order). I may have used the "Alpha Sort Component" located in the Productivity Tab in the past. Not the ideal fix, but I demoted all the parts to a new assembly and not the Browser list order is correct.

When I ran your second code in the model with the "Browser Order Issue" I received the follow error:

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)). In another model that is working fine I do not receive an error. Not sure why it behaves that way.

0 Likes

Thanks Clusta. 

I am using iLogic to suppress parts/assemblies, create custom ilogic parts, and changing members in iPart/iAssemblies.  The method I was originally using to locate parts/assemblies in the model was to first “Normalize” the name in the assembly Browser.  This allowed the  code to search for a static name in the assembly. However our document management software does not allow that. It syncs the Bowser Name to a concatenation of the Part number and Description. So now I am searching be location in the Browser (My_Variable#) to get the parts Browser Name:

My_Variable3 = ThisDoc.Document.ComponentDefinition.Occurrences.Item(3).Name

If(Parameter("AIR_INLET") = "3 OCLOCK" Or Parameter("AIR_INLET") = "6 OCLOCK")
    i = iPart.FindRow(My_Variable3, "Part Number", "=", 101034182)
    Parameter("GAS_VALVE_POSITION") = 0

Else
    i = iPart.FindRow(My_Variable3, "Part Number", "=", 101034183)
    Parameter("GAS_VALVE_POSITION") = 180
    
End If

The problem is the Browser list somehow became static (now out of order). I may have used the "Alpha Sort Component" located in the Productivity Tab in the past. Not the ideal fix, but I demoted all the parts to a new assembly and not the Browser list order is correct.

When I ran your second code in the model with the "Browser Order Issue" I received the follow error:

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)). In another model that is working fine I do not receive an error. Not sure why it behaves that way.

Message 4 of 5
clutsa
in reply to: Anonymous

clutsa
Collaborator
Collaborator

My second code was just grabbing the first thing in the browser after the standard nodes. I got the same error when I moved my first part and that made a folder the node object. 

In the assembly with an issue what is the first node in the browser after either the origin folder or the end of feature node?  (weldment, regular part, virtual component, folder...)

Picture of the browser might be helpful if it's not to much hassle.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State
0 Likes

My second code was just grabbing the first thing in the browser after the standard nodes. I got the same error when I moved my first part and that made a folder the node object. 

In the assembly with an issue what is the first node in the browser after either the origin folder or the end of feature node?  (weldment, regular part, virtual component, folder...)

Picture of the browser might be helpful if it's not to much hassle.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State
Message 5 of 5
clutsa
in reply to: Anonymous

clutsa
Collaborator
Collaborator
Dim doc = ThisDoc.Document
Dim BrowserPane = doc.BrowserPanes("Model")
Dim TopNode = BrowserPane.TopNode
Dim iPartComp As ComponentOccurrence
EndFound = False
For Each node In TopNode.BrowserNodes
	If node.BrowserNodeDefinition.Label = "101034182" Or node.BrowserNodeDefinition.Label = "101034183" Then EndFound = True 'change labels as required
	If EndFound = True Then 
		'MessageBox.Show(node.BrowserNodeDefinition.Label, "Title")
		iPartComp = doc.ComponentDefinition.Occurrences.ItemByName(node.BrowserNodeDefinition.Label)
		Exit For
	End If
Next
If Not iPartComp Is Nothing Then MessageBox.Show("iPartComp = " & iPartComp.Name, "Title")

Small change to my first code. So here I'm looking for one of two names and grabbing that part.... don't know that I need to be doing this from the browser anymore. You could do the same kind of loop in the Occurrences you listed the first time.

 

if you have a ton of parts your iPart could become, you may even be able to go with...

Dim doc = ThisDoc.Document
Dim BrowserPane = doc.BrowserPanes("Model")
Dim TopNode = BrowserPane.TopNode
Dim iPartComp As ComponentOccurrence
EndFound = False
For Each node In TopNode.BrowserNodes
	If node.BrowserNodeDefinition.Label Like "101034*" Then EndFound = True 'change labels as required
	If EndFound = True Then 
		'MessageBox.Show(node.BrowserNodeDefinition.Label, "Title")
		iPartComp = doc.ComponentDefinition.Occurrences.ItemByName(node.BrowserNodeDefinition.Label)
		Exit For
	End If
Next
If Not iPartComp Is Nothing Then MessageBox.Show("iPartComp = " & iPartComp.Name, "Title")

(I don't know your part numbering scheme so maybe not)

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State
0 Likes

Dim doc = ThisDoc.Document
Dim BrowserPane = doc.BrowserPanes("Model")
Dim TopNode = BrowserPane.TopNode
Dim iPartComp As ComponentOccurrence
EndFound = False
For Each node In TopNode.BrowserNodes
	If node.BrowserNodeDefinition.Label = "101034182" Or node.BrowserNodeDefinition.Label = "101034183" Then EndFound = True 'change labels as required
	If EndFound = True Then 
		'MessageBox.Show(node.BrowserNodeDefinition.Label, "Title")
		iPartComp = doc.ComponentDefinition.Occurrences.ItemByName(node.BrowserNodeDefinition.Label)
		Exit For
	End If
Next
If Not iPartComp Is Nothing Then MessageBox.Show("iPartComp = " & iPartComp.Name, "Title")

Small change to my first code. So here I'm looking for one of two names and grabbing that part.... don't know that I need to be doing this from the browser anymore. You could do the same kind of loop in the Occurrences you listed the first time.

 

if you have a ton of parts your iPart could become, you may even be able to go with...

Dim doc = ThisDoc.Document
Dim BrowserPane = doc.BrowserPanes("Model")
Dim TopNode = BrowserPane.TopNode
Dim iPartComp As ComponentOccurrence
EndFound = False
For Each node In TopNode.BrowserNodes
	If node.BrowserNodeDefinition.Label Like "101034*" Then EndFound = True 'change labels as required
	If EndFound = True Then 
		'MessageBox.Show(node.BrowserNodeDefinition.Label, "Title")
		iPartComp = doc.ComponentDefinition.Occurrences.ItemByName(node.BrowserNodeDefinition.Label)
		Exit For
	End If
Next
If Not iPartComp Is Nothing Then MessageBox.Show("iPartComp = " & iPartComp.Name, "Title")

(I don't know your part numbering scheme so maybe not)

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report