Display Hidden Lines (Solidworks macro)

136 views Asked by At

I want to set the appearance of a single part I selected in an assembly to Display Hidden Lines with a macro.

The file I am using is not a drawing, not a part file. assembly file. part will not be selected from the element tree. will be selected from the drawing area. enter image description here enter image description here

so what do i have! What does this macro do? select part and hide it. I don't want to hide the part, I want to change the view style. enter image description here

below is the edited version of the code as in the first answer. enter image description here enter image description here

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelectionMgr As SldWorks.SelectionMgr
Dim swEntity As SldWorks.Entity
Dim swComponent As SldWorks.Component2

Dim Part As Object
Dim PartName
Dim boolstatus As Boolean

Dim instance As IDatumTag
Dim value

Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    ' Get the selected entity (i.e., face, edge, vertex, or loop)
    ' and get the name of its component
    Set swSelectionMgr = swModel.SelectionManager
    Set swEntity = swSelectionMgr.GetSelectedObject6(1, -1)
    Set swComponent = swEntity.GetComponent
    
    Debug.Print "Name of component to which the selected entity belongs: " & swComponent.GetSelectByIDString
    swComponent.ComponentReference = "TestComponentReference"
    Debug.Print "Component reference added to the component to which the selected entity belongs: " & swComponent.ComponentReference
    
     swModel.ForceRebuild3 True
    
'     swComponent.Select False
    ' swModel.HideComponent2             'this hides the selected party.
    ' swModel.ViewDisplayHiddenremoved   ' this changes all the parts.
    ' swComponent.DisplayMode = swComponentDisplayMode_e.swComponentHidden 'didn't work
'     swComponent.DisplayMode = 0 'didn't work
End Sub

I'm not a programmer, I've been researching for a few days, I couldn't go further than you going around the same codes. I need you to guide me on this. Kind regards,

1

There are 1 answers

0
ömür tokman On

A friend of mine just answered this question in a different forum, I'm adding the link and codes here.

If it is forbidden to share a different forum link, please let me know, I will delete the link.

"There isn't direct API call to set the component display mode. There is a SPR requesting it: SPR988885 - An API is required, on IComponent2, to allow setting component display mode As a workaround, you can use the RunCommand method: status = swApp.RunCommand (swCommands_e.swCommands_Comp_Display_Hiddenremoved,"") "

the address where the answer was given

 Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelectionMgr As SldWorks.SelectionMgr
Dim swEntity As SldWorks.Entity
Dim swComponent As SldWorks.Component2
Dim Part As Object
Dim PartName
Dim boolstatus As Boolean
Dim instance As IDatumTag
Dim Status

Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    ' Get the selected entity (i.e., face, edge, vertex, or loop)
    ' and get the name of its component
    Set swSelectionMgr = swModel.SelectionManager
    Set swEntity = swSelectionMgr.GetSelectedObject6(1, -1)
    Set swComponent = swEntity.GetComponent
    
    Debug.Print "Name of component to which the selected entity belongs: " & swComponent.GetSelectByIDString
    swComponent.ComponentReference = "TestComponentReference"
    Debug.Print "Component reference added to the component to which the selected entity belongs: " & swComponent.ComponentReference
    
     swModel.ForceRebuild3 True
    
    ' swComponent.Select False
    ' swModel.HideComponent2             'this hides the selected party.
    ' swModel.ViewDisplayHiddenremoved   ' this changes all the parts.
Status = swApp.RunCommand(swCommands_e.swCommands_Comp_Display_Hiddenremoved, "")
End Sub