几何尺寸与公差论坛

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

【转帖】solidworks macros capabilities

[复制链接]
发表于 2009-4-12 19:40:28 | 显示全部楼层 |阅读模式
solidworks macros capabilities
hi there,
introduction
- first of all, i would like to say that is the 1st time i post in a forum and that i'm a newbie in solidworks! (what a combination to start...). but i think i'm a medium programer in vb (vb6 and a little of vb2005).
- second, i never felt the need to post questions because the answers are always on internet (read foruns, execute little examples...) or in the help files and its just a question of time and patient till finding the answer. well i'm working in this project almost for a month (10 hours/day sometimes) and i'm starting to feel that solidworks is to especific for a type of aplication and it doesn't make what i want.
- third, i need in this forum to understand if it is possible to execute some actions so i can boost my confidence and finish my program... or quit and move to another to cad tool.
- fourth, i will explain things as a 4 year old because that was the way i tried to aproach the solution and probably there is a easier way.
well lets cut to the chase:
-» i have to develop a program (a macro !!!) that permits marking the "point" of intersection between 2 solids.
for example i have a cube and a sphere 5 units apart of each other. starting to getting them closer i want to identify the first point of intersection.
yes i want a point... not a volume (ei... to me, a volume of 0,0001m^3 could be considered a point!).
the complexity of the program rises because the sphere should continue to move around the cube so i can get other points that permits drawing a line, that represents every possibilities of intersection. over that line the face of the cube, should be painted with another colour.
let me now translate in solidworks language:
as far as i know and could perform "hand" made... (without macros) with a cube and a sphere (two diferents parts assembled in a assembly type of project), i started moving the sphere towards the cube using the move comand (inserting the delta x displacement), and started to aplly the "find interference" comand. when i got a low volume of interference (3m^3), i used the
tools-> sketch tools-> interference curve. that intersection curve between the two solids, is a circle... and the center is the point i wanted to know. next i found in the same way another point of intersection and finaly draw the line.
when i finished this by hand, i thought it would be "easy game" to start building a macro using the record method (that everyone uses to startup the constrution of program), right??? wrong... first of all calling object in solidworks to me is everything but a simple process. but worse of all is when i recorded the move actions and all i got was nothing but simple:
boolstatus = part.extension.selectbyid2(" (...) ") (only the selection of a sphere procedure right ???)
but of course... examples in "help api of solidworks". i understood that i had to use the comands, like "movecopybodyfeaturedata" and "transformx"... but it still doesn't work (not 100% sure of the code).
finaly, after i've show you what troubles me, what i want to know is:
is it possible with a macro make the "sphere" move?
is it possible to test the interference until a maximum volume?
is it possible to paint, directly in the assembly, the interference between the 2 pieces and making it a part of the assembly? (it would spare the work of making lines)
is this the right path to the solution ?
aproching the problem from solidworks cosmos could it become easier???
or in another words...
can solidworks make my project ???
to anyone that can enlighten me, freeing me from the darkness of ignorance... thanks
filipe pinto, woking in
solidworks ver. education edition 2007 sp3.1
ps: please help!!! and sorry if along the post ive broken any rule
solidworks
ver. education edition 2007 sp3.1
amd64 3.0 ghz
512mb ddr 400mhz
ati 9550
winxp pro 32bit
portuguese do it better - i do... with this workstation :d
edited: 03/26/2009 at 01:30 pm by filipe pinto
well my answer will be two parts and also short because i have to leave for the day! i will look into this further though!
1. recording macros can show you "some" stuff but overall i have found recording macros almost never gives me anything useful. the code it generates is pretty useless for most projects i try to create.
2. yes everything you are talking about can be done using a macro in my opinion.
i know this wasn't extremely helpful but... more later!
solidworks professional 2009 sp0
dual core amd opteron 2.21ghz cpu
4 gb ram
nvidia quadrofx 4500 w/ 512mb ram
hum...
i'm looking forward for your next post, because "there's hope for this case" right ? but can you tell me in a scale 0-10 the dificulty work i'm facing? (if its a 10 please lie  )
thanks !!!
solidworks
ver. education edition 2007 sp3.1
amd64 3.0 ghz
512mb ddr 400mhz
ati 9550
winxp pro 32bit
portuguese do it better - i do... with this workstation :d
when you say you have a cube and a sphere 5 units apart and move them together until they intersect - i understand that much, although when you says the sphere also needs to move "around" the cube and give additional intersect points i get lost.
at first it seems as if your are moving in the y direction for example until it hits the cube.
when you say later that it needs to move around the cube, does that mean in any direction along multiple axis?
i am thinking about something like the sphere orbiting the cube around and axis 360 degrees and then tilting the axis by a set factor of say 1 degree and orbit agian. then repeating that 259 more times so that you cover the cube totally.
if that is what you are talking about then my question would be: do you start at a distance and move in until it touches, then store that distance and orbit all around the cube using that distance?
once i am clear on what you are trying to accomplish i will understand more of the complexity of the code.
i would say right now its around 8 on a scale of 1-10 for me
solidworks professional 2009 sp0
dual core amd opteron 2.21ghz cpu
4 gb ram
nvidia quadrofx 4500 w/ 512mb ram
edited: 11/05/2008 at 12:26 pm by jake johnson
hello again...
ok... at the first post i was only trying to give a big picture and understanding if some actions where possible... now i'will try to be more especific about the program i want to achieve...
the starting point of the program should consider 2 things:
a sphere (with a specific radius) in a "part" type drawing;
a structure in another "part" type drawing (i started with a cube... but the real case is a small/complex composition of solids). this struture is built in a "floor" or "ground" that will serve as a reference to the movement of the sphere and should be painted to (i think its easier than painting the structure).
having this two "parts" i would migrate them to a "assembly" type of drawing manually (to keep things simple). here is where i feel that the macro should work. the sphere should be placed in one corner "steeped" or into the "floor" manually (simplicity), and then (after pressing ok ) it should start to sweep the structure.
ok... now the "sweep thing".
i haven't figure it out how to move the sphere... but i know what i want to do with it!
notice that i have the sketch of the program im my head... but some code i've built just can't put simple actions in to play like moving the sphere.
1)the desired action...
the sphere starts it's movement by little increments in x, painting the floor along the way (if its possible to paint the result of the interference its just what i want).
when the sphere finds the interference with the struture it paints its face and then increments y paints another"interference". when everything is painted (level floor) its time to increment z and start to do the same operation... this would paint automatically the structure. but this solution but this i have no idea how to code ... but in solidworks look easier hand made...
2)the way i'm trying to implement.
this is what i' trying to implement because its more... "computable".
again the sphere starts it's movement by little increments in x. every increment detects interference between with the structure. if there is a point of intersection (or a small volume <0,01m^3) it draw the the intersection curve between floor/sphere, an struture/sphere. after that increment y to find new points. when interference=0 between struture/sphere its finalized, the center points of the intersection curve sould be connected, building a line/frontier of intersection and above it i was aiming to color it (don't know the complexity of it, yet!).
but eih... wise man said "a picture is worth a thousand words" . i wil try to upload a picture in this post.
so... is this still "makeable" in macros for solid works ?
thanks for the helping me and the community,
filipe
p.s. - sorry for delay in the responses... but its a bit dificult to think and write english at same time.
solidworks
ver. education edition 2007 sp3.1
amd64 3.0 ghz
512mb ddr 400mhz
ati 9550
winxp pro 32bit
portuguese do it better - i do... with this workstation :d
edited: 11/18/2008 at 04:58 am by filipe pinto
click for full image
create a part file of whatever shape you want ( i used a cube)
put it into an assembly (make sure it is not fixed) then select the component and run this code.
it will move the component (right now this is just rotating it 90 degrees) although this is an example of what you will want to start looking at to move your sphere.
i will look more into this as i find time
solidworks professional 2009 sp0
dual core amd opteron 2.21ghz cpu
4 gb ram
nvidia quadrofx 4500 w/ 512mb ram
edited: 11/06/2008 at 02:17 pm by jake johnson
ok thanks...
putting the sphere moving will be a great (huge) help...
i think if you can show me with just a little code how to do that and drawing the line i think i can pick it up from there. because if you give 10% of inspiration the other part is sweating... and thats my part !
then i can say later:"solidworks macros were capable of building this project", "...of course with guidance of the forum people (jake johnson)"
i'm looking forward for next post, thanks again,
filipe
solidworks
ver. education edition 2007 sp3.1
amd64 3.0 ghz
512mb ddr 400mhz
ati 9550
winxp pro 32bit
portuguese do it better - i do... with this workstation :d
lol woops! i suppose it would have been a bigger help if i actually posted the code!!! sorry about that!
here you go.
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.print bret
swdragop.collisiondetectionenabled = false
swdragop.dynamicclearanceenabled = false
' axial rotation
swdragop.transformtype = 0
' solve by relaxation
swdragop.dragmode = 2
bret = swdragop.begindrag
debug.print bret
for i = 0 to 89
' 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.print bret
end sub
solidworks professional 2009 sp0
dual core amd opteron 2.21ghz cpu
4 gb ram
nvidia quadrofx 4500 w/ 512mb ram
ok...
i'm going to work on this tomorow. its going to be a nice weekend... eheheh
thanks a again,
filipe
solidworks
ver. education edition 2007 sp3.1
amd64 3.0 ghz
512mb ddr 400mhz
ati 9550
winxp pro 32bit
portuguese do it better - i do... with this workstation :d
hi there again,
i'm not on a "lucky strike" with solidworks...
not much results...
i'm starting to doubt about this "educational version" of solidworks of mine.
so... i did as you told me:
0 - start from scrath !
1 - build a cube (in a part file);
2 - put the cube on a assembly file;
3 - select a component (the cube right???);
4 - execute the macro;
doesn't work... and i'm not doubting about your code (vb didn't complain... it runs the code no problem). i tried different order of the process but didn't work... conclusion i must be doing something wrong!
i tried to "step" the program, but the part of the program were you "set" various variables (swapp, swmodel, swassy...) didn't assume anything (it returned "nothing" after i "watched" them).
about the "make sure it is not fixed" that you advised, i put the cube in "float mode", as the picture i send shows.
i read the code and i think (with the help of the help files) i got the general ideia (and i'm starting, bit by bit, to understand how the solidworks codes works):
- create a point... call it origin;
- create another point that is going to be rotate;
- swdrag operations 70% understood;
- didn't understood why the debug command;
can you sense what am i doing wrong..?
thanks for the patience spend...
solidworks
ver. education edition 2007 sp3.1
amd64 3.0 ghz
512mb ddr 400mhz
ati 9550
winxp pro 32bit
portuguese do it better - i do... with this workstation :d
click for full image
you are missing this in your code:
const radperdeg as double = 3.14159 / 180#
add that line just under "sub main" and you should get a rotating part (or refer to "rotate assembly component on axis example " in the api help.
-mb
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-12-23 01:24 , Processed in 0.039249 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

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