几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-13, 11:03 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】get x,y,z of drawing view vertexedge

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
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】drawing view placements yang686526 SolidWorks二次开发 0 2009-04-13 10:35 AM
【转帖】drawing view extents ... got huge yang686526 SolidWorks二次开发 0 2009-04-13 10:34 AM
【转帖】drawing view creation yang686526 SolidWorks二次开发 0 2009-04-13 10:34 AM
【转帖】change a drawing views display state yang686526 SolidWorks二次开发 0 2009-04-13 09:36 AM
【转帖】can you modelize a drawing view yang686526 SolidWorks二次开发 0 2009-04-13 09:31 AM


所有的时间均为北京时间。 现在的时间是 02:49 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多