显示隐藏线条(Solidworks宏)

huangapple go评论147阅读模式
英文:

Display Hidden Lines (Solidworks macro)

问题

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.

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.

below is the edited version of the code as in the first answer.

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.

英文:

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.
显示隐藏线条(Solidworks宏)
显示隐藏线条(Solidworks宏)

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.
显示隐藏线条(Solidworks宏)

below is the edited version of the code as in the first answer.
显示隐藏线条(Solidworks宏)
显示隐藏线条(Solidworks宏)

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

得分: 1

以下是翻译好的部分:

"一个朋友在另一个论坛中回答了这个问题,我在这里添加了链接和代码。

如果禁止分享其他论坛链接,请告诉我,我会删除链接。

“没有直接的API调用来设置组件显示模式。有一个SPR请求它:
SPR988885 - 需要一个API,在IComponent2上,允许设置组件显示模式
作为一种解决方法,您可以使用RunCommand方法:
status = swApp.RunCommand (swCommands_e.swCommands_Comp_Display_Hiddenremoved,"")"

答案所在的地址

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
' 获取所选实体(即面、边、顶点或环)和其组件的名称
Set swSelectionMgr = swModel.SelectionManager
Set swEntity = swSelectionMgr.GetSelectedObject6(1, -1)
Set swComponent = swEntity.GetComponent

Debug.Print "所选实体所属组件的名称:" & swComponent.GetSelectByIDString
swComponent.ComponentReference = "TestComponentReference"
Debug.Print "组件引用已添加到所选实体所属的组件:" & swComponent.ComponentReference

swModel.ForceRebuild3 True

' swComponent.Select False
' swModel.HideComponent2             '这将隐藏所选部件。
' swModel.ViewDisplayHiddenremoved   '这将更改所有零件。
Status = swApp.RunCommand(swCommands_e.swCommands_Comp_Display_Hiddenremoved, "")

End Sub

英文:

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

huangapple
  • 本文由 发表于 2023年6月5日 15:32:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76404330.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定