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

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


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

高级搜索
显示模式

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

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

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】inserting and mating parts in an assembly yang686526 SolidWorks二次开发 0 2009-04-12 09:28 PM
【转帖】how can i do to select a componen yang686526 SolidWorks二次开发 0 2009-04-12 09:07 PM
【转帖】inserting and mating parts in an assembly yang686526 SolidWorks二次开发 0 2009-04-12 06:43 PM


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


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