![]() |
【转帖】record macro
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 |
所有的时间均为北京时间。 现在的时间是 03:39 AM. |