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

(Not an Autodesk Employee)