Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlight drawing component in graphics view 1

Status
Not open for further replies.

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....

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)
 
How about turning the appropriate option instead of writing a macro? ;)

In the display/selection options, check in the box that says “dynamic highlight from graphic view”.

On the plus side, props on not letting a problem bother you! Just write a couple of lines of codes and keep on working! I wish I could do that!
 
Actually, "dynamic highlight from graphics view" highlights edges and faces of components as you mouse over them in a drawing view, part, or assembly context. I already have that enabled. And I re-enable it every time I import an IGES file, since importing one turns the option off.

No, this macro highlights the edges in an assembly drawing view of the components selected in the feature manager design tree. SW used to do this with a brownish box drawn around the components in the graphics area. It doesn't anymore - at least not on our machines.

-handleman, CSWP (The new, easy test)
 
My SW08-SP4 install still shows the orange/brown box around an assy component when selected from the FM; and it is enabled/disabled by the Dynamic highlight from graphics view option. Strange!

[cheers]
 
I suppose it could be a graphics issue. If so it's the only one I've encountered (or noticed anyway) with our current setup of card and SW certified driver, and the change seemed to coincide with installation of 2008. Maybe I need to go ahead and get us updated to the latest SP and/or try a different driver.

-handleman, CSWP (The new, easy test)
 
Could that function be affected by different mouse driver settings?

[cheers]
 
The ever-so-wise handleman said:
And I re-enable it every time I import an IGES file, since importing one turns the option off.

Is that what toggles this option off???!!! I've seen this for years, but never been able to track it down. Good find. Thanks.

Joe
SW Office 2006 SP5.1
P4 3.0Ghz 1GB
ATI FireGL X1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor