[help]Group component instances
-
Hi,
I'm beginner in SketchUp Ruby coding and in fact I've never code into Ruby... (only C++ PHP JavaScript skills)
Well I load and place some components using a "for" loop
for i in 1..numberP point = Geom;;Point3d.new x0,y0,z0 transform = Geom;;Transformation.new point model = Sketchup.active_model entities = model.active_entities path = Sketchup.find_support_file "mymodel.skp" ,"Components/" definitions = model.definitions componentdefinition = definitions.load path instance = entities.add_instance componentdefinition, transform # Calculate next panel corner for next loop. numinraw = num % numbyraw if (numinraw==0) x0 = abscisseRaw * rawNum y0 = ordonneeRaw * rawNum rawNum += 1 else x0 = x0 + abscisse y0 = y0 + ordonnee end num += 1 endAnd after that I want to group theses componentdefinition in order to apply them some other transformation...
I imagine placing a line like "group = model.active_entities.add_group" just after the instance declaration or selecting all instances after the loop...
But it does not work certainly due to the group declaration and the way I want to add components inside after
-
Before the loop set up an empty array
instances=[]Within the loop after you've set
instancepush it intoinstancesinstances << instanceAfter the loop
group=model.active_entities.add_group(instances)Note: you could define
entitiesoutside of the loop and then reuse it - stuff you define in a loop is not accessible outside of it...

-
oh nice! thank you for it and for your note... (really need to study ruby first I think)
I've just to transform it now with two rotations but only the last one work in fact. if you got a lil tip for it... I'll calculate the resulting vector and angle of the two transform I need that's pretty strange...
-
In addition to TIG's info, you should move all the one-time code outside the loop.
model = Sketchup.active_model entities = model.active_entities path = Sketchup.find_support_file "mymodel.skp" ,"Components/" . . .I also heartily recommend that you use four-space indentation in spite of the fact that two spaces is a Ruby convention. Four is much more readable which is why it is mandatory in Python, convention in C++, Java, JavaScript, ... (every language I know, except Ruby).
New languages are always a PITA. Fortunately, quite a small subset of Ruby is all you really need to create SketchUp plugins.
Advertisement