几何尺寸与公差论坛

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

【转帖】move assembly componen

[复制链接]
发表于 2009-4-12 21:50:11 | 显示全部楼层 |阅读模式
move assembly component
hi,
i am trying to move component along x axis with macro. i've found this sample in api tutorial, but i cant manage to transform it to make a translation from one point to another. can someone please help me. ohh and i need to keep all mates active.
' problem:
' this code shows how to use the mathutility object
' to directly create a transformation matrix (object)
' that represents rotation about a point and an axis,
' without having to know details of the opengl transformations.
'
' preconditions:
' (1) assembly is open and fully resolved.
' (2) assembly component is selected.
'
' postconditions: selected component is rotated 90° about assembly x axis.
'
'----------------
option explicit
const pi as double = 3.14159
const radperdeg as double = pi / 180#
' dragoperator::transformtype
' translation 0
' transform is translation only
'
' axial rotation 1
' transform is rotation only
'
' general 2
' transform can be translation or rotation or both
' dragoperator:ragmode
' minimum move 0
' move smallest number of geometries
'
' maximum move 1
' move geometries rigidly if possible
'
' relaxation 2
' solve geometries using relaxation
sub main()
dim swapp as sldworks.sldworks
dim swmodel as sldworks.modeldoc2
dim swassy as sldworks.assemblydoc
dim swdragop as sldworks.dragoperator
dim swselmgr as sldworks.selectionmgr
dim swcomp as sldworks.component2
dim swxform as sldworks.mathtransform
dim swmathutil as sldworks.mathutility
dim sworiginpt as sldworks.mathpoint
dim swx_axis as sldworks.mathvector
dim npts(2) as double
dim vdata as variant
dim nnow as single
dim i as long
dim bret as boolean
set swapp = createobject("sldworks.application")
set swmodel = swapp.activedoc
set swassy = swmodel
set swdragop = swassy.getdragoperator
set swselmgr = swmodel.selectionmanager
set swcomp = swselmgr.getselectedobjectscomponent2(1)
set swmathutil = swapp.getmathutility
npts(0) = 0#
npts(1) = 0#
npts(2) = 0#
vdata = npts
set sworiginpt = swmathutil.createpoint(vdata)
npts(0) = 1#
npts(1) = 0#
npts(2) = 0#
vdata = npts
set swx_axis = swmathutil.createvector(vdata)
' this is an incremental rotation,
' so angle is always the same
set swxform = swmathutil.createtransformrotateaxis( _
sworiginpt, swx_axis, 1# * radperdeg)
bret = swdragop.addcomponent(swcomp, false)
debug.assert bret
swdragop.collisiondetectionenabled = false
swdragop.dynamicclearanceenabled = false
' axial rotation
swdragop.transformtype = 1
' solve by relaxation
swdragop.dragmode = 2
bret = swdragop.begindrag
debug.assert bret
for i = 0 to 90
' returns false if drag fails, for example, because of a collision
bret = swdragop.drag(swxform)
' wait for 0.1 secs
nnow = timer
while timer < nnow + 0.1
' process event loop
doevents
wend
next i
bret = swdragop.enddrag
debug.assert bret
end sub
no one is using this command?
there is a lot of code here. perhaps you could let us know which portion you don't understand? the user interface makes this kind of operation look very easy, but it's actually pretty complex. what is your level of familiarity with vba and the solidworks api? matrix algebra and vectors?
i'll get you eh steve, if it's the last thing i dooooo!
i do not know anything about this code but i am wondering if this is like the move command that you get when you right click a part in the browser window. if the part is held in place with mates you can not move the part, so in order to move the part you must suppress at least one mate.
dan miel
hi
if you need the mates to stay active, use a distance mate along the x axis.
use your macro to update the value. no transforms needed.
scott
hi tnx all for replying
i realized that this isnt a good way to do it, i dont even know if i could do this with this code.
becouse in this code i'm rotating axis, but i would like to do translation on axis. i couldnt understand whats the diffrence in this code right here:
' dragoperator::transformtype
' translation 0
' transform is translation only
' axial rotation 1
' transform is rotation only
' general 2
' transform can be translation or rotation or both
swdragop.transformtype = 1 ' 1 is for rotation 0 is for translation
but i dont see any diffrance between rotation and translation...
after that unsuccessfull try i used this code
'rotation
aux_a(0) = 1#: aux_a(1) = 0#: aux_a(2) = 0#
aux_a(3) = 0#: aux_a(4) = 1#: aux_a(5) = 0#
aux_a(6) = 0#: aux_a(7) = 0#: aux_a(8) = 1#
' translation atention: a(9)=x axis a(10)=z axis a(11)=y axis !!!
aux_a(9) = x(i): 'x os
aux_a(10) = y(i): 'y os
aux_a(11) = z(i): 'z os
' scale
aux_a(12) = 1#
' perspectiv
aux_a(13) = 0#: aux_a(14) = 0#: aux_a(15) = 0#
'-------------
vxform = aux_a
insted of this:
npts(0) = 0#
npts(1) = 0#
npts(2) = 0#
vdata = npts
set sworiginpt = swmathutil.createpoint(vdata)
npts(0) = 1#
npts(1) = 0#
npts(2) = 0#
vdata = npts
set swx_axis = swmathutil.createvector(vdata)
' this is an incremental rotation,
' so angle is always the same
set swxform = swmathutil.createtransformrotateaxis(sworiginpt, swx_axis, 1# * radperdeg)
ohh and assembly can move... it haves like 10 mates that needs to be active. im using this to control a robot with g-code.
swdragop.collisiondetectionenabled = true
can i ask if this line works like interfence detection? if i use it it doesnt stop my moving (bret is always true), even though it is a collision(interference) between two parts.
swdragop.collisiondetectionenabled = true
bret = swdragop.begindrag
debug.assert bret
for i = 0 to 90
' returns false if drag fails, for example, because of a collision
bret = swdragop.drag(swxform)
that is why i used interference detection, but i have like 3000 points so this is a very slow method.
hope you get an idea what i am trying to do and someone can help.
thanks
i'm curious. how did you ever get your assembly to move? i'm doing something similar. i am sick of dragging the end of the robot around. i'd like to control it with some sliders or something.
quick
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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