几何尺寸与公差论坛------致力于产品几何量公差标准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:07 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】how can i do to select a componen

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!
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】select and center all dimensions on a drawing yang686526 SolidWorks二次开发 0 2009-04-12 07:33 PM
【转帖】select all bodies for extrudecu yang686526 SolidWorks二次开发 0 2009-04-12 07:32 PM


所有的时间均为北京时间。 现在的时间是 12:38 PM.


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