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: 

Detect Component Pattern as selection or in SelectSet

3 REPLIES 3
Reply
Message 1 of 4
checkcheck_master
526 Views, 3 Replies

Detect Component Pattern as selection or in SelectSet

checkcheck_master
Advocate
Advocate

I have a (too long) iLogic rule that does several things.
One of these: The browser pane is collapsed and when a part or assembly is selected the 'find in browser' function is called for what is selected and this browser node(s) is/are expanded so that you have a direct view on the constraints.
This works fine until...
A part or assembly is part of a component pattern.
I would like to know how to detect that a component pattern is selected.
I would rather know which part or assembly is selected in the component pattern.
Is it possible to find out?

 

Below is the piece of code where we end up when the iLogic rule is activated and a selection has been made.
Here you can see that with 'GetBrowserNodeFromObject' the browser node can be found.
As already mentioned, is it also possible to determine when the selection is a component pattern?

And even better, can also be determined what is selected in the component pattern?

 

' -------------------------------------------------------------------------------------------------------------------------------------------------------------
		' When there was a selection made, highlight the selection and expand the node(s) to see the Constraints
		If ThisApplication.ActiveDocument.SelectSet.count <> 0 Then ' Something is selected
			
		' Show number of selected items in StatusBar
		ThisApplication.StatusBarText = "Selected items: " & ThisApplication.ActiveDocument.SelectSet.count
		
		'MessageBox.Show("Wait")	
			Try				
				'MessageBox.Show(ThisApplication.ActiveDocument.SelectSet.count)
				'For i = 1 To ThisApplication.ActiveDocument.SelectSet.count
				For i = ThisApplication.ActiveDocument.SelectSet.count To 1 Step -1	' In Reverse order
				
					oOcc = ThisApplication.ActiveDocument.SelectSet(i)			
													
					' Get the model browser
					Dim oPane As BrowserPane
					   	oPane = oAssemDoc.BrowserPanes.ActivePane
							
					' Get the browser node that corresponds to the occurrence
					Dim oCompo As BrowserNode
					   	oCompo = oPane.GetBrowserNodeFromObject(oOcc)
						'oCompo.Expanded = True			
						'oCompo.DoSelect						
						
					Dim oNode As BrowserNode					
					For Each oNode In oCompo.BrowserNodes
						'MessageBox.Show(oNode.FullPath)
						If oNode.FullPath.Contains("Origin") Then 'Or oNode.FullPath.Contains("Position") Then
							oNode.Expanded = False
							
							Try
								If oNode.FullPath.Contains("Position") Then	oNode.Expanded = False
							Catch
							End Try

						Else If oNode.FullPath.Contains("Folded Model") Or oNode.FullPath.Contains("Representations") Then
							
							Dim oNodeSheet As BrowserNodeDefinition
							oNodeSheet = oNode.BrowserNodeDefinition
								
						    ' Get the work plane browser node.
						    Dim oWorkPlaneNode As BrowserNode
								oWorkPlaneNode = oCompo.AllReferencedNodes(oNodeSheet).Item(1)
						    Dim oNode2 As BrowserNode
								For Each oNode2 In oWorkPlaneNode.BrowserNodes	
									Try
										If oNode2.FullPath.Contains("Origin") Then
											oNode2.Expanded = False
										End If
									Catch
									End Try
									
										Try
											If oNode2.FullPath.Contains("Position") Then
												oNode2.Expanded = False
											End If
										Catch
										End Try
										
									Try						
										If oNode2.FullPath.Contains("Folded Model") Then
											oNode.Expanded = False 'oNode! NO oNode2!
										End If
									Catch
									End Try
									
										Try	
											If oNode2.FullPath.Contains("Representations") Then
												oNode.Expanded = False 'oNode! NO oNode2!
											End If
										Catch
										End Try										
										
'''										Try
'''											If oNode2.FullPath.Contains("Model States") Then
'''												If oNode2.Visible = True Then oNode.Expanded = False 'oCompo.Expanded = False
'''											End If
'''										Catch
'''										End Try
									
								Next
						End If					
					Next
										
					'MessageBox.Show("Wait")
					
					' Expand the browser node that corresponds to the occurrence
					'MessageBox.Show(oCompo.Expanded)
					oCompo.Expanded = True
					
'''					Call ThisApplication.UserInterfaceManager.DoEvents
'''					If oCompo.Expanded = False Then
'''						Call ThisApplication.UserInterfaceManager.DoEvents
'''						oCompo.Expanded = True						
'''					ElseIf oCompo.Expanded = True Then
'''						Call ThisApplication.UserInterfaceManager.DoEvents
'''						oCompo.Expanded = False
'''					End If											
					
					'Call ThisApplication.UserInterfaceManager.DoEvents
															
					Call ThisApplication.CommandManager.ControlDefinitions.Item("AppFindInBrowserCtxCmd").Execute
				
				Next
			
			Catch			
			End Try

 

 

