Display Hidden Lines (with macro)

Library for macros
User avatar
Ömür Tokman
Posts: 359
Joined: Sat Mar 13, 2021 3:49 am
Answers: 1
Location: İstanbul-Türkiye
x 993
x 345
Contact:

Display Hidden Lines (with macro)

Unread post 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
by JSculley » 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,"") 
Go to full post
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
User avatar
JSculley
Posts: 643
Joined: Tue May 04, 2021 7:28 am
Answers: 55
x 9
x 877

Re: Display Hidden Lines (with macro)

Unread post 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,"") 
User avatar
Ömür Tokman
Posts: 359
Joined: Sat Mar 13, 2021 3:49 am
Answers: 1
Location: İstanbul-Türkiye
x 993
x 345
Contact:

Re: Display Hidden Lines (with macro)

Unread post 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
Attachments
2023-06-05_14-52-15.png
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
User avatar
Ömür Tokman
Posts: 359
Joined: Sat Mar 13, 2021 3:49 am
Answers: 1
Location: İstanbul-Türkiye
x 993
x 345
Contact:

Re: Display Hidden Lines (with macro)

Unread post 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
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
User avatar
gupta9665
Posts: 410
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 433
x 447

Re: Display Hidden Lines (with macro)

Unread post by gupta9665 »

There is a DisplayMode method but not sure if this can be used.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
User avatar
josh
Posts: 295
Joined: Thu Mar 11, 2021 1:05 pm
Answers: 16
x 22
x 508

Re: Display Hidden Lines (with macro)

Unread post 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
User avatar
Ömür Tokman
Posts: 359
Joined: Sat Mar 13, 2021 3:49 am
Answers: 1
Location: İstanbul-Türkiye
x 993
x 345
Contact:

Re: Display Hidden Lines (with macro)

Unread post 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
You ˹alone˺ we worship and You ˹alone˺ we ask for help.
Post Reply