- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I use the below to grey out certain parts in an assembly. I could of sworn this used to work on sub-assemblies but now it doesn't am I wrong?
Class ThisRule Public oTargetName As String Public oTargetLayer As String Sub Main oTargetName = "M21-TEST-001" oTargetLayer = "TEST" If ThisApplication.ActiveDocument.DocumentType <> _ DocumentTypeEnum.kDrawingDocumentObject Then Return 'exit rule ' Get the active drawing document. Dim oDoc As DrawingDocument oDoc = ThisApplication.ActiveDocument Dim oLayers As LayersEnumerator oLayers = oDoc.StylesManager.Layers Dim oLayer As Layer For Each xLayer In oLayers If xLayer.name = oTargetLayer Then oLayer = xLayer Exit For End If Next If oLayer Is Nothing Then MsgBox("No layer named """ & oTargetLayer & """ was found in this drawing." _ & vbLf & vbLf & "Cannot continue.", , "iLogic") Exit Sub End If Dim oSheets As Sheets oSheets = oDoc.Sheets Dim oSheet As Sheet 'get current sheet so it can 'be made active again later Dim oCurrentSheet As Sheet oCurrentSheet = oDoc.ActiveSheet Dim oViews As DrawingViews Dim oView As DrawingView ' Iterate through the sheets For Each oSheet In oSheets 'activate the sheet oSheet.Activate 'get the collection of view on the sheet oViews = oSheet.DrawingViews ' Iterate through the views on the sheet For Each oView In oViews If oView.ReferencedDocumentDescriptor Is Nothing Then Continue For Dim docDesc As DocumentDescriptor docDesc = oView.ReferencedDocumentDescriptor ' Verify that the drawing view is of an assembly. If docDesc.ReferencedDocumentType <> kAssemblyDocumentObject Then Continue For End If ' Get the component definition for the assembly. Dim asmDef As AssemblyComponentDefinition asmDef = docDesc.ReferencedDocument.ComponentDefinition ' Process the view, wrapping it in a transaction so the ' each view can be undone with a single undo operation. Dim trans As Transaction trans = ThisApplication.TransactionManager.StartTransaction( _ oDoc, "Change drawing view color") ' Call the recursive function that does all the work. Call ProcessAssemblyColor(oView, asmDef.Occurrences) trans.End Next 'update the sheet oSheet.Update Next 'return to original sheet oCurrentSheet.Activate End Sub Private Sub ProcessAssemblyColor(drawView As DrawingView, _ Occurrences As ComponentOccurrences) Logger.Info("------------" & drawView.Name) ' Iterate through the current collection of occurrences. Dim occ As ComponentOccurrence For Each occ In Occurrences ' Check to see if this occurrence is a part or assembly. If occ.DefinitionDocumentType = kPartDocumentObject Then If Not occ.Name.Contains(oTargetName) Then Continue For Logger.Info(occ.Name) ' ** It's a part so process the layer ' Get the TransientsObjects object to use later. Dim transObjs As TransientObjects transObjs = ThisApplication.TransientObjects Dim oLayers As LayersEnumerator oLayers = drawView.Parent.Parent.StylesManager.layers Dim oLayer As Layer oLayer = oLayers.Item(oTargetLayer) Dim oDoc As DrawingDocument oDoc = drawView.Parent.Parent ' Get all of the curves associated with this occurrence. On Error Resume Next Dim drawcurves As DrawingCurvesEnumerator drawcurves = drawView.DrawingCurves(occ) If Err.Number = 0 Then On Error GoTo 0 ' Create an empty collection. Dim objColl As ObjectCollection objColl = transObjs.CreateObjectCollection() ' Add the curve segments to the collection. Dim drawCurve As DrawingCurve For Each drawCurve In drawcurves Dim segment As DrawingCurveSegment For Each segment In drawCurve.Segments objColl.Add(segment) Next Next ' Change the layer of all of the segments. Call drawView.Parent.ChangeLayer(objColl, oLayer) End If On Error GoTo 0 ElseIf occ.DefinitionDocumentType = kAssemblyDocumentObject Then ' It's an assembly so process its contents. Call ProcessAssemblyColor(drawView, occ.SubOccurrences) Else Continue For End If Next End Sub End Class
Solved! Go to Solution.