by thomthom » Thu Jul 02, 2009 1:33 pm
SU always uses inches internally. If you want 100mm type 100.mm . See http://code.google.com/intl/nb/apis/ske ... meric.html for more units.
-

thomthom
- Global Moderator
-
- Posts: 17556
- 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
-
by TIG » Thu Jul 02, 2009 1:55 pm
Pilou
Do you want to move each of the selected groups by the same amount (my code - e.g. 100.mm) or by an ever changing amount ?
If you want it to change then you need to define how, and add this into the loop - e.g. z=1..... then loop... z += 2*z exponential type increase !
If you are applying different offsets, and you have made the groups in order, then the increments will apply in that way; but it would be possible to 'stack' groups made at different times and the loop would process then in their made order, but not the 'stacked' order you want ! Perhaps you need to add in another test... for each of the group.bounds.min.z. which sorts them by their relative heights, so at least the groups array would be in the height order you expect...
TIG
-

TIG
- Global Moderator
-
- Posts: 13929
- 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
by Pilou » Thu Jul 02, 2009 2:04 pm
If you want 100mm type 100.mm
Yes! Works like a charm! For my first one that was not like a true romance but with your help, ThomThom, Tig (yet a lot of cryptic for me  , and the Chris tutorial and a dash of milk of Tod Burch Many thx for the helps Next will maybe an "explode view" of several groups Just need to know position of a group  PS @ Tig Sorry but I had no chance with yours! (see previous page)  And yes I want any sort of increments so now I can have any sort of it! Thx!  Just play with parameters  I keep your group.bounds.min.z. trick in my mind!
Please, register (free) to access all the attachments on the forums.
-

Pilou
- Top SketchUcator
-
- Posts: 10032
- Joined: Wed Jan 23, 2008 10:33 pm
- Operating system: Windows
- SketchUp version: 6
- License type: Free
- SketchUp use: hobby
- Level of SketchUp: Advanced
-
by TIG » Thu Jul 02, 2009 2:51 pm
for a completely random offset try - Code: Select all
selection.each do |e| next unless e.is_a? Sketchup::Group ###point = Geom::Point3d.new 0,0,(1000.mm * rand) ### offset in Z somewhere between 0m and 1m - 'rand' makes a random number 0><1 point = Geom::Point3d.new (1000.mm * rand),(1000.mm * rand),(1000.mm * rand) ### offset in all XYZ axes by 0 to 1m t = Geom::Transformation.new point e.transform!(t) end
Swap the ### between the different points = to see the effect
TIG
-

TIG
- Global Moderator
-
- Posts: 13929
- 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
by Pilou » Thu Jul 02, 2009 2:58 pm
Before testing your new randomizer plug  I have a little problem  I have used "Grow" by Tig for make the "volume" on the left (50 groups), then my "Plug" Thomthomised with a normal interval of course! Seems there is something wrong somewhere Groups are not recorded following the "grow" generation?
Please, register (free) to access all the attachments on the forums.
Last edited by Pilou on Thu Jul 02, 2009 3:02 pm, edited 1 time in total.
-

Pilou
- Top SketchUcator
-
- Posts: 10032
- Joined: Wed Jan 23, 2008 10:33 pm
- Operating system: Windows
- SketchUp version: 6
- License type: Free
- SketchUp use: hobby
- Level of SketchUp: Advanced
-
by thomthom » Thu Jul 02, 2009 3:01 pm
The entities are not returned in their order in z height. You would need to sort the objects by their Z position before applying the transformations.
-

thomthom
- Global Moderator
-
- Posts: 17556
- 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
-
by Pilou » Thu Jul 02, 2009 3:18 pm
So i must use the Tig Advertissement more soon than I have expected 
-

Pilou
- Top SketchUcator
-
- Posts: 10032
- Joined: Wed Jan 23, 2008 10:33 pm
- Operating system: Windows
- SketchUp version: 6
- License type: Free
- SketchUp use: hobby
- Level of SketchUp: Advanced
-
by Pilou » Thu Jul 02, 2009 3:38 pm
This group.bounds.min.z. can be found somewhere or the sorting of Groups must be forged again? (nothing about sort, sorting in the API helping) 
-

Pilou
- Top SketchUcator
-
- Posts: 10032
- Joined: Wed Jan 23, 2008 10:33 pm
- Operating system: Windows
- SketchUp version: 6
- License type: Free
- SketchUp use: hobby
- Level of SketchUp: Advanced
-
by thomthom » Thu Jul 02, 2009 3:48 pm
Build a hash with the entities as the key and their Z posiiton as value and then sort the hash by the values.
-

thomthom
- Global Moderator
-
- Posts: 17556
- 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
-
by Pilou » Thu Jul 02, 2009 4:05 pm
Each groups has not a "time creation" trace board? So no need to remake a sorting ? Seems I have re-open a new nightmare door 
-

Pilou
- Top SketchUcator
-
- Posts: 10032
- Joined: Wed Jan 23, 2008 10:33 pm
- Operating system: Windows
- SketchUp version: 6
- License type: Free
- SketchUp use: hobby
- Level of SketchUp: Advanced
-
by Chris Fullmer » Thu Jul 02, 2009 5:23 pm
Awesome Pilou! Keep it up, its looking great. You've got lots of good help around here.
Chris
-

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
-
by TIG » Thu Jul 02, 2009 5:39 pm
Try something like... - Code: Select all
zeds=[] index=0 groups.each{|group| zeds.push(group.bounds.min.z, index) index+=1 } zeds.sort! sorted_groups=[] zeds.each{|z|sorted_groups.push(groups[z[1]]) } ### sorted_groups is now groups sorted by Z
TIG
-

TIG
- Global Moderator
-
- Posts: 13929
- 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
by Pilou » Thu Jul 02, 2009 6:02 pm
Does the group.bounds.min.z only valuable in SU 7? Edit seems not  little try but seems I miss something  (any doubt selection but the sorted_groups gives nothing on the screen) - Code: Select all
model = Sketchup.active_model entities = model.entities selection = model.selection groups = [] z=0 zeds=[] index=0 groups.each{|group| zeds.push(group.bounds.min.z, index) index+=1 } zeds.sort! sorted_groups=[] zeds.each{|z|sorted_groups.push(groups[z[1]]) } ### sorted_groups is now groups sorted by Z
sorted_groups.each do |e| point = Geom::Point3d.new 0,0,z t = Geom::Transformation.new point e.transform!(t) z = z + 1000.mm end
-

Pilou
- Top SketchUcator
-
- Posts: 10032
- Joined: Wed Jan 23, 2008 10:33 pm
- Operating system: Windows
- SketchUp version: 6
- License type: Free
- SketchUp use: hobby
- Level of SketchUp: Advanced
-
by TIG » Thu Jul 02, 2009 6:58 pm
groups = [] then nothing set !!! You emptied the groups array... You need to fill it from the selection... - Code: Select all
groups=[];selection.each{|entity|groups.push(entity) if entity.kind_of?(Sketchup::Group)}
Last edited by TIG on Thu Jul 02, 2009 9:17 pm, edited 1 time in total.
TIG
-

TIG
- Global Moderator
-
- Posts: 13929
- 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
by 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
-

Pilou
- Top SketchUcator
-
- Posts: 10032
- Joined: Wed Jan 23, 2008 10:33 pm
- Operating system: Windows
- SketchUp version: 6
- License type: Free
- SketchUp use: hobby
- Level of SketchUp: Advanced
-
by 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 
You're hooked now! No way back! 
-

thomthom
- Global Moderator
-
- Posts: 17556
- 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
-
by 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
-

TIG
- Global Moderator
-
- Posts: 13929
- 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
by Pilou » Fri Jul 03, 2009 3:41 pm
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.
-

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

TIG
- Global Moderator
-
- Posts: 13929
- 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
by Pilou » Sat Jul 04, 2009 1:15 pm
Thx I had missed this one 
-

Pilou
- Top SketchUcator
-
- Posts: 10032
- Joined: Wed Jan 23, 2008 10:33 pm
- Operating system: Windows
- SketchUp version: 6
- License type: Free
- SketchUp use: hobby
- Level of SketchUp: Advanced
-
by Pilou » Tue Jul 07, 2009 11:52 am
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.
-

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

thomthom
- Global Moderator
-
- Posts: 17556
- 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
-
by Pilou » Tue Jul 07, 2009 12:07 pm
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.
-

Pilou
- Top SketchUcator
-
- Posts: 10032
- Joined: Wed Jan 23, 2008 10:33 pm
- Operating system: Windows
- SketchUp version: 6
- License type: Free
- SketchUp use: hobby
- Level of SketchUp: Advanced
-
by Pilou » Wed Jul 15, 2009 2:55 pm
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 
-

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

thomthom
- Global Moderator
-
- Posts: 17556
- 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
-
by Pilou » Wed Jul 15, 2009 4:02 pm
Many thx! It's always the more easy ans usefull who is not written as example 
-

Pilou
- Top SketchUcator
-
- Posts: 10032
- Joined: Wed Jan 23, 2008 10:33 pm
- Operating system: Windows
- SketchUp version: 6
- License type: Free
- SketchUp use: hobby
- Level of SketchUp: Advanced
-
by Pilou » Wed Jul 15, 2009 5:05 pm
??? = error : in ‘initialize’: undefined local variable or method ‘boundbox’ - 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
-

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

thomthom
- Global Moderator
-
- Posts: 17556
- 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
-
by Pilou » Wed Jul 15, 2009 6:29 pm
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.
-

Pilou
- Top SketchUcator
-
- Posts: 10032
- Joined: Wed Jan 23, 2008 10:33 pm
- Operating system: Windows
- SketchUp version: 6
- License type: Free
- SketchUp use: hobby
- Level of SketchUp: Advanced
-
Return to Developers' Forum
|