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

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


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】api hooks for new bom reorganization functionality yang686526 SolidWorks二次开发 0 2009-04-12 11:04 PM
【转帖】cosmosworks api questions yang686526 SolidWorks二次开发 0 2009-04-12 08:32 PM
【转帖】solidworks 2008 api book - released yang686526 SolidWorks二次开发 0 2009-04-12 07:38 PM
【转帖】外挂开发中的封包技术 huangyhg vc编程 0 2007-12-03 04:41 PM
【转帖】对于hook函数的一点认识 huangyhg vc编程 0 2007-03-27 11:53 AM


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


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