![]() |
【转帖】macro
macro
i am having difficulty with creating ellipses with a macro. after i create the partial ellipse and revolve it, i run the macro and i receive an error saying 'wrong number of arguments or invalid property assignment'. anyone know why this error comes up? i have seen the macro recorder record the wrong number of arguments for some methods. look at the api help file to find out what arguments it needs. not sure if this is the method that was recorded, but here is what i found in the api help for partial ellipse. retval = sketchmanager.createellipticalarc ( xc, yc, zc, xmajor, ymajor, zmajor, xminor, yminor, zminor, x1, y1, z1, x2, y2, z2, direction) input: (double) xc x coordinate for the ellipse center point input: (double) yc y coordinate for the ellipse center point input: (double) zc z coordinate for the ellipse center point input: (double) xmajor x coordinate for a point on the ellipse and on the major axis input: (double) ymajor y coordinate for a point on the ellipse and on the major axis input: (double) zmajor z coordinate for a point on the ellipse and on the major axis input: (double) xminor x coordinate for a point on the ellipse and on the minor axis input: (double) yminor y coordinate for a point on the ellipse and on the minor axis input: (double) zminor z coordinate for a point on the ellipse and on the minor axis input: (double) x1 x coordinate for counter-clockwise elliptical arc start point input: (double) y1 y coordinate for counter-clockwise elliptical arc start point input: (double) z1 z coordinate for counter-clockwise elliptical arc start point input: (double) x2 x coordinate for counter-clockwise elliptical arc end point input: (double) y2 y coordinate for counter-clockwise elliptical arc end point input: (double) z2 z coordinate for counter-clockwise elliptical arc end point input: (short) direction +1 : go from the start point to the end point in a counter-clockwise direction -1 : go from the start point to the end point in a clockwise direction output: (lpsketchsegment) retval sketch segment for the elliptical arc wayne matus texas engineering systems for example: option explicit dim swapp as sldworks.sldworks dim swmodel as modeldoc2 dim sm as sketchmanager sub main() set swapp = application.sldworks set swmodel = swapp.activedoc if swmodel is nothing then exit sub end if set sm = swmodel.sketchmanager if sm is nothing then exit sub end if sm.createellipticalarc 0, 0, 0, 0.02, 0, 0, 0, 0.01, 0, 0, 0.01, 0, 0.02, 0, 0, -1 end sub hi this is the line code i get when after i record making the ellispe. i added the -1 at the end to see if it was missing an argument. still get the same error. i don't know what vb is for: part.createellipsevb -0.001791025641026, 0.02134305555556, 0, -0.001791025641026, 0.05776057692308, 0, -0.02417884615385, 0.02134305555556, 0, 0, -0.01495774268682, 0, 0, 0.05764385379793, 0, -1 recorded macro output should always be viewed with suspicion. rarely yields the best way to accomplish a task. perhaps "createellipticalarcbycentervb"? shawn, it looks like you are using solidworks 2007. i get the same createellipsevb method when i record macro in 2007. in 2008 i get what luke and i mentioned. i looked in the 2007 api help and there was not a createellipsevb method listed, but i did find a createellipticalarc2 method. you should be able to change the line you mentioned to: part.createellipticalarc2 -0.001791025641026, 0.02134305555556, 0, -0.001791025641026, 0.05776057692308, 0, -0.02417884615385, 0.02134305555556, 0, 0, -0.01495774268682, 0, 0, 0.05764385379793, 0 note it does not need the -1 at the end. wayne matus texas engineering systems thanks will try hi, luke, your codes don't work in vb.net 2008, do you have a way to fix it? the code i provided was vb not vb.net, it is easy enough to convert though: create a new windows forms application, add references to sldworks as required and create a button on the form and add an onclick event, then your coding should look like this: imports sldworks imports swcommands imports swconst imports swpublished public class form1 private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click dim swapp as sldworks.sldworks dim swmodel as modeldoc2 dim sm as sketchmanager swapp = new sldworks.sldworks swmodel = swapp.activedoc if swmodel is nothing then exit sub end if sm = swmodel.sketchmanager if sm is nothing then exit sub end if sm.createellipticalarc(0, 0, 0, 0.02, 0, 0, 0, 0.01, 0, 0, 0.01, 0, 0.02, 0, 0, -1) end sub end class |
所有的时间均为北京时间。 现在的时间是 07:38 PM. |