Move groups with different measures?
-
it's like a snowball on the top of the mountain


-
groups = [] then nothing set !!!
You emptied the groups array...
You need to fill it from the selection...
groups=[];selection.each{|entity|groups.push(entity) if entity.kind_of?(Sketchup;;Group)} -
another try found: undefined method โ[]โ

model = Sketchup.active_model entities = model.entities selection = model.selection z=0 zeds=[] index=0 sorted_groups=[] groups=[];selection.each{|entity|groups.push(entity) if entity.kind_of?(Sketchup;;Group)} groups.each{|group|zeds.push(group.bounds.min.z, index) index+=1 } zeds.sort! zeds.each{|z|sorted_groups.push(groups[z[1]]) } ### sorted_groups is now groups sorted by sorted_groups.each do |e| # update! # Now we process the groups point = Geom;;Point3d.new 0,0,z t = Geom;;Transformation.new point # Apply the transformation e.transform!(t) z = z + 100.cm end -
Is that the only error message you get?
@unknownuser said:
it's like a snowball on the top of the mountain

You're hooked now! No way back!

-
Here's some tweaked code
def test() model = Sketchup.active_model model.start_operation("Move in Z") entities = model.entities selection = model.selection zeds=[] index=0 sorted_groups=[] groups=[];selection.each{|entity|groups.push(entity) if entity.kind_of?(Sketchup;;Group)} groups.each{|group|zeds.push([group.bounds.min.z, index]) index+=1 } zeds.sort! zeds.each{|z|sorted_groups.push(groups[z[1]]) } ### sorted_groups is now groups sorted by z = 0.0 sorted_groups.each do |e| # update! # Now we process the groups t = Geom;;Transformation.new(Geom;;Point3d.new(0,0,z)) # Apply the transformation e.transform!(t) z = z + 100.cm end model.commit_operation return nil end#defRuns as '
test'.
I made a typo - it needed an array[]of two items adding tozeds: zeds.push([group.bounds.min.z, index])not two 'loose' items as inzeds.push(group.bounds.min.z, index).
I made yourz = 0intoz = 0.0as it needs the number as a float, not an integer...
Removed 'point' variable and set the point definition directly inside the transformation - not necessary but fewer variables...
I added amodel.start_operation("")...model.commit_operationso it becomes a one step undo.
I addedreturn nilat end so the Ruby-Console doesn't get clogged with info...Tested it - it works...
-
Seems indeed that some corrections were necessary

This time works like a charm! Excellent! TIG + Thomthom! Bravo!
I will see all that more in detail for learn this little cryptic language !
Very funny plug!
For the next Pilou's foolish...
...I need to know the "centroรฏd" (xyz) of a "bounding box's group"
Here of course without different measure, just for little test!
(click image)

-
@unknownuser said:
...I need to know the "centroรฏd" (xyz) of a "bounding box's group"
centre_point=group.bounds.centerSee http://code.google.com/apis/sketchup/docs/ for all these details

-
Thx I had missed this one

-
It'd help if you posted the error messages.
However, I can still see the problem here.
Sketchup::Componentisn't an SU object. Check the manual, you haveSketchup::ComponentDefinitionandSketchup::ComponentInstance. In your case you're looking for aSketchup::ComponentInstance. -
I have replaced "Group" by "Component" but seems that is not so simple

groups=[];selection.each{|entity|groups.push(entity) if entity.kind_of?(Sketchup;;Component)} groups.each{|component|zeds.push([component.bounds.min.z, index])Else I can yet nest a component inside a group color transparent

That works fine (just disable Edges visible) but I suppose there is another thing

-
@ Tig Some cryptic but I will see that

Joint an image for no ambiguities
So here the increment is 300 cm
Edit sorry I have not seen all these speedy results!
@Thomthom! Yes that is that ! e.transform!(t)


-
Come back in these very dangerous territories

As I understand that retrieve the center XYZ of the bounding box group by
center = boundbox.centerbut how give these 3 values(?) to these 3 variables ?

xc= ?
yc= ?
zc= ?
must be trivial but yet some foggy for me
PS I read the API from the end to the start, and inverse but this stay mysterious found anything except that
-
boundbox.centerreturns an object of typePoint3d. You can check what an object is by checking the.classvalue of an object. That gives you an indication to where to look.xc= boundbox.center.x yc= boundbox.center.y zc= boundbox.center.z -
Many thx!

It's always the more easy ans usefull who is not written as example
-
??? = error : in โinitializeโ: undefined local variable or method โboundboxโ

model = Sketchup.active_model entities = model.entities selection = model.selection #groups = [] xp=100 # Pivot Point yp=100 zp=100 xc=0 #Center Point of the grouped object yc=0 zc=0 xe=0 #End Point of the grouped object ye=0 ye=0 selection.each do |e| # update! # Skip all entities that aren't groups next unless e.is_a? Sketchup;;Group # Now we process the groups center = boundbox.center xc= boundbox.center.x # ??? error yc= boundbox.center.y zc= boundbox.center.z xe=xc ye=yc ze=zc if xc<xp xe =xc - 100 end if xc>xp xe =xc +100 end if yc<yp ye =yc - 100 end if yc>yp ye =yc +100 end if zc<zp ze =zc - 100 end if zc>zp ze =zc +100 end point = Geom;;Point3d.new xe,ye,ze t = Geom;;Transformation.new point # Apply the transformation e.transform!(t) end -
That's because of
center = boundbox.center<- you haven't referencedboundboxyet.center = boundbox.center xc= boundbox.center.x # ??? error yc= boundbox.center.y zc= boundbox.center.zchange to
center = e.bounds.center xc= center.x yc= center.y zc= center.z -
Thx!

More easy with that
Works like a charm 
I can now test some natures of explodes

-
Funny thing


-
Looking good Pilou!
Instant assembly drawings!
This should come in handy. -
@unknownuser said:
Instant assembly
Alas for the inverse, that must be more tricky!

Better is use the Undo
Advertisement