Running a command on T&P Add-in Occurrence in Drawing

Running a command on T&P Add-in Occurrence in Drawing

A.Acheson
Mentor Mentor
4,138 Views
20 Replies
Message 1 of 21

Running a command on T&P Add-in Occurrence in Drawing

A.Acheson
Mentor
Mentor

Is it possible to run a command on specific assembly occurrences in the drawing environment.

 

Using the add-in Tube and pipe. If you right click on the Run assembly occurrence in the browser you are presented with a command “Include Route Centerlines”

I placed this snippet

 

(ThisApplication.CommandManager.ControlDefinitions(“CADC:Drawing:CenterlineRecoveryChecked”).Execute)

 

at the point where the loop found the Occurrence.
Using this method the button is not triggered.

 

 I am guessing this is the case because the command manager is trying to act on the whole drawing and not on the specific Occurrences.  Is there a method to do this?.

 

Commands:

Include Route Centerlines - CADC:Drawing:CenterlineRecoveryChecked
Include Route Centerlines - CADC:Drawing:CenterlineRecoveryTriState
Include Route Centerlines - CADC:Drawing:CenterlineRecoveryUnchecked

Resources used.

https://modthemachine.typepad.com/my_weblog/2009/03/running-commands-using-the-api.html

 

 

Any help greatly appreciated.

 

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
4,139 Views
20 Replies
Replies (20)
Message 21 of 21

Seemed like it was the Browser that made my problems my final uptate if any body are interested:

 

'Error with clicking vs select set
'https://forums.autodesk.com/t5/inventor-customization/what-is-the-difference-between-selectset-select-and-clicking-on/td-p/9249928
Class ShowCenters
	Dim ShowLines As Boolean =True
Sub Main
	'Need to expand the browser to find the tube runs
	ThisApplication.CommandManager.ControlDefinitions.Item("AppBrowserExpandAllCmd").Execute
	Dim que As MsgBoxResult = MsgBox("Show Center Lines",vbYesNo,"Select")
	If que = vbYes Then
		ShowLines=True
		Else
			ShowLines=False
		End If
	If Not TypeOf ThisApplication.ActiveDocument Is DrawingDocument Then
		MsgBox("Open a drawing document first")
		Exit Sub
	End If
	
	Dim doc As DrawingDocument
	doc = ThisApplication.ActiveDocument
	doc.SelectSet.Clear
	Dim bp As BrowserPane = doc.BrowserPanes("Model")
	
    Call GetRouteBrowserNodes(bp.GetBrowserNodeFromObject(doc.ActiveSheet).BrowserNodes) 'only touch active sheet.
    Call GetRunBrowserNodes(bp.GetBrowserNodeFromObject(doc.ActiveSheet).BrowserNodes)
'[	
'	'ThisApplication.CommandManager.ControlDefinitions.Item("AppBrowserCollapseAllCmd").Execute2(True)
'	  For Each obj As BrowserNode In tosel
'		Dim n As BrowserNode = obj
'		While n.Parent.Type = obj.Type
'			n = n.Parent
'			n.Expanded = True 
'		End While
'		obj.DoPreSelect
'		'Attempt to activate the context menu by RMB ona browser node containing routecenterline. This does not work as may be unsupported.
'		'Imports System.Windows.Forms (Place in Header)
'		'SendKeys.SendWait("+({F10})")'The parentheses indicates that F10 should be pressed while Shift is held down

