## Move groups with different measures?

### Re: Move groups with different measures?

another try found: undefined method ‘[]’

Code: Select all
`model = Sketchup.active_modelentities = model.entitiesselection = model.selectionz=0zeds=[]index=0sorted_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.cmend`
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

### Re: Move groups with different measures?

Is that the only error message you get?

Pilou wrote:it's like a snowball on the top of the mountain

You're hooked now! No way back!
Thomas Thomassen — SketchUp Monkey & Coding addict

thomthom
Global Moderator

Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
SketchUp use: architecture

### Re: Move groups with different measures?

Here's some tweaked code
Code: Select all
`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#def`
Runs as 'test'.
I made a typo - it needed an array [] of two items adding to zeds: zeds.push([group.bounds.min.z, index]) not two 'loose' items as in zeds.push(group.bounds.min.z, index).
I made your z = 0 into z = 0.0 as 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 a model.start_operation("")...model.commit_operation so it becomes a one step undo.
I added return nil at end so the Ruby-Console doesn't get clogged with info...

Tested it - it works...
TIG

TIG
Global Moderator

Posts: 14311
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 2013
SketchUp use: architecture

### Re: Move groups with different measures?

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)
Please, register (free) to access all the attachments on the forums.
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

### Re: Move groups with different measures?

...I need to know the "centroïd" (xyz) of a "bounding box's group"

Code: Select all
`centre_point=group.bounds.center`

See http://code.google.com/apis/sketchup/docs/ for all these details
TIG

TIG
Global Moderator

Posts: 14311
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 2013
SketchUp use: architecture

### Re: Move groups with different measures?

Thx I had missed this one
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

### Re: Move groups with different measures?

I have replaced "Group" by "Component" but seems that is not so simple
Code: Select all
`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
Please, register (free) to access all the attachments on the forums.
Last edited by Pilou on Tue Jul 07, 2009 11:59 am, edited 1 time in total.
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

### Re: Move groups with different measures?

It'd help if you posted the error messages.

However, I can still see the problem here. Sketchup::Component isn't an SU object. Check the manual, you have Sketchup::ComponentDefinition and Sketchup::ComponentInstance. In your case you're looking for a Sketchup::ComponentInstance.
Thomas Thomassen — SketchUp Monkey & Coding addict

thomthom
Global Moderator

Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
SketchUp use: architecture

### Re: Move groups with different measures?

Yep!!! THX! Miracle that is working!
Sure I should read the Api document before But I had risked the trick
So my second script was a new speedy success and a big lesson
groups=[];selection.each{|entity|groups.push(entity) if entity.kind_of?(Sketchup::ComponentInstance)}

groups.each{|ComponentInstance|zeds.push([ComponentInstance.bounds.min.z, index])

Copy my code follow in the Web console from Jim Foltz
(if you have components use the file linked )
Code: Select all
`    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    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`

Some help for fun variations
Please, register (free) to access all the attachments on the forums.
Last edited by Pilou on Tue Jul 17, 2012 10:20 am, edited 14 times in total.
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

### Re: Move groups with different measures?

Come back in these very dangerous territories

As I understand that retrieve the center XYZ of the bounding box group by
Code: Select all
` center = boundbox.center `

but 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
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

### Re: Move groups with different measures?

boundbox.center returns an object of type Point3d. You can check what an object is by checking the .class value of an object. That gives you an indication to where to look.

Code: Select all
`xc= boundbox.center.xyc= boundbox.center.yzc= boundbox.center.z`
Thomas Thomassen — SketchUp Monkey & Coding addict

thomthom
Global Moderator

Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
SketchUp use: architecture

### Re: Move groups with different measures?

Many thx!
It's always the more easy ans usefull who is not written as example
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

### Re: Move groups with different measures?

??? = error : in ‘initialize’: undefined local variable or method ‘boundbox’

Code: Select all
`model = Sketchup.active_modelentities = model.entitiesselection = model.selection#groups = []xp=100  # Pivot Point yp=100zp=100xc=0  #Center Point of the grouped objectyc=0zc=0xe=0  #End Point of the grouped objectye=0ye=0selection.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=xcye=ycze=zcif xc<xp xe =xc - 100end  if xc>xp xe =xc +100endif yc<yp ye =yc - 100end  if yc>yp ye =yc +100endif zc<zpze =zc - 100end  if zc>zpze =zc +100end  point = Geom::Point3d.new xe,ye,ze  t = Geom::Transformation.new point  # Apply the transformation  e.transform!(t)end`
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

### Re: Move groups with different measures?

That's because of center = boundbox.center <- you haven't referenced boundbox yet.

Code: Select all
`center = boundbox.center        xc= boundbox.center.x # ??? error   yc= boundbox.center.y   zc= boundbox.center.z`

change to

