Page 1 of 1

Display Hidden Lines (with macro)

Posted: Mon Jun 05, 2023 2:02 am
by Ömür Tokman
Hello everybody!
You are aware that I am not an active and very useful person for the forum, but I still wanted to ask my question here first.
I thought I should ask here since it's the Macro section, if the section is wrong please let me know.

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.
2023-06-05_08-49-55.png
2023-06-05_08-52-06.png
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.
2023-06-05_09-00-47.png

Code: Select all

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

@artem
@gupta9665

Re: Display Hidden Lines (with macro)

Posted: Mon Jun 05, 2023 7:41 am
by JSculley
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:

Code: Select all

status = swApp.RunCommand (swCommands_e.swCommands_Comp_Display_Hiddenremoved,"") 

Re: Display Hidden Lines (with macro)

Posted: Mon Jun 05, 2023 7:49 am
by Ömür Tokman
I don't know much about spr and macros. copy-pasted and trial and error is my favourite.
The code you gave did exactly what I wanted.
Thank you very much my friend.

The working code is below.

Code: Select all

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

Re: Display Hidden Lines (with macro)

Posted: Mon Jun 05, 2023 8:00 am
by Ömür Tokman
JSculley wrote: Mon Jun 05, 2023 7:41 am 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:

Code: Select all

status = swApp.RunCommand (swCommands_e.swCommands_Comp_Display_Hiddenremoved,"") 
I couldn't find any lines that I haven't visited in SW api for two days.

Did you know this code or did you find it by calling?

I have not yet learned how to find the code or function I need in the SW api. I usually come to a certain point and get stuck at some point.

I've seen them but didn't understand how to use them.
2023-06-05_16-33-14.png

Re: Display Hidden Lines (with macro)

Posted: Mon Jun 05, 2023 12:13 pm
by gupta9665
There is a DisplayMode method but not sure if this can be used.

Re: Display Hidden Lines (with macro)

Posted: Thu Jun 08, 2023 12:17 pm
by josh
Ömür Tokman wrote: Mon Jun 05, 2023 8:00 am I couldn't find any lines that I haven't visited in SW api for two days.

Did you know this code or did you find it by calling?

I have not yet learned how to find the code or function I need in the SW api. I usually come to a certain point and get stuck at some point.

I've seen them but didn't understand how to use them.
2023-06-05_16-33-14.png
Basically, all of the commands that are available in RunCommand are the same as clicking the button in the user interface. You don't need any of the code in your macro except the one RunCommand line. All the rest of that does nothing.

Sub main()
Set swapp = application.sldworks
swapp.runcommand [stuff]
end sub

Re: Display Hidden Lines (with macro)

Posted: Fri Jun 09, 2023 3:31 am
by Ömür Tokman
josh wrote: Thu Jun 08, 2023 12:17 pm Basically, all of the commands that are available in RunCommand are the same as clicking the button in the user interface. You don't need any of the code in your macro except the one RunCommand line. All the rest of that does nothing.

Sub main()
Set swapp = application.sldworks
swapp.runcommand [stuff]
end sub
No, was that all... all that code was a big lie... o[ grumph :o
I learned something new today (thanks to you)

Thanks you so much Mate.
2023-06-09_10-25-51.png

Code: Select all

Sub main()
Set swApp = Application.SldWorks
Status = swApp.RunCommand(swCommands_e.swCommands_Comp_Display_Hiddenremoved, "")
End Sub