几何尺寸与公差论坛

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

【转帖】couple of api questions

[复制链接]
发表于 2009-4-13 09:59:27 | 显示全部楼层 |阅读模式
couple of api questions
i have done some searching and after a while i decided to ask here.
does anyone know what objects i need to call to get at the property of a selected dimension?
i want to pick a dim in a sketch and run my macro -
it will capture that dim and a corresponding dim associated with with by name and swap the driven/driving status of the dims.
for example:
there are 2 dims:
la@sketch1 and lb@sketch1
la is a driving dim and lb is driven. i want to pick on la and click my macro and make la driven and lb driving. i will select the other dim based off the name of the selected dim.
im having trouble finding out where to find that stuff in the api i tried receording a macro but it gives me nothing that is useful.
my other question deals with equations in a part file. i want to pick a dimension that has an equation tied to it and use that dimensions name to search the list of equations in a part file and toggle it on or off.
most of this deals with my lack of solidworks api knowledge and the timeframe in which i have to complete this macro  any help would be greatly appreciated. even if it is just to point me to the right object i need to access to get at the properties i want to manipulate.
thanks!
solidworks professional 2009 sp0
dual core amd opteron 2.21ghz cpu
4 gb ram
nvidia quadrofx 4500 w/ 512mb ram
the dimension object has a property called "drivenstate" that can be used to get/set that attribute.
'--------------------
dim la as object
dim lb as object
' make dimension d1@sketch1 on part (assumed set) into a driven dimension
set la = part.parameter("la@sketch1")
set lb = part.parameter("lb@sketch1")
' constants pulled from swdimensiondrivenstate_e enumeration
la.drivenstate = swdimensiondriven
lb.drivenstate = swdimensiondriving
your equation problem shouldn't be too hard to tackle either..but will require some research...
hope this helps in the meantime...
brian titus, cswp
zeometric llc
dell precision m6300
solidworks office premium 2007/2008/2009
in follow up, i'd use the equation manager in solidworks to parse each of the equation strings looking for dimension name in question.
sub main()
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
dim sweqnmgr as sldworks.equationmgr
dim i as long
dim ncount as long
dim bret as boolean
set swapp = application.sldworks
set swmodel = swapp.activedoc
set sweqnmgr = swmodel.getequationmgr
debug.print "file = " & swmodel.getpathname
debug.print " status = " & sweqnmgr.status
ncount = sweqnmgr.getcount
for i = 0 to ncount - 1
debug.print " eqn(" & i & ") = " & sweqnmgr.equation(i)
debug.print " value = " & sweqnmgr.value(i)
debug.print " supp = " & sweqnmgr.suppression(i)
next i
end sub
brian titus, cswp
zeometric llc
dell precision m6300
solidworks office premium 2007/2008/2009
i tried receording a macro but it gives me nothing that is useful.
get used to that.
the object and property you need is dimension:: drivenstate
actually getting the dimension object can be a trick. if you are getting it from a selection, the selected object will be a displaydimension object, and you will need to use displaydimension::getdimension to get the dimension object from the displaydimension object.
thanks guys!
total time savers! i wish i had time to research the solidworks object model the way i want to.  silly employers want me to design while i'm in the office though! hahah go figure!
solidworks professional 2009 sp0
dual core amd opteron 2.21ghz cpu
4 gb ram
nvidia quadrofx 4500 w/ 512mb ram
i am flipping the status of the dimensions just fine now - although i need to refesh the view somehow.
if i throw a editrebuild3 it rebuilds ok aside from the fact that it exits my sketch.
the dimensions change as expected although the driving dimension remains greyed out and the driven dimension remains black.
if i double click the black (driven) dimension it pops a messagebox telling me its a driven dim and then it turns grey.
if i click the grey dim (driving) it opens the edit dim dialog and i can change the dim and it turns black.
anyone know what solidworks is calling that refreshes the graphics area? i am thinking rebuild is not what i want. it's like i want redraw the screen.
tia
solidworks professional 2009 sp0
dual core amd opteron 2.21ghz cpu
4 gb ram
nvidia quadrofx 4500 w/ 512mb ram
try a forcerebuild3 instead of an editrebuild3, might fix that...
no dice
i looked into modelview::graphicredraw() but it didn't seem to do anything at the sketch level.
oddly enough, if i scroll my mouse wheel after running my code the dims redraw and show up properly.
i'm going to dig some more - there has to be some kind of screen refresh or redraw.
solidworks professional 2009 sp0
dual core amd opteron 2.21ghz cpu
4 gb ram
nvidia quadrofx 4500 w/ 512mb ram
edited: 10/10/2008 at 09:33 am by jake johnson
bah no luck yet -
anyone know how to repaint the graphics area? i don't want a rebuild.
i need to redraw the screen so to speak - my program is making the changes i want to some dimensions although they are not being displayed correctly until i do something like roll my mouse wheel or pan the screen.
solidworks professional 2009 sp0
dual core amd opteron 2.21ghz cpu
4 gb ram
nvidia quadrofx 4500 w/ 512mb ram
not sure if this will work for you. it's from the api help.
'----------------------
' preconditions: model document is open.
'
' postconditions: graphics area is redrawn.
'-----------------------
option explicit
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
sub main()
set swapp = application.sldworks
set swmodel = swapp.activedoc
swmodel.graphicsredraw2
end sub
'----------------------
tobin sparks
.nov.com
more info:
my sketch line remains fully defined after changing the dimension to a driven dim.
let me clarify that one: it is black in color - but if i drag the line it changes to blue.
so it appears that nothing being updated - but the changes are being made.
the behavior i need to mimic is when you have a fully defined sketch and right click a dimension and change it from driving to driven. when you do this through solidworks it updates the dim and the line with the changes. (the dim turns gray and the line turns blue)
when i do this via code the changes happen as expected although the dim stays black and so does the line.
when i pan, zoom or rotate the dim turns gray like it should but the line remains black until i drag it then it goes blue on me.
tobin: i looked in the api help and only saw references to graphicsredraw, not graphicsredraw2 but it ran with no errors in the code - although it didn't seem to do anything.  i was hoping! haha
solidworks professional 2009 sp0
dual core amd opteron 2.21ghz cpu
4 gb ram
nvidia quadrofx 4500 w/ 512mb ram
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-24 03:02 , Processed in 0.036450 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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