几何尺寸与公差论坛

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

【转帖】record macro

[复制链接]
发表于 2009-4-13 13:49:09 | 显示全部楼层 |阅读模式
record macro
please see the code below
i used record macro to create this macro
when i run it, i got a runtime error at the highlight line
i think when i used record macro, the sketch and dimenion are d1 and sketch7; however, when i run this macro with diff. part, the names of dimension and sketch are diff., so how to control the names here?
thx, chris
dim swapp as object
dim part as object
dim selmgr as object
dim boolstatus as boolean
dim longstatus as long, longwarnings as long
dim feature as object
sub main()
set swapp = application.sldworks
set part = swapp.activedoc
set selmgr = part.selectionmanager
part.sketchmanager.insertsketch true
boolstatus = part.extension.selectbyid2("", "face", 0.01001749844499, -9.885070821838e-04, 0.0100000000001, false, 0, nothing, 0)
part.clearselection2 true
part.sketchrectangle 0.008294147041225, -0.003565252671621, 0, 0.02336194267531, -0.008393607073705, 0, 1
part.clearselection2 true
part.createtangentarc2 0.02336194267531, -0.003565252671621, 0, 0.02336194267531, -0.008393607073705, 0, 1
part.clearselection2 true
part.setpickmode
part.createtangentarc2 0.008294147041225, -0.003565252671621, 0, 0.008294147041225, -0.008393607073705, 0, 1
part.clearselection2 true
part.setpickmode
boolstatus = part.extension.selectbyid2("line1", "sketchsegment", 0.01095806671134, -0.003398757692239, 0.005, false, 0, nothing, 0)
dim annotation as object
set annotation = part.adddimension2(0.0142047, -0.000651591, 0.01)
part.clearselection2 true
part.parameter("<A href="mailto:d1@sketch7").systemvalue">d1@sketch7").systemvalue = 0.015
part.setpickmode
part.clearselection2 true
boolstatus = part.extension.selectbyid2("point2", "sketchpoint", 0.02329414704122, -0.008393607073705, 0, false, 0, nothing, 0)
boolstatus = part.extension.selectbyid2("point4", "sketchpoint", 0.02329414704122, -0.003565252671621, 0, true, 0, nothing, 0)
set annotation = part.adddimension2(0.0296055, -0.00572969, 0.01)
part.clearselection2 true
part.parameter("<A href="mailto:d2@sketch7").systemvalue">d2@sketch7").systemvalue = 0.005
part.clearselection2 true
part.sketchmanager.insertsketch true
end sub
solidworks 2007 (office pro.) sp5.0
testing solidworks 2009 (pro) sp0.0
dell precision t3400
2 cpu (8500) 3.16 ghz, 3.25 gb of ram
window xp pro sp2
nvidia fx 570 6.14.11.6262
edited: 05/22/2008 at 12:17 pm by chris ch
chris,
you are right. the dimension name is changing. when you add the dimension two lines before you set the value, it is setting the annotation object to this newly created displaydimension object.
you can add a
dim dimension as object
set dimension = annotation.getdimension2
now you can use one of three of the dimension object's methods. setsystemvalue3, setuservaluein2, or setvalue3 to change the value.
wayne matus
texas engineering systems
thx, wayne
jus wondering how you'd do with the sketch name?
chris
solidworks 2007 (office pro.) sp5.0
testing solidworks 2009 (pro) sp0.0
dell precision t3400
2 cpu (8500) 3.16 ghz, 3.25 gb of ram
window xp pro sp2
nvidia fx 570 6.14.11.6262
if you know the dimension name, just replace d1@sketch7 with it. if you do not know the name, then you would still have to get the dimension object like i mentioned in the previous reply. but you could use "dimension.name" to get the dimension name.
wayne matus
texas engineering systems
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 08:51 , Processed in 0.036690 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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