几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-12, 09:12 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】how suppress a operation of a componen

how suppress a operation of a component
hi!
i want to suppress some operations of components. i tried with:
retval = modeldocextension.selectbyid2 ( name, type, x, y, z, append, mark, callout, selectoption )
retval = modeldoc2.editunsuppress2 ( ) or retval = modeldoc2.editsuppress2 ( )
but when i have to select something like this: modeldoc-->assembly-->assembly-->part-->operation i have problems with the name because is very longer.
anybody knows another way?
thanks!
if you know the name of the feature (if it is a feature of course) you want to supress and you have the component/part/assembly object that contains that feature you can use featurebyname (assemblydoc::featurebyname, component2::featurebyname, partdoc::featurebyname) to get the feature then select the feature (feature::select2) and then supress it.
alternatively i am pretty sure that there was another post on the forums that explained how to select features in subassemblies.
cheers,
--stav.
in this world i am nobody...
and nobody is perfect !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
edited: 03/11/2009 at 06:45 am by stavros antoniou
how to get right name which can be used with selectbyid2
i have been thinking and do you think if it is possible to create a macro that when you select a feature you have the name and then you can get the "fullname" to use like the name in retval = modeldocextension.selectbyid2 ( name, type, x, y, z, append, mark, callout, selectoption )
i believe that it is possible by modifying the code that ivana is indicating and using "gettype" for the "type" in the selectby id2 command. it seems like i had to remove the feature name and then add it to the front of the returned path to get the full name of the feature.
dan miel
this should get the feature path needed for selectbyid2. the type should be the type you need. if you have a component selected instead of a feature this will error.
i hope this helps.
dan miel
'written dan miel jan 7, 08
'this will return the component.name to a string that can be used to
'select a part by using "selectbyid2".
'to select a component in the tree use "getselectedobject6"
'to select a component in the graphics window use getselectedobjectscomponent3
dim swapp as sldworks.sldworks
dim part as sldworks.modeldoc2
dim comp as sldworks.component2
dim selmgr as sldworks.selectionmgr
dim feat as sldworks.feature
dim entity as sldworks.entity
dim comppath as string
dim featpath as string
sub main()
set swapp = application.sldworks
set part = swapp.activedoc
set selmgr = part.selectionmanager
'set comp = selmgr.getselectedobject6(1, -1)' this will select part in tree
set comp = selmgr.getselectedobjectscomponent3(1, -1) 'select the face or edge of a part in the window
debug.print "comp.name = " & comp.name2
'this gets and prints the name for the component
comppath = getcompstring(comp.name) 'if f is passed then feature stringstring is returned
debug.print "comp path = "; comppath
'the next lines adds the feature name to the comp path
set feat = selmgr.getselectedobject6(1, -1)
featpath = feat.name & "@" & comppath
debug.print "feat path = " & featpath
'the next lines gets and print the type
set entity = selmgr.getselectedobject6(1, -1)
debug.print "type = " & entity.gettype
end sub
function getcompstring(byval comppath as string)
dim v as variant
dim ti as integer
dim i as integer
dim inassm as string
dim loops as integer
dim pathstring as string
'added next four lines when i edited
dim filetitle as string
filetitle = part.gettitle
i = instr(1, filetitle, ".") - 1
if i > 0 then
filetitle = left(filetitle, i)
end if
'splits comp name into seperate strings
v = split(comppath, "/")
pathstring = v(0) & "@" & filetitle
'reworks componet name to string needed
for ti = 0 to ubound(v) - 1
inassm = v(ti)
inassm = left(inassm, instrrev(inassm, "-") - 1)
pathstring = pathstring & "/" & v(ti + 1) & "@" & inassm
next ti
getcompstring = pathstring
'returns string in this format
thank you very much for your help, dan miel! i have changed a bit your code. in my case i'll select a component or a feature from the feature manager. so the macro has to know if it is a component or a feature and then call to the function. this is my code:
option explicit
dim part as sldworks.modeldoc2
sub main()
dim swapp as sldworks.sldworks
dim selmgr as sldworks.selectionmgr
dim comp as sldworks.component2
dim feat as sldworks.feature
dim entity as sldworks.entity
dim comppath as string
dim swcomponent as sldworks.component2
set swapp = createobject("sldworks.application")
set part = swapp.activedoc
set selmgr = part.selectionmanager
'''''''''''''
'for components:
on error goto salto1
set comp = selmgr.getselectedobject6(1, -1) ' this will select part in tree
comppath = getcompstring(comp.name)
''''''''''''''''
salto1:
'for features:
on error goto salto2
set feat = selmgr.getselectedobject6(1, -1)
set entity = feat
set swcomponent = entity.getcomponent
comppath = getcompstring(swcomponent.name2)
comppath = feat.name & "@" & comppath
'''''''''''''''''''''''''
salto2:
msgbox "comp path = " & comppath
end sub
function getcompstring(byval comppath as string)
dim v as variant
dim ti as integer
dim i as integer
dim inassm as string
dim loops as integer
dim pathstring as string
dim filetitle as string
filetitle = part.gettitle
i = instr(1, filetitle, ".") - 1
if i > 0 then
filetitle = left(filetitle, i)
end if
v = split(comppath, "/")
pathstring = v(0) & "@" & filetitle
for ti = 0 to ubound(v) - 1
inassm = v(ti)
inassm = left(inassm, instrrev(inassm, "-") - 1)
pathstring = pathstring & "/" & v(ti + 1) & "@" & inassm
next ti
getcompstring = pathstring
'returns string in this format
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 10:23 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多