SketchUcation Premium Membership

 

 

Move groups with different measures?

Re: Move groups with different measures?

Postby Pilou » Fri Jul 03, 2009 1:31 am

another try found: undefined method ‘[]’ :?

Code: Select all
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
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby thomthom » Fri Jul 03, 2009 9:49 am

Is that the only error message you get?

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

You're hooked now! No way back! ;) :)
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17545
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby TIG » Fri Jul 03, 2009 9:51 am

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
User avatar
TIG
Global Moderator
 
Posts: 13901
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Pilou » Fri Jul 03, 2009 3:41 pm

Seems indeed that some corrections were necessary :D
This time works like a charm! Excellent! TIG + Thomthom! Bravo! :fro:
I will see all that more in detail for learn this little cryptic language ! :enlight:
Very funny plug! ;)
For the next Pilou's foolish... :mrgreen:
...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
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby TIG » Fri Jul 03, 2009 5:03 pm

...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
User avatar
TIG
Global Moderator
 
Posts: 13901
Joined: Mon Nov 12, 2007 7:24 pm
Location: Northumbria UK
Name: TIG
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Pilou » Sat Jul 04, 2009 1:15 pm

Thx I had missed this one ;)
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Pilou » Tue Jul 07, 2009 11:52 am

I have replaced "Group" by "Component" but seems that is not so simple :mrgreen:
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 :mrgreen:
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
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby thomthom » Tue Jul 07, 2009 11:58 am

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
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17545
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Pilou » Tue Jul 07, 2009 12:07 pm

Yep!!! THX! Miracle that is working! :ecstatic:
Sure I should read the Api document before :oops: :oops: :oops: But I had risked the trick :mrgreen:
So my second script was a new speedy success and a big lesson :D
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
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Pilou » Wed Jul 15, 2009 2:55 pm

Come back in these very dangerous territories :mrgreen:

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 ? :roll:
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 :mrgreen:
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby thomthom » Wed Jul 15, 2009 3:20 pm

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.x
yc= boundbox.center.y
zc= boundbox.center.z
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17545
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Pilou » Wed Jul 15, 2009 4:02 pm

Many thx! :enlight:
It's always the more easy ans usefull who is not written as example :roll:
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Pilou » Wed Jul 15, 2009 5:05 pm

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

Code: Select all
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
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby thomthom » Wed Jul 15, 2009 5:30 pm

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
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17545
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Pilou » Wed Jul 15, 2009 6:29 pm

Thx! :enlight:
More easy with that :) Works like a charm :fro:
I can now test some natures of explodes :mrgreen:
Please, register (free) to access all the attachments on the forums.
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Pilou » Wed Jul 15, 2009 7:06 pm

Funny thing :D
Please, register (free) to access all the attachments on the forums.
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Pilou » Thu Jul 16, 2009 10:15 am

Some tests :mrgreen: Put the code inside the WebConsole by Jim Foltz
Press "Eval" button and have fun :D
Veyron model is from 3Dwarehouse!
Code: Select all
model = Sketchup.active_model
entities = model.entities
selection = model.selection

xp=100  # Pivot Point (as you want)
yp=100
zp=100

q=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 object
ye=yc
ze=zc

if xc<xp
 xe =xc - q
end

if xc>xp
 xe =xc + q
end

if yc<yp
 ye =yc - q
end

if yc>yp
 ye =yc + q
end

if zc<zp
 ze =zc - q
end

if zc>zp
 ze =zc + q
end

  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
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby thomthom » Thu Jul 16, 2009 10:22 am

Looking good Pilou!
Instant assembly drawings! :D This should come in handy.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17545
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Pilou » Thu Jul 16, 2009 10:27 am

Instant assembly

Alas for the inverse, that must be more tricky! :?
Better is use the Undo :mrgreen:
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby thomthom » Thu Jul 16, 2009 10:43 am

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
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17545
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Pilou » Thu Jul 16, 2009 10:52 am

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 :roll:
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
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Chris Fullmer » Thu Jul 16, 2009 10:14 pm

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
User avatar
Chris Fullmer
SketchUp Team
 
Posts: 6680
Joined: Wed Nov 21, 2007 3:21 am
Location: Davis, CA
Name: Chris Fullmer
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: landscape architecture
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Pilou » Thu Jul 16, 2009 10:25 pm

@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
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Chris Fullmer » Thu Jul 16, 2009 10:38 pm

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
User avatar
Chris Fullmer
SketchUp Team
 
Posts: 6680
Joined: Wed Nov 21, 2007 3:21 am
Location: Davis, CA
Name: Chris Fullmer
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: landscape architecture
Level of SketchUp: Advanced

Re: Move groups with different measures?

Postby Pilou » Fri Jul 17, 2009 8:59 am

@Chris thx for the Info :enlight:
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
User avatar
Pilou
Top SketchUcator
 
Posts: 10027
Joined: Wed Jan 23, 2008 10:33 pm
Operating system: Windows
SketchUp version: 6
License type: Free
SketchUp use: hobby
Level of SketchUp: Advanced

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Not a Premium Member yet? Check out the great time-limited deal we are offering.

Ad Machine
Robot
 
Posts: 2012

Previous


 

Return to Developers' Forum

Who is online

Users browsing this forum: gerami and 1 guest