For completeness, the complete rule as a txt file.
Note that the rule interacts with another iLogic rule and a vba piece of code due to a bug in IV2022.
So I don't think it can be tested directly.

0 Likes

Detect Component Pattern as selection or in SelectSet

I have a (too long) iLogic rule that does several things.
One of these: The browser pane is collapsed and when a part or assembly is selected the 'find in browser' function is called for what is selected and this browser node(s) is/are expanded so that you have a direct view on the constraints.
This works fine until...
A part or assembly is part of a component pattern.
I would like to know how to detect that a component pattern is selected.
I would rather know which part or assembly is selected in the component pattern.
Is it possible to find out?

 

Below is the piece of code where we end up when the iLogic rule is activated and a selection has been made.
Here you can see that with 'GetBrowserNodeFromObject' the browser node can be found.
As already mentioned, is it also possible to determine when the selection is a component pattern?

And even better, can also be determined what is selected in the component pattern?

 

' -------------------------------------------------------------------------------------------------------------------------------------------------------------
		' When there was a selection made, highlight the selection and expand the node(s) to see the Constraints
		If ThisApplication.ActiveDocument.SelectSet.count <> 0 Then ' Something is selected
			
		' Show number of selected items in StatusBar
		ThisApplication.StatusBarText = "Selected items: " & ThisApplication.ActiveDocument.SelectSet.count
		
		'MessageBox.Show("Wait")	
			Try				
				'MessageBox.Show(ThisApplication.ActiveDocument.SelectSet.count)
				'For i = 1 To ThisApplication.ActiveDocument.SelectSet.count
				For i = ThisApplication.ActiveDocument.SelectSet.count To 1 Step -1	' In Reverse order
				
					oOcc = ThisApplication.ActiveDocument.SelectSet(i)			
													
					' Get the model browser
					Dim oPane As BrowserPane
					   	oPane = oAssemDoc.BrowserPanes.ActivePane
							
					' Get the browser node that corresponds to the occurrence
					Dim oCompo As BrowserNode
					   	oCompo = oPane.GetBrowserNodeFromObject(oOcc)
						'oCompo.Expanded = True			
						'oCompo.DoSelect						
						
					Dim oNode As BrowserNode					
					For Each oNode In oCompo.BrowserNodes
						'MessageBox.Show(oNode.FullPath)
						If oNode.FullPath.Contains("Origin") Then 'Or oNode.FullPath.Contains("Position") Then
							oNode.Expanded = False
							
							Try
								If oNode.FullPath.Contains("Position") Then	oNode.Expanded = False
							Catch
							End Try

						Else If oNode.FullPath.Contains("Folded Model") Or oNode.FullPath.Contains("Representations") Then
							
							Dim oNodeSheet As BrowserNodeDefinition
							oNodeSheet = oNode.BrowserNodeDefinition
								
						    ' Get the work plane browser node.
						    Dim oWorkPlaneNode As BrowserNode
								oWorkPlaneNode = oCompo.AllReferencedNodes(oNodeSheet).Item(1)
						    Dim oNode2 As BrowserNode
								For Each oNode2 In oWorkPlaneNode.BrowserNodes	
									Try
										If oNode2.FullPath.Contains("Origin") Then
											oNode2.Expanded = False
										End If
									Catch
									End Try
									
										Try
											If oNode2.FullPath.Contains("Position") Then
												oNode2.Expanded = False
											End If
										Catch
										End Try
										
									Try						
										If oNode2.FullPath.Contains("Folded Model") Then
											oNode.Expanded = False 'oNode! NO oNode2!
										End If
									Catch
									End Try
									
										Try	
											If oNode2.FullPath.Contains("Representations") Then
												oNode.Expanded = False 'oNode! NO oNode2!
											End If
										Catch
										End Try										
										
'''										Try
'''											If oNode2.FullPath.Contains("Model States") Then
'''												If oNode2.Visible = True Then oNode.Expanded = False 'oCompo.Expanded = False
'''											End If
'''										Catch
'''										End Try
									
								Next
						End If					
					Next
										
					'MessageBox.Show("Wait")
					
					' Expand the browser node that corresponds to the occurrence
					'MessageBox.Show(oCompo.Expanded)
					oCompo.Expanded = True
					
