Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

iLogic Script to change colour of drawing view line work

gcoombridge
Advisor
Advisor

iLogic Script to change colour of drawing view line work

gcoombridge
Advisor
Advisor

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

 

 

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399
Reply
1,068 Views
3 Replies
Replies (3)

WCrihfield
Mentor
Mentor

Hi @gcoombridge.  That is a pretty deep and time / resource intensive rabbit hole just to provide a 'context' view on a drawing sheet.  It seems to me like you could simply create a DesignViewRepresentation (aka Design Views, within the Representations folder in your model browser) in your model document, in which the selected component(s) are a different vibrant color, and/or others may be dull color or a degree of translucent/transparent.  Then specify that DesignViewRepresentation when placing that view to make the view look that way.  There are a few more intricacies to it, but far, far simpler than what you are trying to do with code here...and simpler to revert back (if needed).  Component colors may only show in shaded in certain situations, but can also effect line colors of non-shaded views.  Anyways, that process seems more manageable and simpler to me for this type of situation.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

gcoombridge
Advisor
Advisor

@WCrihfield thanks for the response. It is a bit of a rabbit-hole to be fair, I worked on a few things like this in 2020 when I was on extended parental leave with a CAD laptop and needed something to exercise my brain. It worked very well at the time on test samples but is far too slow on real examples with 30+ piping runs and many edges.

 

I take your design view rep suggestion on board, but the reason I have done this in the way I have is that it is a minor part of the drawing sheet. Just a view to provide context, I typically only do shaded views for ballooned isometrics. Example of the difference below (bottom is done via the code above):

image.png

Above you say: "Component colors may only show in shaded in certain situations, but can also effect line colors of non-shaded views". 

To my understanding design view reps can only affect shaded views, to change line colours I'd have to do something similar to the code above wouldn't I? Can't see an out of the box approach to this...

Use iLogic Copy? Please consider voting for this long overdue idea (not mine):https://forums.autodesk.com/t5/inventor-ideas/string-replace-for-ilogic-design-copy/idi-p/3821399

dschwab
Participant
Participant

Hello @gcoombridge,

I know I am about 2 years late to the party, but I have been looking for a solution to the same problem in Inventor 2023. I am coloring the lines directly through DrawingCurve.Color, but the difference seems trivial. Accessing / setting attributes of DrawingCurve objects takes more time than is reasonable, perhaps because tons of events fire every time a drawing updates.

 

I feel like I shaved a few minutes off with these optimizations:

ThisApplication.ScreenUpdating = False
ThisApplication.ActiveDocument.DrawingSettings.DeferUpdates = True

 Then reverting back to default when complete:

 

ThisApplication.ScreenUpdating = True
ThisApplication.ActiveDocument.DrawingSettings.DeferUpdates = False

This by no means solves the problem. Inventor needs to provide a better way to access color properties in drawingViews.

0 Likes