'		obj.DoSelect 'the command seems to act on the last selected object
' 			'Includes the Route centerline....(opposite to it's name)
'			'oControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("CADC:Drawing:CenterlineRecoveryUnchecked")
'		 	'oControlDef.Execute
		
'			'Excludes the Route centerline....(opposite to it's name)
'        '	oControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("CADC:Drawing:CenterlineRecoveryChecked")
'		'	oControlDef.Execute
		 
'		Call ThisApplication.UserInterfaceManager.DoEvents 'lets inventor catch up
		
'	  Next
		
		']
		ThisApplication.CommandManager.ControlDefinitions.Item("AppBrowserCollapseAllCmd").Execute2(True)
		doc.SelectSet.Clear

					
					
End Sub

Dim tosel As New ArrayList 'store valid browsernodes

Sub GetRouteBrowserNodes(nodes As BrowserNodesEnumerator)
	'On Error Resume Next
	For Each node As BrowserNode In nodes
	
		If node.NativeObject IsNot Nothing Then
			'Logger.Info(CType(node.NativeObject.type, ObjectTypeEnum).ToString)
				
			If (node.NativeObject.type = ObjectTypeEnum.kComponentOccurrenceObject)
				
								If node.NativeObject.Definition.Document.DocumentInterests.HasInterest("Piping Route Environment")
									tosel.Add(node)
									End If
									
								'Use "Piping Runs Environment" for the top level run defintion
								'Use "Piping Run Environment" for individual runs like Run00, Run01
								'Use "Piping Route Environment"	for individual routes
								If node.FullPath.Contains("Route") Then
									node.DoSelect
									'This needs run before setting the state 
									Try
										
									ThisApplication.CommandManager.ControlDefinitions.Item("CADC:Drawing:CenterlineRecoveryTriState").Execute 
								Catch ex As Exception
								Logger.Info(ex.ToString )
								End Try
								
								If ShowLines Then
						Try
											'If the "Include Route Centerline" is unchecked the code will check it 
								ThisApplication.CommandManager.ControlDefinitions.Item("CADC:Drawing:CenterlineRecoveryUnchecked").Execute 
									Catch ex As Exception
								Logger.Info(ex.ToString )
								End Try					
								Else
									Try
										'If the "Include Route Centerline" is checked the code will uncheck it 
								ThisApplication.CommandManager.ControlDefinitions.Item("CADC:Drawing:CenterlineRecoveryChecked").Execute 
							Catch ex As Exception
								Logger.Info(ex.ToString )
								End Try
							End If
						
								Logger.Info(node.FullPath)
							End If
								'Return 'this run is taken care of so don't search any deeper
								
			End If
					If node.NativeObject IsNot Nothing AndAlso 
						(TypeOf node.NativeObject Is DrawingView OrElse
						node.NativeObject.type = ObjectTypeEnum.kComponentOccurrenceObject OrElse
						node.NativeObject.type = ObjectTypeEnum.kAssemblyComponentDefinitionObject) Then
						    GetRouteBrowserNodes(node.BrowserNodes) 'recursively search, only want to search valid node types
					End If
		End If
	Next
End Sub
Sub GetRunBrowserNodes(nodes As BrowserNodesEnumerator)
	On Error Resume Next
	For Each node As BrowserNode In nodes
	
		If node.NativeObject IsNot Nothing Then
			'Logger.Info(CType(node.NativeObject.type, ObjectTypeEnum).ToString)
				
			'If (node.NativeObject.type = ObjectTypeEnum.kComponentOccurrenceObject)
								If (node.FullPath.Contains("Run")) 'assuming these are not renamed
									
									tosel.add(node)
								End If
								'Use "Piping Runs Environment" for the top level run defintion
								'Use "Piping Run Environment" for individual runs like Run00, Run01
								'Use "Piping Route Environment"	for individual routes
								
								'Logger.Info(node.FullPath)
								'Return 'this run is taken care of so don't search any deeper
							
			End If
					If node.NativeObject IsNot Nothing AndAlso 
						(TypeOf node.NativeObject Is DrawingView OrElse
						node.NativeObject.type = ObjectTypeEnum.kComponentOccurrenceObject) Then
						    GetRunBrowserNodes(node.BrowserNodes) 'recursively search, only want to search valid node types
					End If
		'End If
	Next

End Sub


End Class
Aleksander Myklebust
0 Likes