'''					Call ThisApplication.UserInterfaceManager.DoEvents
'''					If oCompo.Expanded = False Then
'''						Call ThisApplication.UserInterfaceManager.DoEvents
'''						oCompo.Expanded = True						
'''					ElseIf oCompo.Expanded = True Then
'''						Call ThisApplication.UserInterfaceManager.DoEvents
'''						oCompo.Expanded = False
'''					End If											
					
					'Call ThisApplication.UserInterfaceManager.DoEvents
															
					Call ThisApplication.CommandManager.ControlDefinitions.Item("AppFindInBrowserCtxCmd").Execute
				
				Next
			
			Catch			
			End Try

 

 

For completeness, the complete rule as a txt file.
Note that the rule interacts with another iLogic rule and a vba piece of code due to a bug in IV2022.
So I don't think it can be tested directly.

Labels (4)
3 REPLIES 3
Message 2 of 4

Ralf_Krieg
Advisor
Advisor

Hello

 

You can check if your SelectedItem.Type is kRectangularOccurrencePatternObject/kCircularOccurrencePatternObject.

If you select a part in your pattern, your SelectedItem should be of type kComponentOccurrence. If you get an kComponentOccurenceProxy, your selected Part is in a subassembly and you have to traverse up the SelectedItem.ParentOccurrence object until you get a kComponentOccurrenceObject. Then you can check the IsPatternElement property. If True, your selected part is in a pattern.

 


R. Krieg
RKW Solutions GmbH
www.rkw-solutions.com
0 Likes

Hello

 

You can check if your SelectedItem.Type is kRectangularOccurrencePatternObject/kCircularOccurrencePatternObject.

If you select a part in your pattern, your SelectedItem should be of type kComponentOccurrence. If you get an kComponentOccurenceProxy, your selected Part is in a subassembly and you have to traverse up the SelectedItem.ParentOccurrence object until you get a kComponentOccurrenceObject. Then you can check the IsPatternElement property. If True, your selected part is in a pattern.

 


R. Krieg
RKW Solutions GmbH
www.rkw-solutions.com
Message 3 of 4

checkcheck_master
Advocate
Advocate

Thank you Krieg for your message and explanation.
I'll try and see if I can get this in.

0 Likes

Thank you Krieg for your message and explanation.
I'll try and see if I can get this in.

Message 4 of 4

checkcheck_master
Advocate
Advocate

@Anonymous
See code/screenshot, this is what I made of it.
Works well, the pattern is highlighted and expands when something in a pattern is selected.
Seems logical to me, but just to be sure, to be able to select a part I have to switch to Part Priority, right?
In other words, when a part or sub-assembly in a pattern is selected in Component Priority, Inventor does not yet know which part or sub-assembly is selected?

 

' -----------------------------------------------------------------------------------------
						' When the selected sub-assy is in a (Component) Pattern
						Dim oSelItem As Object
						oSelItem = ThisApplication.ActiveDocument.SelectSet(i)
						'MessageBox.Show("Here: " & oSelItem.type.tostring)
						
						' Get the model browser
						Dim oPaneTemp As BrowserPane
					   	oPaneTemp = oAssemDoc.BrowserPanes.ActivePane
						
						' Get the browser node that corresponds to the occurrence
						Dim oCompoTemp As BrowserNode
					   	oCompoTemp = oPaneTemp.GetBrowserNodeFromObject(oSelItem)
						oCompoTemp.Expanded = True			
						oCompoTemp.DoSelect		
						
						Call ThisApplication.CommandManager.ControlDefinitions.Item("AppFindInBrowserCtxCmd").Execute
						'MessageBox.Show("Here") 

 

0 Likes

@Anonymous
See code/screenshot, this is what I made of it.
Works well, the pattern is highlighted and expands when something in a pattern is selected.
Seems logical to me, but just to be sure, to be able to select a part I have to switch to Part Priority, right?
In other words, when a part or sub-assembly in a pattern is selected in Component Priority, Inventor does not yet know which part or sub-assembly is selected?

 

' -----------------------------------------------------------------------------------------
						' When the selected sub-assy is in a (Component) Pattern
						Dim oSelItem As Object
						oSelItem = ThisApplication.ActiveDocument.SelectSet(i)
						'MessageBox.Show("Here: " & oSelItem.type.tostring)
						
						' Get the model browser
						Dim oPaneTemp As BrowserPane
					   	oPaneTemp = oAssemDoc.BrowserPanes.ActivePane
						
						' Get the browser node that corresponds to the occurrence
						Dim oCompoTemp As BrowserNode
					   	oCompoTemp = oPaneTemp.GetBrowserNodeFromObject(oSelItem)
						oCompoTemp.Expanded = True			
						oCompoTemp.DoSelect		
						
						Call ThisApplication.CommandManager.ControlDefinitions.Item("AppFindInBrowserCtxCmd").Execute
						'MessageBox.Show("Here") 

 

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

Post to forums  

Autodesk Design & Make Report