Drawing view: change line color of isometric views

Drawing view: change line color of isometric views

CCarreiras
Mentor Mentor
461 Views
4 Replies
Message 1 of 5

Drawing view: change line color of isometric views

CCarreiras
Mentor
Mentor

HI!

 

I'd like to have an iLogic rule to change the line color of the isometric views present in the active sheet.

Could this be possible?

CCarreiras

EESignature

0 Likes
462 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @CCarreiras. Sure.  There are a few ways to do something like that.  You can simply change the Color of each DrawingCurve in the view directly, which can tend to take a longer time to process.  Or you can gather every DrawingCurveSegment in the view to an ObjectCollection, then use the Sheet.ChangeLayer method to put them all on a special layer that is set to the color you want.  I am showing both of those options in this rule example below.

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oViews As DrawingViews = oDDoc.ActiveSheet.DrawingViews
Dim oRed As Color = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
Dim oLayer As Layer = oDDoc.StylesManager.Layers.Item(1).Copy("ISO View Curves")
oLayer.Color = oRed
Dim oObjCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oView As DrawingView In oViews
	oObjCol.Clear
	If oView.Camera.ViewOrientationType = ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation Or _
		oView.Camera.ViewOrientationType = ViewOrientationTypeEnum.kIsoBottomRightViewOrientation Or _
		oView.Camera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopLeftViewOrientation Or _
		oView.Camera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation Then
		Dim oDCs As DrawingCurvesEnumerator = oView.DrawingCurves
		For Each oDC As DrawingCurve In oDCs
			'oDC.Color = oRed
			Dim oDCSs As DrawingCurveSegments = oDC.Segments
			For Each oDCSeg As DrawingCurveSegment In oDCSs
				oObjCol.Add(oDCSeg)
			Next 'oDCSeg
		Next 'oDC
	End If
Next 'oView
oDDoc.ActiveSheet.ChangeLayer(oObjCol, oLayer)

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

CCarreiras
Mentor
Mentor

Hi @WCrihfield 

 

Thank you, it works!

 

But there's one problem: it only works one time.

Ex, If i add a new ISO view, when rerunning the rule, it will fail at line 8. I believe it's because the layer already exists.

I tried some "on error resume next" but had no success.

 

Also, it only catches one orientation: the "ISO Bottom Right" views... 

ViewOrientationTypeEnum.kIsoBottomRightViewOrientation


All the others stay unchanged, in the original layer.

Imagine the "ISO view" layer already exists in the template, and the rule only has to catch the geometry and change color and place it in the layer.
The rule should be used more than one time (if needed).

 

Do you think it's possible to tweak the rule to do this?

Thank you.


It's possible to overtake this issue?

 

 

CCarreiras

EESignature

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

Hi @CCarreiras.  I see the mistake now, and I also see a lot of room for improvement.  I just typed that one up from scratch on the spot, without testing, which does often lead to mistakes.  I have fixed the mistake, and added in some additional robustness.  All possible feedback from potential problems will now be written to the 'iLogic Log' tab of the iLogic DockableWindow, so you can review what happened after the fact, without any pop-up messages pausing the rule while its running.  I also built a transaction handler into the process, which bundles multiple actions into one element in the UNDO list, so that you can undo everything that the rule did in one click of the UNDO button, just in case.  Hopefully this version will function much better for you, as it has done in my testing this morning.

 

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oTrans As Inventor.Transaction = Nothing 'used to bundle multiple actions into one UNDO
oTrans = ThisApplication.TransactionManager.StartTransaction(oDDoc, "Change ISO View Colors")
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oViews As DrawingViews = oSheet.DrawingViews
If oViews.Count = 0 Then
	Logger.Debug("There were no views on the active sheet.")
	oTrans.Abort
	Exit Sub
End If
Dim oRed As Color = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
Dim oLayer As Layer = Nothing
Try
	oLayer = oDDoc.StylesManager.Layers.Item("ISO View Curves")
Catch
	oLayer = oDDoc.StylesManager.Layers.Item(1).Copy("ISO View Curves")
	oLayer.Color = oRed
End Try
If IsNothing(oLayer) Then
	Logger.Debug("The Layer named 'ISO View Curves' could not be found or created.")
	oTrans.Abort
	Exit Sub
End If
Dim oObjCol As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oView As DrawingView In oViews
	If oView.Suppressed Then Continue For 'skip to next oView
	oObjCol.Clear
	Dim oViewOrientation As ViewOrientationTypeEnum = oView.Camera.ViewOrientationType
	If oViewOrientation = ViewOrientationTypeEnum.kIsoBottomLeftViewOrientation Or _
		oViewOrientation = ViewOrientationTypeEnum.kIsoBottomRightViewOrientation Or _
		oViewOrientation = ViewOrientationTypeEnum.kIsoTopLeftViewOrientation Or _
		oViewOrientation = ViewOrientationTypeEnum.kIsoTopRightViewOrientation Then
		Dim oDCs As DrawingCurvesEnumerator = Nothing
		Try
			oDCs = oView.DrawingCurves
		Catch
			Logger.Error("Error getting DrawingCurves from view named " & oView.Name)
			Continue For 'skip to next oView
		End Try
		If IsNothing(oDCs) OrElse oDCs.Count = 0 Then Continue For 'skip to next oView
		For Each oDC As DrawingCurve In oDCs
			'oDC.Color = oRed
			Dim oDCSs As DrawingCurveSegments = oDC.Segments
			For Each oDCSeg As DrawingCurveSegment In oDCSs
				oObjCol.Add(oDCSeg)
			Next 'oDCSeg
		Next 'oDC
		If oObjCol.Count > 0 Then oSheet.ChangeLayer(oObjCol, oLayer)
	End If 'oViewOrientation
Next 'oView
oSheet.Update
If oDDoc.RequiresUpdate Then oDDoc.Update2(True)
'If oDDoc.Dirty Then oDDoc.Save
oTrans.End

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

CCarreiras
Mentor
Mentor

Thank you very much @WCrihfield .

 

It's closer, but still no effect in some views

ccarreiras_0-1679933882149.png

 

CCarreiras

EESignature

0 Likes