![]() |
【转帖】why is distance mate dim is always 1
why is distance mate dim is always 1
i have a routine that makes a mate to an inserted part, but no matter what i put for the distance value, it always makes my distance mate 1" i have the same question for my angle mates, i put 45 as my value, but they come out 58.31007809deg in the assembly. i think it has to do with the values vs units thing?? is the required value a real/integer/etc... and it's not equal to my dim? i'm running the macro in an assembly, and the units are ips (inch pound second) whichis what i want. here are the two commands to make the mates: (the top one is the angle mate and the bottom one is the distance mate) thanks! -wes boolstatus = assy.extension.selectbyid2("front plane@" & swcomp.name2 & "@" & swrootcomp.name2, "plane", 0, 0, 0, false, 0, nothing, 0) boolstatus = assy.extension.selectbyid2("front plane", "plane", 0, 0, 0, true, 0, nothing, 0) assy.addmate 6, 2, 0, 0.06326275636025, 45 boolstatus = assy.extension.selectbyid2("top plane@" & swcomp.name2 & "@" & swrootcomp.name2, "plane", 0, 0, 0, false, 0, nothing, 0) boolstatus = assy.extension.selectbyid2("top plane", "plane", 0, 0, 0, true, 0, nothing, 0) assy.addmate 5, 2, 0, 0.0254, 24 wes mosier cswp in '03 & '08 .forefrontstudios.com 2009 premium x64 bit option explicit sub main() dim swapp as sldworks.sldworks dim swmodel as sldworks.modeldoc2 dim assy as sldworks.assemblydoc dim boolstatus as boolean dim longwarnings as long, longerror as long dim swcomp as sldworks.component2 dim refmodel as sldworks.modeldoc2 dim filter as string dim filename as string dim fileconfig as string dim filedispname as string dim fileoptions as long dim sdoctype as string dim swconfig as sldworks.configuration dim swrootcomp as sldworks.component2 const pi as double = 3.14159265358979 set swapp = application.sldworks ' this following string has three filters associated with it; note the use ' of the | character between filters filter = "solidworks files (*.sldprt; *.sldasm; *.slddrw)|*.sldprt;*.sldasm;*.slddrw|filter name (*.fil)|*.fil|all files (*.*)|*.*" filename = swapp.getopenfilename("file to attach", "", filter, fileoptions, fileconfig, filedispname) ' in the dialog, click the down-arrow associated with files to type to see the filters ' dialogfiles of type down arrow key set swmodel = swapp.activedoc if swmodel.gettype <> swdocassembly then msgbox "open assembly first" exit sub end if if ucase(swmodel.getpathname) = ucase(filename) then msgbox "can't open same file" exit sub end if set assy = swmodel select case ucase(right(filename, 6)) case "sldasm" sdoctype = swdocassembly case "sldprt" sdoctype = swdocpart case else msgbox "wrong type" exit sub end select swapp.documentvisible false, sdoctype set refmodel = swapp.opendoc6(filename, sdoctype, swopendocoptions_silent, fileconfig, longerror, longwarnings) set swcomp = assy.addcomponent4(filedispname, fileconfig, 0, 0, 0) swapp.documentvisible true, sdoctype set swconfig = swmodel.getactiveconfiguration set swrootcomp = swconfig.getrootcomponent boolstatus = assy.extension.selectbyid2("front plane@" & swcomp.name2 & "@" & swrootcomp.name2, "plane", 0, 0, 0, false, 0, nothing, 0) boolstatus = assy.extension.selectbyid2("front plane", "plane", 0, 0, 0, true, 0, nothing, 0) assy.addmate3 swmateangle, 2, 0, 0.632, 0.632, 0.632, 0, 0, 45 * pi / 180, 45 * pi / 180, 45 * pi / 180, false, longerror the following link was submitted by handleman in his 19 nov 07 10:55 post in okay, i think the light switches are starting to flicker on now.... based on the angle mate code that ivana provided me, it looks like the api deals with radians. i seem to remember something about that from my old college days. thanks for that! what about the distance mates though... do they only deal with milimeters or something? why is it that when i replace my code with yours for the distance mate, it still comes out 1"?? kelvin, when i look at your routine, i see you're adding the mate, then changing it. is this because sw won't allow you to add the exact distance to begin with? wes mosier cswp in '03 & '08 .forefrontstudios.com 2009 premium x64 bit answer according to the api help, the usage syntax for addmate is: void assemblydoc.addmate ( matetype, align, flip, dist, angle) your code has 0.0254 for the "dist" argument. this specifies a mate distance of 0.0254 meters, or 1". the 24 in your code is the "angle" argument, which is ignored for a distance mate. 45 radians is about 2578.31 degrees, which corresponds to 58.31 degrees after you subtract out 7*360. i'll get you eh steve, if it's the last thing i dooooo! excellent, thanks everybody! all i needed to do was get the correct placement of my dimension, and change it's value to meters instead of inches. -thanks! wes mosier cswp in '03 & '08 .forefrontstudios.com 2009 premium x64 bit wes, i have no clue about the code in the link i posted. i am api illiterate. i just posted here because the macro seemed like a good fit. work: p4-2.8ghz, 2gb ram, asus mobo, nvidia quadro fx500/600 home: c2d e8400-3ghz, 4gb ram, asus-nvidia mobo with integrated quadro fx470 xp pro-sp3 x32, sw2009-sp3 and /3gb switch on both (/userva option not needed) quick |
所有的时间均为北京时间。 现在的时间是 06:06 PM. |