几何尺寸与公差论坛

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

【转帖】part coordinates

[复制链接]
发表于 2009-4-12 21:59:55 | 显示全部楼层 |阅读模式
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 14:59 , Processed in 0.194114 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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