handleman
Automotive
- Jan 7, 2005
- 3,411
Has anyone else noticed that 2008 (I think) dropped the functionality that when you select a component in the design tree of an assembly drawing (.slddrw) it used to draw a brownish box around the component? This really helped in figuring out what was what. I really miss it.
So guess what. I wrote a macro. Surprised?
This macro will highlight all the edges in the graphics area (visible or not) of the components selected in the feature tree. Subassemblies are OK too. Anything else that is selected (hole features, planes, sketches, etc) will be ignored. Unfortunately, it won't do silhouette edges, so if you have a sphere or a torus or some other topological oddity then it won't show up.
Now I just need to find an unused shortcut key....
-handleman, CSWP (The new, easy test)
So guess what. I wrote a macro. Surprised?
This macro will highlight all the edges in the graphics area (visible or not) of the components selected in the feature tree. Subassemblies are OK too. Anything else that is selected (hole features, planes, sketches, etc) will be ignored. Unfortunately, it won't do silhouette edges, so if you have a sphere or a torus or some other topological oddity then it won't show up.
Now I just need to find an unused shortcut key....
Code:
Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swDwg As SldWorks.DrawingDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim NumSels As Long
Dim swDwgComp As SldWorks.DrawingComponent
Dim swComp As SldWorks.Component2
Dim i As Long
Sub main()
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
If swDoc.GetType <> swDocDRAWING Then
Exit Sub
End If
Set swDwg = swDoc
Set swSelMgr = swDoc.SelectionManager
NumSels = swSelMgr.GetSelectedObjectCount2(-1)
'MsgBox NumSels & " selections made"
For i = 1 To NumSels
If swSelMgr.GetSelectedObjectType3(i, -1) = swSelCOMPONENTS Then
Set swDwgComp = swSelMgr.GetSelectedObject6(i, -1)
Set swComp = swDwgComp.Component
If swComp.GetModelDoc.GetType = swDocASSEMBLY Then
Call HighlightAssy(swComp, swDwg.ActiveDrawingView)
Else
Call HighlightPart(swComp)
End If
End If
Next i
'MsgBox swDwg.ActiveDrawingView.Name
End Sub
Sub HighlightPart(ByVal myComp As SldWorks.Component2)
Dim CompBods As Variant
Dim BodEdges As Variant
Dim j As Long
Dim k As Long
CompBods = myComp.GetBodies2(swAllBodies)
For j = 0 To UBound(CompBods)
BodEdges = CompBods(j).GetEdges
On Error GoTo TRYFACES
For k = 0 To UBound(BodEdges)
BodEdges(k).Highlight True
Next k
DIDFACES:
Next j
Debug.Print "Highlighted " & myComp.Name2
Exit Sub
TRYFACES:
BodEdges = CompBods(j).GetFaces
For k = 0 To UBound(BodEdges)
BodEdges(k).Highlight True
Next k
Resume DIDFACES
End Sub
Sub HighlightAssy(ByVal myAssyComp As SldWorks.Component2, myView As SldWorks.View)
Dim j As Long
Dim AssyChildren As Variant
Dim myDwgComp As SldWorks.DrawingComponent
AssyChildren = myAssyComp.GetChildren
For j = 0 To UBound(AssyChildren)
If (AssyChildren(j).GetSuppression = swComponentResolved) Or (AssyChildren(j).GetSuppression = swComponentFullyResolved) Then
If AssyChildren(j).GetModelDoc.GetType = swDocASSEMBLY Then
Debug.Print "Get children of " & AssyChildren(j).Name2
HighlightAssy AssyChildren(j), myView
Else
HighlightPart AssyChildren(j)
End If
Else
Debug.Print AssyChildren(j).Name & " Not resolved"
End If
Next j
End Sub
-handleman, CSWP (The new, easy test)