|
mathpoint in sw drawing
i am trying to write a macro that automates drawing creation for my fixture layouts and i am having a problem inserting a block into the sheet template. the problem is that no matter what values i put in the variant array to create the mathpoint the result is corrupt. for example the variant array has values of 8 ,8, and 0 but the mathpoint.arraydata shows 2.47e-324, 8, 2.47e-324 respectively.
what am i doing wrong?
many thanks
robert luck
here is my code
sub insertblock(block as string, xpos as double, ypos as double, zpos as double)
const blockpath as string = "j:\solidworks\blocks\"
const distscale as long = 1
dim vpoint(2) as variant
dim swmathpoint as mathpoint
dim swsketchblockdef as sldworks.sketchblockdefinition
dim swblockinst as sldworks.sketchblockinstance
dim swsketchmgr as sldworks.sketchmanager
dim swdraw as sldworks.drawingdoc
dim swsheet as sldworks.sheet
set swapp = application.sldworks
set swmodel = swapp.activedoc
set swdraw = swmodel
set swsheet = swdraw.getcurrentsheet
set swselmgr = swmodel.selectionmanager
vpoint(0) = xpos * distscale
vpoint(1) = ypos * distscale
vpoint(2) = zpos * distscale
set swmathutil = swapp.getmathutility
set swmathpoint = swmathutil.createpoint(vpoint)
set swmodel = swapp.activedoc
set swsketchmgr = swmodel.sketchmanager
swmodel.setaddtodb true
swmodel.edittemplate
swmodel.editsketch
swmodel.clearselection2 true
set swsketchblockdef = swsketchmgr.makesketchblockfromfile(swmathutil.createpoint(vpoint), (blockpath & block), true, 1, 0)
swmodel.setaddtodb false
swmodel.editsheet
swmodel.graphicsredraw2
end sub
robert luck
production engineer ~ cam programmer
try putting the vpoint variable in parenthesis when you use it to create the point. i struggled with this for a while also and the trick seems to be that to pass it as a safe array you must enclose it in parens like this:
set swmathpoint = swmathutil.createpoint((vpoint))
thanks for that matthew. i have tried what you suggest but the results are just the same. i have even tried changing the swmathpoint.arraydata individually after creation, but sw just will not have it - no errors, no alarms - it is just as if the line of code didn't exist.
i am getting very frustrated with this thing.
robert luck
production engineer ~ cam programmer
further to my trials with creating a mathpoint, i have given up. the approach i am now trying is to set the block insertion point to "nothing" eg
set swsketchblockdef = swsketchmgr.makesketchblockfromfile(nothing, (blockpath & block), true, 1, 0)
then move the block instance to tthe position i require. it seem very primitive but i just cannot spend any more time getting the mathpoint to work.
robert luck
production engineer ~ cam programmer
robert, change your const distscale to .0254, as the solidworks api handles coordinates in metric by default. then, each coordinate you select will be converted from metric to inch. let me know if that works.
to defeat the wheat, go against the grain.
quick |
|