几何尺寸与公差论坛

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

【转帖】get x,y,z of drawing view vertexedge

[复制链接]
发表于 2009-4-13 11:03:46 | 显示全部楼层 |阅读模式
get x,y,z of drawing view vertex/edge
ok it is the simplest thing yet it seems nearly impossible; i am just after the x and y location relative to the drawing sheet of a vertex or an edge from a drawing view. no matter what i try i cannot get any valid result.
for example say you have a view of a cube and it is positioned in the middle of a drawing sheet. if you get the bottom left edge vertex of the box and call the edge::getstartvertex::getpoint it returns 0, 0, 0 for example as it is the bottom corner in the model. however, i want that position relative to the drawing sheet, which would be something like 0.15, 0.1, 0 (x,y,z in meters).
i have tried using mathutility to create a point and apply a transform to it using the views modeltoviewtransform and modeltoviewtransform.inverse, and neither give the correct result. i have tried using the sheet view, the model view, everything.
it is a simple enough request that seems impossible to do. any advice anyone?
luke,
here is some code i used to for inserting breaklines based on model space. however there is an issue with the transforms in 2008 and the solution from the api group was to do it twice to get the right point.
'get the transform for getting from model space to view space
set viewxform = swview.modeltoviewtransform
'get the transform array to go from paper space to view origin
viewtrans = swview.getxform
transx = viewtrans(0)
transy = viewtrans(1)
nscale = viewtrans(2)
'setup the math point for postion 1 in model space
'ptarray(0) = pos1x * 25.4 / 1000: ptarray(1) = pos1y * 25.4 / 1000: ptarray(2) = pos1z * 25.4 / 1000
boolstatus = swuserunit.converttosystemvalue(cstr(pos1x), ptarray(0))
if not boolstatus then exit function
boolstatus = swuserunit.converttosystemvalue(cstr(pos1y), ptarray(1))
if not boolstatus then exit function
boolstatus = swuserunit.converttosystemvalue(cstr(pos1z), ptarray(2))
if not boolstatus then exit function
vptarray = ptarray
set postion1modelpt = swmathutil.createpoint((vptarray))
set postion1drawingpt = postion1modelpt.multiplytransform(viewxform)
ptarray(0) = (postion1drawingpt.arraydata(0) - transx) / nscale
ptarray(1) = (postion1drawingpt.arraydata(1) - transy) / nscale
ptarray(2) = (postion1drawingpt.arraydata(2) - 0#) / nscale
vptarray = ptarray
set postion1drawingpt = swmathutil.createpoint((vptarray))
edited: 09/05/2008 at 10:18 am by matthew cempa
does it need to detect the point itself, or can you make use of document.getinsertionpoint for the approx. location?
i have got the edge point automatically so its just converting it to sheet view space. i will give the above code a try and let you know
still gives totally wrong values.
swview is the view that contains the edge
e is the edge containing in the view:
mathutility swmathutil = (mathutility)swapp.getmathutility();
mathtransform swviewxform = swview.modeltoviewtransform;
mathpoint mp;
double[] viewtrans = (double[])swview.getxform();
double transx, transy, nscale;
transx = viewtrans[0];
transy = viewtrans[1];
nscale = viewtrans[2];
vertex v = (vertex)e.getstartvertex();
swview.selectentity(v, false);
double[] points = (double[])v.getpoint();
mp = (mathpoint)swmathutil.createpoint(new double[] { points[0], points[1], points[2] });
// model to view transform
mp = (mathpoint)mp.multiplytransform(swviewxform);
points = (double[])mp.arraydata;
double truex, truey;
truex = (points[0] - transx) / nscale;
truey = (points[1] - transy) / nscale;
messagebox.show(truex.tostring() + ", " + truey.tostring());
the values are not even close to any correct value...
i'm not sure this is possible. i know you can insert a view at a particular location, but i'm not sure how reliable it will be to use that view to establish a location on the drawing sheet itself. this is because the relative location can change with when the edit of the view changes (which is 100% controlled by sw s/w).
matt lorono
solidworks 2007 sp3.1
cad engineer/ecn analyst
hi luke,
i know of two things you should be concerned about (and a suggestion).
1) the drawing sheet origin is not always in the bottom left corner
2) the sheet scale affects the position that you are trying to select
also, can you use the view.getlines function then go through them and look for the endpoint most to the bottom and left?
have fun!
luke,
i've played with this and found that i had to account for the model view scale factor using scale = modelview.scale2. can remember if i had to divide or multiply but this will account for how much you are zoomed out or in on the active document view and does affect the numbers based on it.
cadcam systems analyst
-solidworks office premium 2009 sp3.0
-solidworks simulation premium 2009 sp3.0
-solidworks flow simulation 2009 sp3.0
-2 cpu (fx-62), 2.0 gb of ram
-window xp pro sp2
-nvidia geforce 7950 gx2 (512mb) 6.14.11.6921
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 18:14 , Processed in 0.036300 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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