Put sub-assembly in color in drawing

Put sub-assembly in color in drawing

inventor4578
Advocate Advocate
498 Views
5 Replies
Message 1 of 6

Put sub-assembly in color in drawing

inventor4578
Advocate
Advocate

Hi,

 

I would like to know if it possible by iLogic to put in color (red) the current sub-assembly of the sheet (i have 1 sub-assembly by sheet), in a general view (ISO) of the top assembly, to see quickly where is this sub-assembly in the main.

 

- I have 1 sub-assembly by sheet (The sub is already in a assembly, in the top assembly...)

- I put a ISO view, and i select this view

- I run the macro, the macro look for the current sheet attached model

- It search on the ISO view the corresponding assembly

- It put in RED color line

 

Thank you very much !

0 Likes
499 Views
5 Replies
Replies (5)
Message 2 of 6

daltonNYAW9
Advocate
Advocate

I created something similar to this a while ago. The main difference is instead of changing the line's layer, I would hold <CTRL> then change the "edge properties" color. It worked faster this way. 

Tweeked that rule:
First manually add a layer w/ a specific name ("Item Detail" for this rule)

Also, assumed the sub-assembly is always the first drawing view

' Get the transaction manager from the application
Dim oTxnMgr As TransactionManager
oTxnMgr = ThisApplication.TransactionManager

' Start a regular transaction
Dim oTxn As Transaction
oTxn = oTxnMgr.StartTransaction(ThisDoc.Document, "transaction")

Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oTopAssyView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select Assembly View")
Dim oTopAssyViewBrowserNode As BrowserNode = oDDoc.BrowserPanes("Model").GetBrowserNodeFromObject(oTopAssyView).Parent
Dim oTopAssyDoc As AssemblyDocument = oTopAssyView.ReferencedDocumentDescriptor.ReferencedDocument

Dim oSheet As Sheet = oDDoc.ActiveSheet
Dim oSubAssyView As DrawingView = oSheet.DrawingViews(1)
Dim oSubAssyDoc As AssemblyDocument = oSubAssyView.ReferencedDocumentDescriptor.ReferencedDocument

'expand sheet nodes to get assembly nodes
ThisApplication.CommandManager.DoSelect(oTopAssyView.Parent)
ThisApplication.CommandManager.ControlDefinitions.Item("AppBrowserExpandChildrenCmd").Execute

Dim lines As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection

For Each oOcc As ComponentOccurrence In oTopAssyDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oSubAssyDoc)
	Dim oOccBrowserNodeDef As BrowserNodeDefinition = oTopAssyDoc.BrowserPanes.GetNativeBrowserNodeDefinition(oOcc)
	For Each oBrowserNode As BrowserNode In oTopAssyViewBrowserNode.AllReferencedNodes(oOccBrowserNodeDef)
		oDDoc.SelectSet.Clear
		oBrowserNode.DoSelect
		If oDDoc.SelectSet.Count <> 0
			ThisApplication.CommandManager.ControlDefinitions.Item("SelectAsEdgesCtxCmd").Execute
			For i = 1 To oDDoc.SelectSet.Count
				lines.Add(oDDoc.SelectSet.Item(i))
			Next


		End If
	Next
Next

'collapse all browser nodes
ThisApplication.CommandManager.ControlDefinitions.Item("AppBrowserCollapseAllCmd").Execute

'layer you want it changed to
Dim oLayer As Layer = oDDoc.StylesManager.Layers.Item("Item Detail")
oSheet.ChangeLayer(lines, oLayer)

oTxn.End



0 Likes
Message 3 of 6

Stakin
Collaborator
Collaborator

how reset to default layer?

0 Likes
Message 4 of 6

daltonNYAW9
Advocate
Advocate

@Stakin change the 'oLayer' value.

Dim oLayer As Layer = oDDoc.StylesManager.Layers.Item("Visible (ANSI)")

'or

oLayer = Nothing
0 Likes
Message 5 of 6

Stakin
Collaborator
Collaborator

thanks it works for every curvesegment ,but can't work for changelayer method.

0 Likes
Message 6 of 6

daltonNYAW9
Advocate
Advocate

Yeah changing the layers for each curve segment is a bit finicky. Here's how you could do it without messing with the layers, just the line "properties" in the drawing:
And to reset the properties you can just right click on the view's assembly node > properties... > color "by layer"

' Get the transaction manager from the application
Dim oTxnMgr As TransactionManager
oTxnMgr = ThisApplication.TransactionManager

' Start a regular transaction
Dim oTxn As Transaction
oTxn = oTxnMgr.StartTransaction(ThisDoc.Document, "transaction")

Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oTopAssyView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select Assembly View, Hold <CTRL> for multiple")
Dim oTopAssyViewBrowserNode As BrowserNode = oDDoc.BrowserPanes("Model").GetBrowserNodeFromObject(oTopAssyView).Parent
Dim oTopAssyDoc As AssemblyDocument = oTopAssyView.ReferencedDocumentDescriptor.ReferencedDocument

Dim oSheet As Sheet = oDDoc.ActiveSheet
Dim oSubAssyView As DrawingView = oSheet.DrawingViews(1)
Dim oSubAssyDoc As Document = oSubAssyView.ReferencedDocumentDescriptor.ReferencedDocument

'expand sheet nodes to get assembly nodes
ThisApplication.CommandManager.DoSelect(oTopAssyView.Parent)
ThisApplication.CommandManager.ControlDefinitions.Item("AppBrowserExpandChildrenCmd").Execute

For Each oOcc As ComponentOccurrence In oTopAssyDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oSubAssyDoc)
	Dim oOccBrowserNodeDef As BrowserNodeDefinition = oTopAssyDoc.BrowserPanes.GetNativeBrowserNodeDefinition(oOcc)
	For Each oBrowserNode As BrowserNode In oTopAssyViewBrowserNode.AllReferencedNodes(oOccBrowserNodeDef)
		oBrowserNode.DoSelect

	Next
Next

'collapse all browser nodes
ThisApplication.CommandManager.ControlDefinitions.Item("AppBrowserCollapseAllCmd").Execute
'unselect sheet 
ThisApplication.CommandManager.DoUnSelect(oSheet)
'change line color command
ThisApplication.CommandManager.ControlDefinitions.Item("DrawingObjectPropertiesCtxCmd").Execute

oTxn.End