几何尺寸与公差论坛

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

【转帖】part properties through drawing

[复制链接]
发表于 2009-4-12 22:00:18 | 显示全部楼层 |阅读模式
part properties through drawing
does anyone know how to access custom properties of a part through a drawing?
i am writing some code which runs on a drawing but i also need to access some of the properties of the part/assembly that it references.
any ideas?
thanks
you will need to get a handle for the modeldoc2 object of the part in the view you are interested in.
i'll get you eh steve, if it's the last thing i dooooo!
then
swmodel.filesummaryinfo
that should bring it up the window to change the property settings.
solidworks 2006,2007,2008,2009 (office premium.)
core 2 duo e6850 @ 3.00 mhz
window xp pro sp3 32 bit
ati firegl v7350
thanks but i need to be able to access these programatically without user intervention.
i already have a handle for the modeldoc2 object but that is only enables me access to the properties of the drawing ifself not the part/assembly on the drawing.
you need to get a handle for the modeldoc2 object of the part in the view you are interested in. each view in a drawing points to a modeldoc2 object. each drawing document can have multiple sheets. each sheet can have multiple views all pointing to different parts/assemblies. how are you planning to handle that possibility? if you think it's not likely to happen in your case, you can probably get away with drawingdoc::getfirstview and then cycling through the views with view::getnextview until you find a view that returns a valid pointer to a modeldoc2 object from view::referenceddocument.
i'll get you eh steve, if it's the last thing i dooooo!
this is what i have so far...
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
dim swselmgr as sldworks.selectionmgr
dim swview as sldworks.view
dim swdrawmodel as sldworks.modeldoc2
dim smodelname as string
set swapp = application.sldworks
set swview = swapp.activedoc.getfirstview
while not swview is nothing
debug.print " " & swview.getname2 & " [" & swview.type & "]"
set swview = swview.getnextview
wend
end sub
but it still refuses to work...i get to a drawing view and try to get the referenceddocument but it does not work....
any ideas?
thanks
just worked it out...little trickier than the help files made out but i got there in the end.
thanks to all who contributed
david:
i know you've already worked out a solution, but i thought i'd share this in case it might help someone else.
i use swmodelref.getdependencies2 and act upon the returned array. i assume the first referenced document is the intended one, so if there are more than one this may not work as expected. the following code snippet should work:
vdepend = swmodelref.getdependencies2(false, false, false)
if ubound(vdepend) = -1 then
vresponse = msgbox("no model is associated with this drawing", vbokonly)
shutdown (false)
end if
if right(vdepend(1), 6) = "sldprt" then
set swmodel = swapp.opendoc6(vdepend(1), swdocpart, swopendocoptions_silent, "", 0, 0)
elseif right(vdepend(1), 6) = "sldasm" then
set swmodel = swapp.opendoc6(vdepend(1), swdocassembly, swopendocoptions_silent, "", 0, 0)
else
vresponse = msgbox("invalid filetype is associated with this drawing", vbokonly)
shutdown (false)
end if
you could augment this to handle multiple references. for example, you could gather all of the filenames and prompt the user to choose one of them.
regards,
john.
sw 2007 sp5
optimist: "the glass is half full"
pessimist: "the glass is half empty"
engineer: "the glass is twice as big as it needs to be"
edited: 02/03/2009 at 01:42 pm by john manly
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 20:30 , Processed in 0.036309 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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