几何尺寸与公差论坛

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

【转帖】how can i do to select a componen

[复制链接]
发表于 2009-4-12 21:07:55 | 显示全部楼层 |阅读模式
how can i do to select a component?
hi!
i want to select all the component of an assembly. these components are parts and assemblies, so i have to make out it before.
code:
vchildcomp = swcomp.getchildren
for j = 0 to ubound(vchildcomp)
set swchildcomp = vchildcomp(j)
a = swchildcomp.select3(true, nothing)
set c = swchildcomp.getmodeldoc
type = c.gettype
if type = 1 then 'type=1 is a part
c.editpart 'error 438 else
c.editassembly 'type<>1 is an assembly
end if
but when select a part that is inside of an assembly i have an error 438 in line c.editpart that say: 'the object' doesn&acute;t admite this property or method'.
can anybody help me, please?
thank you so much!
editpart is not a valid method for a part file. editpart is a method of an assembly document.
i'll get you eh steve, if it's the last thing i dooooo!
hey marian,
have a alook at this example in the api help:
traverse assembly at component level example (vb).
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
it's ok. thank you for your help!
edited: 03/10/2009 at 10:05 am by marian ruiz
i have studied your possibilities and i have created another code but it doesn&acute;t work.
the idea is that i want to select all the components of an assembly.
sub main()
dim swmodel as sldworks.modeldoc2
dim swassy as sldworks.assemblydoc
dim swconf as sldworks.configuration
dim swchildcomp as sldworks.component2 'objetu bat da
set swapp = createobject("sldworks.application")
set swmodel = swapp.activedoc
set swconf = swmodel.getactiveconfiguration
set swchildcomp = swconf.getrootcomponent
edit swchildcomp 'call to edit procedure
end sub
sub edit(swcomp as sldworks.component2)
dim swmodel as sldworks.modeldoc2
dim swassy as sldworks.assemblydoc
dim swchildcomp as sldworks.component2
dim vchildcomp as variant
dim j as integer
dim a as boolean
dim nstatus as long, ninfo as long
vchildcomp = swcomp.getchildren
for j = 0 to ubound(vchildcomp)
set swchildcomp = vchildcomp(j)
a = swchildcomp.select3(true, nothing)
'in the next line i want to edit the selected component but it appears error 91
nstatus = swassy.editpart2(true, false, ninfo) 'error 91 in this line
edit swchildcomp
next j
end sub
where do you set your swassy object?
from the code you have pasted here it seems that you don't.
if that is the case then that's why you get the error.
what you can do is either set it in your main subroutine and pass it as an argument in the edit sub or just set it in your edit sub...
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
yes, sorry i forgot to copy some lines. the problem is that to edit a component a have to use swassy.editpart2 and in this procedure i'm working with component; so i have to transform a component--> modeldoc2-->assembly. but i don&acute;t know how to do it well.
the code is like this:
sub edit()
dim c as sldworks.modeldoc2
...
a = swchildcomp.select3(true, nothing)
set c = swchildcomp.getmodeldoc
set swassy = c
nstatus = swassy.editpart2(true, false, ninfo)
...
edit sub
no your approach is wrong!
the swassy object must be the assembly that contains all the components. what you are trying to do there is to assign the model doc object of a component (essentially it can either be a part or an assembly depending on the type of the component) to an assembly object and then use that to edit your component.
think of your big assembly as a container that includes several components. what you need to do to edit a component is use the "container" object.
so what you need to do is set your swassy object to be equal to the initial modeldoc object which is the assembly level modeldoc.
set your swassy object in your main to be equal to your swmodel object and then pass it as an argument in your edit function.
also get rid of the declaration for the swassy object in the edit function if you are going to use the same names for the swassy object.
change the edit function to:
sub edit(swcomp as sldworks.component2, swassy as sldworks.assemblydoc)
in this world i am nobody...
and nobody is perfect ;) !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
i can&acute;t get it.
code:
option explicit
sub main()
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
dim swassy as sldworks.assemblydoc
dim swconf as sldworks.configuration
dim swchildcomp as sldworks.component2
set swapp = createobject("sldworks.application")
set swmodel = swapp.activedoc
set swassy = swmodel
set swconf = swmodel.getactiveconfiguration
set swchildcomp = swconf.getrootcomponent
edit swchildcomp, swassy
end sub
sub edit(swcomp as sldworks.component2, assy as sldworks.assemblydoc)
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
dim swchildcomp as sldworks.component2
dim vchildcomp as variant
dim swassy as sldworks.assemblydoc
dim j as integer
dim a as boolean
dim nstatus as long
dim ninfo as long
vchildcomp = swcomp.getchildren 'error 91 in this line
for j = 0 to ubound(vchildcomp)
set swcomp = vchildcomp(j)
a = swcomp.select3(true, nothing)
nstatus = assy.editpart2(true, false, ninfo)
edit swchildcomp, swassy
next j
end sub
edited: 03/10/2009 at 11:11 am by marian ruiz
the only thing that i can think of is that your swcomp object is empty i.e. has value = nothing
make sure that the swcomp object you pass int he edit method is not nothing.
in this world i am nobody...
and nobody is perfect ;) !!!
---------
solidworks office 2008 sp4.0
dell precision pws390
nvidia quadro fx 3450/4000 sdi
when it is running the line edit swchildcomp, swassy
swchildcomp= nothing. but it is ok because this component is a part and it hasn&acute;t any children.
i have tried in other code and i have the error 91 in line nstatus = assy.editpart2(true, false, ninfo)
the problem is that i want to change assembly's components mates so i have to select and edit a component before doing it.
i will try another way!i will tell you...
thank you so much for your help!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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