iLogic Script to change colour of drawing view line work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All,
I wrote a piece of code (after patching together some references on the forum and elsewhere) to colour all lines in a view grey (using a layer called 'context') and then select a particular subassembly by selecting a line and colouring that bright red (using another layer called 'context highlight').
The purpose of this is to draw attention to the particular piping line the drawing sheet is detailing. It looks effective and has worked well EXCEPT that it is very slow! I feel like it is getting slower the more times it is refreshed thought that may just be my frustration 😁
I'm posting the code below. Can anyone offer any advice to improve its efficiency? I have noticed that when using 'select all edges' from the browser node it is much faster. I considered looking for a control definition for the properties, but I find navigating the browser nodes quite complex with code... Perhaps I just need to do this manually
Thanks,
'The purpose of this rule is to"
'1) colour all linework In the selected view grey,
'2) then highlight red one Or several Sub-assemblies.
'I use this in my tube and pipe run drawings to show a context view of the run alongside other pipework.
'This first paragraph is just a test to verify the rule is being run in a drawing document
Dim DocCheck As Document
DocCheck = ThisDoc.Document
If DocCheck.DocumentType = kDrawingDocumentObject Then
'Declare Document and other variables
Dim oDoc As DrawingDocument
oDoc = ThisDoc.Document
Dim oSheet As Sheet
oSheet = oDoc.ActiveSheet
'These two layers MUST already exist. If you are using my latest templates they will otherwise make them...
Dim Context As Layer
Context = oDoc.StylesManager.Layers.Item("Context")
Dim ContextHighlight As Layer
ContextHighlight = oDoc.StylesManager.Layers.Item("Context Highlight")
Dim oView As DrawingView
Dim oTransObj As TransientObjects
oTransObj = ThisApplication.TransientObjects
'PART 1_CHOOSE THE VIEW AND GREY OUT
'Selection with a drawing view filter - choose the view
oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select Drawing View to Grey/Highlight")
'If nothing is selected end rule...
If IsNothing(oView) Then 'Do Nothing
Else
'Create an object collection
Dim oObjCol As ObjectCollection
oObjCol = oTransObj.CreateObjectCollection()
'collect all of the curves in the view
Dim oCurves As DrawingCurvesEnumerator
oCurves = oView.DrawingCurves
'for each curve, iterate through all the segments and add them the the object collection
Dim oCurve As DrawingCurve
For Each oCurve In oCurves
Dim oSegment As DrawingCurveSegment
For Each oSegment In oCurve.Segments
oObjCol.Add (oSegment)
Next
Next
'the parent of the view is the model - change it's layer (specificially the object collection and context will be the layer
oView.Parent.ChangeLayer(oObjCol, Context)
'Clear the collection because we'll fill it again but with less stuff
oObjCol.Clear
End If
'PART 2_CHOOSE MODEL EDGES OF THE SUB-ASSEMBLIES TO HIGHLIGHT
'define variables...
Dim oOccSelected As ComponentOccurrence
Dim oSelectedCurveSegment As DrawingCurveSegment
Dim CurveCol As ObjectCollection
CurveCol = oTransObj.CreateObjectCollection()
'This while statement allows more than one thing to be selected...
While True
oSelectedCurveSegment = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter , "Select Tube and Pipe Runs to Highlight (ESC when done)")
If IsNothing(oSelectedCurveSegment) Then Exit While
'adding selected curves to a collection
CurveCol.Add(oSelectedCurveSegment)
End While
For Each oSelectedCurveSegment In CurveCol
'This checks if there is a .parentoccurrence (i.e it's part of a sub-assembly) otherwise it continues as a part...
Try
oOccSelected = oSelectedCurveSegment.Parent.ModelGeometry.ContainingOccurrence.ParentOccurrence
MsgBox(oOccSelected.Name,MessageBoxIcon.Information,"Sub-Assembly to be Highlighted")
Catch
oOccSelected = oSelectedCurveSegment.Parent.ModelGeometry.ContainingOccurrence
MsgBox(oOccSelected.Name,MessageBoxIcon.Information,"Part to be Highlighted")
End Try
'most of this is the same a part 1
Dim oObjCol As ObjectCollection
oObjCol = oTransObj.CreateObjectCollection
Dim oCurves As DrawingCurvesEnumerator
'except note that we're specifying the models the curves belong to, not just all curves in the view - (targeted to selection)
oCurves = oView.DrawingCurves(oOccSelected)
Dim oCurve As DrawingCurve
For Each oCurve In oCurves
'defining segment again because I want it to be all the segments in the model view, not just the selected ones
Dim oSegment As DrawingCurveSegment
For Each oSegment In oCurve.Segments
oObjCol.Add (oSegment)
Next
Next
'change to highlight layer (red)
oView.Parent.ChangeLayer(oObjCol, ContextHighlight)
Next oSelectedCurveSegment
Else ' Do Nothing
End If