几何尺寸与公差论坛------致力于产品几何量公差标准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-12, 09:59 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】part coordinates

part coordinates
hello,
i am trying to set the positioning of the part(pipe) attached within an assembly. i am already calculating and changing the length dimension of this part based on the two x,y,z coordinates.
how do i go about placing this part in the right position based on the coordinates given. do i need to use transforms - i am not too fimiliar with what these are?
any code examples/tips/help would be very appreciated.
thanks
edited: 10/03/2008 at 01:24 am by vincent nesbitt
vincent,
you are on the correct path with transforms.
see the function
component2.transform2
you can use it both retrieve and set the parameters
look it up in the api help provided with solidworks. when you find it, click the 'component transform' link to see the explanation of transforms.
they are not terribly difficult to understand, especially if you known anything about linear algebra.
assuming you don't know that, i can provide you with a simple solution.
1) retrieve the transform using: component2.transform2
2) extract the data using: mathtransform.getdata2
this will return some mathvectors for the orientation of the x,y, z axis and position of the part in assembly coordinants.
3) now you must know the location of the origin of the part. is it at one end the part? is it in the center of the part?
4) if you know where it is, then you can calculate where you want origin of the part in assembly coordinants.
5) if you want the part oriented the same way and only shifted within assembly space, you can create a new position vector using: mathutility.createvector
6) and then you can then create a transform using the old orientation data and the new position data using: mathutility.composetransform
note that you should put 1 in for the scaling
7) now use component2.transform2 to set the new transform
this works only if you don't have any mates fully constraining the model.
hope that helps.
anthony
i am conviced anything can be done in solidworks api.
solidworks 7.0 sp2.2
vb.net
thank you very much for the reply anthony.
i will give this a try and report back
here is the code to get part's origin coordinates in assembly
transform point from component space to assembly space example (vb)
this example shows how to transform a point from component space to assembly space.
'---------------
'
' preconditions:
' (1) assembly document is open.
' (2) component is selected.
'
' postconditions: component's origin is transformed to a point assembly space.
'
'----------------
sub main()
dim swapp as sldworks.sldworks
dim swmathutil as sldworks.mathutility
dim swmodel as sldworks.modeldoc2
dim swselmgr as sldworks.selectionmgr
dim swcomp as sldworks.component2
dim swxform as sldworks.mathtransform
dim npt(2) as double
dim nptinass(2) as double
dim vpt as variant
dim swpt as sldworks.mathpoint
dim i as long
dim bret as boolean
set swapp = application.sldworks
set swmathutil = swapp.getmathutility
set swmodel = swapp.activedoc
set swselmgr = swmodel.selectionmanager
set swcomp = swselmgr.getselectedobjectscomponent(1)
set swxform = swcomp.transform2
' point at component origin
npt(0) = 0#
npt(1) = 0#
npt(2) = 0#
vpt = npt
set swpt = swmathutil.createpoint(vpt)
set swpt = swpt.multiplytransform(swxform)
'koordinate to?k
nptinass(0) = swpt.arraydata(0) * 1000#
nptinass(1) = swpt.arraydata(1) * 1000#
nptinass(2) = swpt.arraydata(2) * 1000#
end sub
quick
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


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

高级搜索
显示模式

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

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



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


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