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

sw api practices
hello fella's !
i was wondering ...
what's the best, most stable, or quickest way to program the following situation.
a part has 4 configurations.
the user picks a configuration via a form.
a var is set :
scname = "requestedconfig"
the code changes the configuration :
boolstatus = modeldoc2.compconfigproperties4(2, 0, true, true, scname, false)
this changes the configuration on the part, even when the current active config is the same as the requested config by the user right ?
is it more efficient/stable if i got it to check the active current configuration on the part with the one requested, and only if they aren't the same, then configure the part with the requested config ?
else, just leave it like that ?
thing is, i'm switching a config on a part, and on many occasions, it crashes my macro ..
what's your opinion ?
greets,
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
bert,
i don't see why it should be a problem activating an already active configuration. i have made a number of configurator solutions working just like that and it has never been a problem. there must be some other unstable elements in your setup.
have you tracked it down to crash exactly when the configuration is changed?
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
you are much better getting the component and changing the referenceconfiguration than you are resetting all configuration properties.
jorn,
i didn't have a problem with this, up till now .. for some reason, my macro (wich is getting somewhat elaborate ) crashes each type it has to change a config this way.
luke,
could you possibly be bothered to write me some samplecode on how i can change the config as you have suggested ?
i allways start off with a selected part by using
boolstatus = modeldoc2.etc
i'd be very greatfull !
overall, as my macro is getting better and "heavier" i'm starting to look into what is more efficient, lean and mean when it comes to code ...
this is a disipline on its own i rekon.
greets,
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
bert,
all depends how you want to obtain the component, you can select it directly using selectbyid2, or loop all components in an assembly.
once you have the component2 object you literally just call
comp.referencedconfiguration = "configname"
if you provide a bit more info about your layout i can provide a method to get the components.
heya luke ! sorry for my delayed reply ...
in general, my macro looks like this (altough 40x longer and more actions to be taken) but as an example, this is how i select my parts, change my dimensions, suppress parts or features, switch configurations etc ..
dim swapp as object
dim modeldoc2 as object
dim mydimension as object
dim boolstatus as boolean
dim longstatus as long, longwarnings as long
sub main()
set swapp = application.sldworks
set modeldoc2 = swapp.activedoc
'set lenght of cube
boolstatus = modeldoc2 .extension.selectbyid2("d1@sketch1@part1.sldprt", "dimension", 0.04364437810937, 0.0130670150456, -0.05171008214468, false, 0, nothing, 0)
modeldoc2 .parameter("<A href="mailto:d1@sketch1").systemvalue">d1@sketch1").systemvalue = 0.1
'set width of cube
boolstatus = modeldoc2 .extension.selectbyid2("d2@sketch1@part1.sldprt", "dimension", 0.0582534341154, -0.01778784542079, -0.03546929205944, false, 0, nothing, 0)
modeldoc2 .parameter("<A href="mailto:d2@sketch1").systemvalue">d2@sketch1").systemvalue = 0.075
'suppress hole in cube
boolstatus = modeldoc2 .extension.selectbyid2("hole", "bodyfeature", 0, 0, 0, false, 0, nothing, 0)
modeldoc2 .editsuppress2
'set cub height to 50mm
boolstatus = modeldoc2 .extension.selectbyid2("d1@cube@part1.sldprt", "dimension", 0.03768076751945, 0.005412183250505, -0.03809288378403, false, 0, nothing, 0)
modeldoc2 .parameter("<A href="mailto:d1@cube").systemvalue">d1@cube").systemvalue = 0.05
'switch cube configuration to config2
boolstatus = modeldoc2 .extension.selectbyid2("config2@part1.sldprt", "configurations", 0, 0, 0, false, 0, nothing, 0)
boolstatus = modeldoc2 .compconfigproperties4(2, 0, true, true, "config2", false)
'do a final rebuild
boolstatus = modeldoc2 .forcerebuild3(true)
end sub
this has been working well for a long time. still, as my macro grows to be more and more a full-blown configurator, it comes to this point that when switching configurations this way, the macro halts, pauzes and crashes (without giving me an error).
if i comment out the lines of code responsible for switching configs, then there aren't any problems.
could the following better in my case ? :
boolstatus = modeldoc2 .extension.selectbyid2("config2@part1.sldprt", "configurations", 0, 0, 0, false, 0, nothing, 0)
boolstatus = modeldoc2 .showconfiguration2("config2")
but does this work on a part in a subassy aswell ?
many thnaks in advance to all of you, for your opinions or advice !
yours,
bert
*edit* removed typos in code*
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
edited: 03/25/2009 at 06:19 am by bert de spiegelaere
change this:
'switch cube configuration to config2
boolstatus = modeldoc2 .extension.selectbyid2("config2@part1.sldprt", "configurations", 0, 0, 0, false, 0, nothing, 0)
to this:
'switch cube configuration to config2
boolstatus = modeldoc2 .extension.selectbyid2("myitem-1@part1", "component", 0, 0, 0, false, 0, nothing, 0)
where "myitem-1@part1" is the string used to select the component from the feature manager tree at the left that you wish to change the configuration of. just record a macro, select it then look at the macro for the correct string.
then do this:
dim selmgr as selectionmgr
set selmgr = modeldoc2.selectionmanager
dim comp as component2
set comp = selmgr.getselectedobject6(1,-1)
comp.referencedconfiguration = "config2"
that seems to work !
altough i'd might want to make a seperate sub ( like : call changeconfig) as repeating that block of code would start to look "heavy" .
odd thing is, when i work via following code :
boolstatus = modeldoc2 .extension.selectbyid2("config2@part1.sldprt", "configurations", 0, 0, 0, false, 0, nothing, 0)
boolstatus = modeldoc2 .showconfiguration2("config2")
it works too, quick and stable.
wich one is better then ?
greets,
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
showconfiguration2 is a method, referencedconfiguration is a property, so naturally the property would be quicker, but could not say without benchmarking the 2.
heya luke, i'll have to take back what i said about the referencedconfiguration doing it for me ..
its all good when i switch configurations on sub-assy's but as soon as i want to switch configs on parts within those sub-assy's , it fails.
the other method (showconfiguration2) works fine on both.
what do you suggest i should do ?
regards,
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
place the sub-assembly into edit mode first. thats all the showconfiguration method will do
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】solidworks 2008 api book - released yang686526 SolidWorks二次开发 0 2009-04-12 07:38 PM
【转帖】doc manager api requires presence of solidworks explorer yang686526 SolidWorks二次开发 0 2009-04-12 06:00 PM
【转帖】外挂开发中的封包技术 huangyhg vc编程 0 2007-12-03 04:41 PM
【转帖】对于hook函数的一点认识 huangyhg vc编程 0 2007-03-27 11:53 AM


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


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