欢迎光临
我们一直在努力

solidworks二次开发–10–从example中寻找-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

solidworks的api帮助还是很全面的,里面有好多见简单而有效的程序,成天在api帮助里泡着,现在做程序的速度是越来越快。好像当年成天在excel中录制宏看代码的感觉。下面的程序是api帮助里的,它用来显示装配体的所有零部件。我给我的同事们用,他们觉得不错 :)。程序使用了一个简单的递归方法遍历了装配体。
make all assembly components visible example (vb)
this example shows how to make all assembly components visible.

 

—————————————

preconditions: an assembly document is open.

postconditions: any hidden assembly components are made visible.

—————————————

option explicit

public enum swcomponentvisibilitystate_e

}}–>    }}–>swcomponenthidden = 0

}}–>    }}–>swcomponentvisible = 1

end enum

 

sub traversecomponent _

( _

}}–>    }}–>swcomp as sldworks.component2, _

}}–>    }}–>nlevel as long _

)

}}–>    }}–>dim vchildcomparr }}–>              }}–>as variant

}}–>    }}–>dim vchildcomp }}–>                 }}–>as variant

}}–>    }}–>dim swchildcomp }}–>                }}–>as sldworks.component2

}}–>    }}–>dim swcompconfig }}–>               }}–>as sldworks.configuration

}}–>    }}–>dim spadstr }}–>                    }}–>as string

}}–>    }}–>dim i }}–>                          }}–>as long

}}–>    }}–>

}}–>    }}–>for i = 0 to nlevel – 1

}}–>        }}–>spadstr = spadstr + " }}–> }}–>"

}}–>    }}–>next i

}}–>    }}–>

}}–>    }}–>vchildcomparr = swcomp.getchildren

}}–>    }}–>for each vchildcomp in vchildcomparr

}}–>        }}–>set swchildcomp = vchildcomp

}}–>        }}–>

}}–>        }}–>debug.print spadstr & swchildcomp.name2 & " <" & swchildcomp.referencedconfiguration & ">"

}}–>        }}–>

}}–>        }}–>if swcomponenthidden = swchildcomp.visible then

}}–>            }}–>swchildcomp.visible = swcomponentvisible

}}–>        }}–>end if

}}–>        }}–>

}}–>        }}–>traversecomponent swchildcomp, nlevel + 1

}}–>    }}–>next

end sub

 

sub main()

}}–>    }}–>dim swapp }}–>                      }}–>as sldworks.sldworks

}}–>    }}–>dim swmodel }}–>                    }}–>as sldworks.modeldoc2

}}–>    }}–>dim swassy }}–>                     }}–>as sldworks.assemblydoc

}}–>    }}–>dim swconf }}–>                     }}–>as sldworks.configuration

}}–>    }}–>dim swrootcomp }}–>                 }}–>as sldworks.component2

}}–>    }}–>dim bret }}–>                       }}–>as boolean

}}–>    set swapp = application.sldworks

}}–>    }}–>set swmodel = swapp.activedoc

}}–>    }}–>set swconf = swmodel.getactiveconfiguration

}}–>    }}–>set swrootcomp = swconf.getrootcomponent}}–>}}–>

}}–>    }}–>debug.print "file = " & swmodel.getpathname

}}–>    traversecomponent swrootcomp, 1

end sub

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » solidworks二次开发–10–从example中寻找-.NET教程,Asp.Net开发
分享到: 更多 (0)