几何尺寸与公差论坛

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

【转帖】edit dimensions within patterns

[复制链接]
发表于 2009-4-12 20:46:34 | 显示全部楼层 |阅读模式
edit dimensions within patterns
a new day, a fresh new post.. about another problem
i got this pattern within a sub-assy.
i can succesfully and without any hassle alter the d3 dimension of it (the spacing of the pattern). but
for some odd reason i can't seem to change the d1 dimension of the pattern (dictates the # of instances)
allow me to post a snippet of my code :
boolstatus = modeldoc2.extension.selectbyid2("d1@patroon links@deur-1@draaideur", "dimension", -0.5391050629386, 1.732050214792, 0.07460631424376, false, 0, nothing, 0)
set mydimension = modeldoc2.parameter("d1@patroon links@deur.assembly")
mydimension.systemvalue = asch
boolstatus = modeldoc2.extension.selectbyid2("d3@patroon links@deur-1@draaideur", "dimension", -0.5466265051487, 1.747759246485, 0.06642127771258, false, 0, nothing, 0)
set mydimension = modeldoc2.parameter("d3@patroon links@deur.assembly")
mydimension.systemvalue = (nuh - 456) / (asch - 1) / 1000
asch and nuh are both singles .
asch varies between 2 - 5
so nothing exotic here i suppose.
i was wondering if this has anything to do with this "scope of selection" that seems to rule over parts/features in sub-assy's ? but then again, it does change 1 of 2 dimensions, so why not both ?
all advice / inputs are more then welcome !
greetings,
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
bert,
god morning. what a good spirit you have - it's refreshing!
have you verified that the calculation returns the value you expect? step through the code and read the value on the fly, make a message box with the value or debug.print the value to verify.
changing dimensions can be made much simpler. omit these type of lines:
boolstatus = modeldoc2.extension.selectbyid2("d3@patroon links@deur-1@draaideur", "dimension", -0.5466265051487, 1.747759246485, 0.06642127771258, false, 0, nothing, 0)
set mydimension = modeldoc2.parameter("d3@patroon links@deur.assembly")
...and simply use this:
modeldoc2.parameter("d3@patroon <A href="mailto:links@deur.assembly").systemvalue">links@deur.assembly").systemvalue = (nuh - 456) / (asch - 1) / 1000
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
god morgen j&oslash;rn !
thank you for the tip on how to better change my dimensions !
its tips like these that help my code to be more compact en readable !
i've double-checked the value of asch and it is correct. debug.print gave me te right value.
could it have something to do with the unit ? i doubt it has ..
what i mean is, my inputs and values of distance are all in millimeters.
in my code i have to work in meters, making me divide by 1000 (result/1000) to set the dimension.
funny case is, in this very same macro (but in a section that handles another assy) i find myself in the same situation. changing a "component pattern" within a sub-assy and there it does work !
only visible difference is, that in that case , the value of the dimension is set not by a variable, but by a formula.
only conclusion i can come to, is that all dimensions on component patterns change fine here; if the value evaluates out of an formula.
example :
modeldoc2.parameter("d3@patroon <A href="mailto:links@deur.assembly").systemvalue">links@deur.assembly").systemvalue = (nuh - 456) / (asch - 1) / 1000
ok
modeldoc2.parameter("d1@patroon <A href="mailto:links@deur.assembly").systemvalue">links@deur.assembly").systemvalue = asch
not ok
wierd ?.. i'm sure there is more to it than meets the eye ..
*edit*
whoops; now thats not entirely true.
looking into my methods, i see i've used a value of 1 on several patterns in order to "supress" them !
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
edited: 03/19/2009 at 05:16 am by bert de spiegelaere
answer bert,
hmmm... in most cases like this it is either because the value calculated is different than what is expected (you ruled that one out already) - or because the referenced dimension name is not correct.
in order to chech the last case the easiest way is to record a small macro where you change the dimension in question and then compare it to the code you already have - or right away make a copy-paste of the dimension name from the recorded macro to your own code. you could also try to play a little with the recorded macro to verify if that one is able to change the dimension.
one step back and two steps forward - that's the way of programming (sometimes).
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
as i'm not oldtimer in sw-api, i still hold the habit of recording actions to get correct selections on parts/features or any other component for that matter.
i recorded the wanted action once again, and did a playback. that worked nicely !
after that i cleaned up the recorded code. still worked fine on plaback.
then i copied my cleaned up code into my own macro, and it still works !
hmm must of been a very slight error in the code, as i'm still looking into what the difference between the two is/was ..
good news, afterall it works ! odd thing is it must of been just a little thing i've overlooked time over time ...
thanks j&oslash;rn !
greets,
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
you're welcome. it is very easy to overlook a small difference in a dimension name, feature name etc. i therefore often record a small macro in these cases and copy-paste the name - just to be sure the name is correct.
jorn bjarning
cswp
cad & plm consultant
sw2008 sp5 / sw2009 sp2
yes, i do the same to obtain the correct names and such.
but, looks like i cheered too early.
it works now, but only half the time.
and i think i know why.
let me sketch the situation :
1 assembly with 2 configs : left & right
in the assembly i got 2 patterns : left pattern & right pattern
when switching configurations, one pattern gets suppressed, the other unsuppressed.
my code works as follows ;
-it switches to the desired configuration (if needed, if configuration is the desired one allready it does nothing)
-it alters the active pattern (the one not suppressed)
this works fine, only if the desired configuration and thus the desired pattern are active before the code runs. then the pattern is set correctly.
however, if the assembly is configured as "right" and gets switched to "left" by the code and then the left pattern is altered, it fails to take the "amount of instances" dimension , the "spacing" dimension gives no problems ...
re-doing this manually i do get the misplaced error from time to time telling me :
"can only edit this dimension in the active configuration." whilst the pattern isn't suppressed at all ....
wierd ..
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
i sorta solved this problem, but not in the way i tought i would.
the thing was :
when i unsupressed a pattern directly followed by a change on the dimension of "number of instances" , it didn't "catch on".
what i do now is, have none of the 2 patterns suppressed. i set the one i don't need to a value of 1 (invisible really) and the other on the desired value, and switch freely this way.
it works without glitching thus i'm happy with it !
greets,
bert
solidworks professional 2009 sp2.0
hpxw4400 workstation
intel core2 cpu
6600 @ 2.40ghz
yes, i'm aware i have a funky surname ....
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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