几何尺寸与公差论坛

 找回密码
 注册
查看: 768|回复: 0

【转帖】how suppress a operation of a componen

[复制链接]
发表于 2009-4-12 21:12:09 | 显示全部楼层 |阅读模式
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-12-23 10:57 , Processed in 0.036598 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表