Load & Put Components Together
-
Hey,
I want to put 2 - 4 componentes together, without hardcoding the
coordinates of the componentes.For example:
so i show you what i've programmed:driller= Sketchup.active_model.definitions.load("\\driller.skp") pos_driller =Geom::Point3d.new 47,32,25
<- that's the problem
` set_driller= Geom::Transformation.new pos_driller
instance1 = entities.add_instance driller, set_drillercuboid_wood = Sketchup.active_model.definitions.load("\Cuboid_wood.skp")
pos_cuboid = Geom::Point3d.new 0,0,0<- like here
set_cuboid = Geom::Transformation.new pos_cuboid
instance2 = entities.add_instance cuboid_wood, set_cuboid`but this is hardcoded
and i want that the computer places the objects correctly together automatically,by calculating the best position, but i can't calculate the size of these objects, because i don't know how. (i would have to measure the size with the measure-tool in SU with the mouse, but it should retrieve the values with a method)Or is there another possibility to avoid the harcoded way?
I have the task to do that with many components, that's why i wouldn't
say the detailed coordinates for every components, which i load.the programm should be able to load componentes, put it together correctly and dynamically, take some photos in different perspectives, save these pictures, clear it all and start at the beginning with other components ... everthing is quite clear to me, with the exception of the hardcoded coordinates of these objects
Thanks for your suggestions.
Greets
-
Chris88,
The simplest way to determine the size of a component is to use the bounding box of the component. For example, if you wanted to assemble the components in the X direction, calculate the distance between the center points, calculate the new center point for instance2, define the transformation to move it there, then do the transform.
bb1 = instance1.bounds ctr1 = bb1.center halfx1 = (bb1.max.x-bb1.min.x)/2.0 bb2 = instance2.bounds ctr2 = bb2.center halfx2 = (bb2.max.x-bb2.min.x)/2.0 ctr_to_ctr = halfx1 + halfx2 new_ctr2 = ctr1.offset(X_AXIS,ctr_to_ctr) mov_cuboid = Geom;;Transformation.new(new_ctr2-ctr2) instance2.transform! mov_cuboid
-
Thank you very much, sdmitch!
It sounds very good, i will test it at once.
Do you know another way to assemble components dynamically?
Because you said that this is the easiest way. -
It doesn't work correctly,
my tool (driller, saw,...) is set right beside the wooden cuboid, although i put the cuboid on 0,0,0.
Then i changed your code a little bit to:
mov_cuboid = Geom;;Transformation.new(ctr1)
so the tool is in the middle of cuboid, but i can't change the height of the tool or just x,y-coordinate
-
Chris, The code works perfectly as far as it was designed to do and that was to place instance1 beside instance2. Only you know how you want and need the components to be related to each other and only you have the components to work with.
Advertisement