Code: Select all
`center = e.bounds.center   xc= center.x   yc= center.y   zc= center.z`
Thomas Thomassen — SketchUp Monkey & Coding addict

thomthom
Global Moderator

Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
SketchUp use: architecture

### Re: Move groups with different measures?

Thx!
More easy with that Works like a charm
I can now test some natures of explodes
Please, register (free) to access all the attachments on the forums.
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

### Re: Move groups with different measures?

Funny thing
Please, register (free) to access all the attachments on the forums.
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

### Re: Move groups with different measures?

Some tests Put the code inside the WebConsole by Jim Foltz
Press "Eval" button and have fun
Veyron model is from 3Dwarehouse!
Code: Select all
`model = Sketchup.active_modelentities = model.entitiesselection = model.selectionxp=100  # Pivot Point (as you want)yp=100zp=100q=50 # Measure of translation (as you want) selection.each do |e| # update!  # Skip all entities that aren't groups or components (replace follow "ComponentInstance" by "Group" if you have groups  next unless e.is_a? Sketchup::ComponentInstance  # Now we process the component or group center = e.bounds.center #Center Point of the grouped object   xc= center.x   yc= center.y   zc= center.z   xe=xc #End Point of the grouped objectye=ycze=zcif xc<xp xe =xc - qendif xc>xp xe =xc + qendif yc<yp ye =yc - qendif yc>yp ye =yc + qendif zc<zp ze =zc - qendif zc>zp ze =zc + qend  point = Geom::Point3d.new xe,ye,ze  t = Geom::Transformation.new point  # Apply the transformation  e.transform!(t)end`
Please, register (free) to access all the attachments on the forums.
Last edited by Pilou on Fri Jul 17, 2009 9:08 am, edited 5 times in total.
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

### Re: Move groups with different measures?

Looking good Pilou!
Instant assembly drawings! This should come in handy.
Thomas Thomassen — SketchUp Monkey & Coding addict

thomthom
Global Moderator

Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
SketchUp use: architecture

### Re: Move groups with different measures?

Instant assembly

Alas for the inverse, that must be more tricky!
Better is use the Undo
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

### Re: Move groups with different measures?

hm... You could store the relative position you move the entities by in and attribute dictionary. Then perform the opposite when you want to reassemble.

though, that will fail if the user moves anything...
Maybe, you could store the original absolute position before you move stuff. Then you can reassemble back to that original position. That would allow the user to move things around as they please.
Thomas Thomassen — SketchUp Monkey & Coding addict

thomthom
Global Moderator

Posts: 17923
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: Thomas Thomassen
Operating system: Windows
SketchUp version: 2013
SketchUp use: architecture

### Re: Move groups with different measures?

In theory that must be more easy
Just select that you want and apply a "negative" translation : a deflation
Maybe my next
And the above is not yet perfect! The Pivot Point seems not have the wished result wanted
be continued...

Ps When Groups or Components are nested how to process automatically?
A plug for make each components individual is maybe existing?
Edit
one exist for group by TIG Explode2groups

miss now somethings transform Transform2goups or Explode2Components
Last edited by Pilou on Thu Jul 16, 2009 10:24 pm, edited 1 time in total.
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

### Re: Move groups with different measures?

Store the original transformation in a dictionary attached to the group/component. Then to unexplode, just re-apply that transformation onto the group. It will go right back where it belongs.

I wrote that crazy scrambler script a while ago that does this and it worked very well.

Chris
Lately you've been tan, suspicious for the winter.
All my Plugins I've written

Chris Fullmer
SketchUp Team

Posts: 6762
Joined: Wed Nov 21, 2007 3:21 am
Location: Davis, CA
Name: Chris Fullmer
Operating system: Windows
SketchUp version: 8
SketchUp use: landscape architecture

### Re: Move groups with different measures?

@Chris Any chance to see it somewhere?

PS
A plug for make each components individual is maybe existing?
Edit
one exist for group by TIG Explode2groups

miss now somethings for components Transform2goups or Explode2Components
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

### Re: Move groups with different measures?

take the componentInstance, add it to a group, then explode the component instance.

And I posted my scrambler script here. I'll see if I can find the thread.

Chris
Lately you've been tan, suspicious for the winter.
All my Plugins I've written

Chris Fullmer
SketchUp Team

Posts: 6762
Joined: Wed Nov 21, 2007 3:21 am
Location: Davis, CA
Name: Chris Fullmer
Operating system: Windows
SketchUp version: 8
SketchUp use: landscape architecture

### Re: Move groups with different measures?

@Chris thx for the Info
Fredo6 has inside the FredoScale something who transform any selection of groups or Components in "Unique" groups or componants! (each become individual)
(last icon)
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie

Pilou
Top SketchUcator

Posts: 10220
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
SketchUp use: hobby

Need SketchUp Books, Models, Styles or Textures? Check out our One Stop Shop for SketchUp.