by EarthMover » Tue Aug 07, 2012 2:26 pm
Is it possible through ruby (or does something exist) to scale a face to a desired area size? Let's say I draw an irregular shape which needs to be a specific square footage. Is it possible to have a plugin which let you click on the face and set a desired square footage and the face automatically scales to that area? I'm drawing a bunch of different free form (lagoon style) pools for a client, but have a target square footage the shapes. I can get close with trial and error and scale tool, just thought it would be nice to do it exact through a script. EDIT - Plugin attached. Thanks TIG. EDIT: by TIG - code fixed for all unit types ! TIG Donations==
Last edited by EarthMover on Fri Aug 10, 2012 5:12 pm, edited 3 times in total.
3D Artist at Clearstory 3D Imaging Guide Tool at Winning With Sketchup Content Creator at Skapeup
-

EarthMover
- Premium Member

-
- Posts: 1801
- Joined: Fri Sep 12, 2008 9:06 pm
- Location: Eastern Pennsylvania
- Name: EarthMover
- Operating system: Windows
- SketchUp version: 2016
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by thomthom » Tue Aug 07, 2012 3:35 pm
- Code: Select all
module TT_ScaleToArea def self.scale_face( face, target_area ) unit_ratio = '1'.to_l ** 2 target_area_inch = target_area * unit_ratio ratio = target_area_inch / face.area pt = face.bounds.center tr = Geom::Transformation.scaling( pt, ratio ) face.parent.entities.transform_entities( tr, [face] ) end end
TT_ScaleToArea.scale_face( Sketchup.active_model.selection[0], 4000 )target_area is numeric input in the current model units.
-

thomthom
- PluginStore Author

-
- Posts: 19496
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by TIG » Tue Aug 07, 2012 3:49 pm
Here's my version, with dialog... - Code: Select all
require 'sketchup.rb' ### module TIG ### scales a select face about its center to a new area, in current uinits. def self.scale_face() model=Sketchup.active_model es=model.active_entities ss=model.selection fa=nil fa=ss[0] if ss[0] unless fa && fa.is_a?(Sketchup::Face) UI.messagebox("Scale_Face:\n\nPreSelect ONE FACE !") return nil end ar=fa.area mo=model.options["UnitsOptions"] p mo["LengthFormat"] case mo["LengthUnit"] when 0 units="in" if mo["LengthFormat"]==2 #Engineering trap ">>' units="ft" ar=ar/12.0/12.0 end when 1 units="ft" ar=ar/12.0/12.0 when 2 units="mm" ar=ar*25.4*25.4 when 3 units="cm" ar=ar*25.4*25.4/10/10 when 4 units="m" ar=ar*25.4*25.4/1000/1000 else units="??" end rs=inputbox(["New Area [sq "+units+"]: "], [ar], "Scale_Face") return nil unless rs na= rs[0] na= -na if na < 0 unless na>0 UI.beep return nil end ro=Math.sqrt(na/ar) pt=fa.bounds.center tr=Geom::Transformation.scaling(pt, ro) model.start_operation("Scale_Face") es.transform_entities(tr, fa.vertices) model.commit_operation end ### UI.menu("Plugins").add_item("Scale_Face"){self.scale_face()} unless file_loaded?(__FILE__) file_loaded(__FILE__) ### end ###
Copy/paste code into a script in the Plugins folder named 'TIG-scale_face.rb', and restart Sketchup. Run it from the menu item or by typing TIG.scale_face in the Ruby Console... EDIT: Typo fixed in menu code !!! EDIT: Improved Unit/Fractional/Engineering handling - see 1st post in the thread for the .rb version.
TIG
-

TIG
- Global Moderator
-
- Posts: 20308
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by thomthom » Tue Aug 07, 2012 4:14 pm
na = -na if na < 0 Why not just use #abs ? na = na.abs
-

thomthom
- PluginStore Author

-
- Posts: 19496
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by TIG » Tue Aug 07, 2012 4:31 pm
thomthom wrote:na = -na if na < 0 Why not just use #abs ? na = na.abs
No reason. I assume you meant na=results[0].abs as a one-step solution. I was just writing it on the fly and needed to trap for a negative or zero reply... Incidentally, I noted that you transformed the face while I did the face.vertices, is there any advantage in either way? Presumably transforming the face changes its vertices and what they are connected to anyway, and conversely transforming the vertices transforms the face and also whatever they are connected to also ?
TIG
-

TIG
- Global Moderator
-
- Posts: 20308
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by thomthom » Tue Aug 07, 2012 4:47 pm
TIG wrote:Incidentally, I noted that you transformed the face while I did the face.vertices, is there any advantage in either way? Presumably transforming the face changes its vertices and what they are connected to anyway, and conversely transforming the vertices transforms the face and also whatever they are connected to also ?
I'd expect that under the hood, when you feed entities to #transform_entities it collects the vertices - so [face] and face.vertices should have the exact same effect. I kind of liked face.vertices instead of wrapping the face in an array - feel it reads better as the brackets isn't so easy to see immediately.
-

thomthom
- PluginStore Author

-
- Posts: 19496
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by TIG » Tue Aug 07, 2012 5:02 pm
Actually just face should work as well as [face] because the transformation is the first argument and you can then pass an array OR a series of arguments, so 'face' would be seen as the first one anyway ? ...
TIG
-

TIG
- Global Moderator
-
- Posts: 20308
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by thomthom » Tue Aug 07, 2012 5:17 pm
API-doh!
-

thomthom
- PluginStore Author

-
- Posts: 19496
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by EarthMover » Tue Aug 07, 2012 9:31 pm
 You guys both rock! THANKS so much!
3D Artist at Clearstory 3D Imaging Guide Tool at Winning With Sketchup Content Creator at Skapeup
-

EarthMover
- Premium Member

-
- Posts: 1801
- Joined: Fri Sep 12, 2008 9:06 pm
- Location: Eastern Pennsylvania
- Name: EarthMover
- Operating system: Windows
- SketchUp version: 2016
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by jorge2011 » Wed Aug 08, 2012 3:20 am
-
jorge2011
-
- Posts: 159
- Joined: Thu Jun 02, 2011 5:01 pm
- Name: jorge2011
- Operating system: Windows
- SketchUp version: 7
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Intermediate
by thomthom » Wed Aug 08, 2012 8:47 am
That's nice looking. The VCB is a nice way to control it. But I think $10 is too much for such a trivial script. 
-

thomthom
- PluginStore Author

-
- Posts: 19496
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by EarthMover » Wed Aug 08, 2012 2:18 pm
TIG, having an issue with your script loading properly. I copied and pasted the code exactly into a notepad file and named it - TIG-scale_face.rb. Upon loading Sketchup, I get no errors, but none of my toolbars load. When I delete the script, all the toolbars load again.
3D Artist at Clearstory 3D Imaging Guide Tool at Winning With Sketchup Content Creator at Skapeup
-

EarthMover
- Premium Member

-
- Posts: 1801
- Joined: Fri Sep 12, 2008 9:06 pm
- Location: Eastern Pennsylvania
- Name: EarthMover
- Operating system: Windows
- SketchUp version: 2016
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by EarthMover » Wed Aug 08, 2012 3:43 pm
Thom, excuse my ignorance, but how would I going about testing your code?
3D Artist at Clearstory 3D Imaging Guide Tool at Winning With Sketchup Content Creator at Skapeup
-

EarthMover
- Premium Member

-
- Posts: 1801
- Joined: Fri Sep 12, 2008 9:06 pm
- Location: Eastern Pennsylvania
- Name: EarthMover
- Operating system: Windows
- SketchUp version: 2016
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by thomthom » Wed Aug 08, 2012 4:15 pm
EarthMover wrote:Thom, excuse my ignorance, but how would I going about testing your code?
Sorry Adam, I typed it up and posted in a hurry. You'd put it in a .rb file and form the console invoke: TT_ScaleToArea.scale_face( Sketchup.active_model.selection[0], 4000 )Didn't have the time to add UI.
-

thomthom
- PluginStore Author

-
- Posts: 19496
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by TIG » Wed Aug 08, 2012 4:53 pm
The code is now tested and working version... I edited the original ! viewtopic.php?p=419936#p419936Stupid typo unless.file_loaded? instead of unless file_loaded? I added the UI as an afterthought and never tested it sorry!
TIG
-

TIG
- Global Moderator
-
- Posts: 20308
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by EarthMover » Thu Aug 09, 2012 3:11 pm
Thanks TIG. It works as long as I am using a decimal unit type. With fractional units, it deletes everything in the model. Not sure why, just have to remember to switch the units before using the plugin. Thanks again. I'll update the first post with the rb file. Also it is still stating inches in the dialog even when the units are feet. No big deal though. Works for what I need. Thanks again! 
3D Artist at Clearstory 3D Imaging Guide Tool at Winning With Sketchup Content Creator at Skapeup
-

EarthMover
- Premium Member

-
- Posts: 1801
- Joined: Fri Sep 12, 2008 9:06 pm
- Location: Eastern Pennsylvania
- Name: EarthMover
- Operating system: Windows
- SketchUp version: 2016
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by TIG » Thu Aug 09, 2012 3:21 pm
I'll adjust the code... I did type it on the fly...
TIG
-

TIG
- Global Moderator
-
- Posts: 20308
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by EarthMover » Thu Aug 09, 2012 4:18 pm
If you have time. If not, no worries. I just figured I'd mention the issues in case anyone else needed to use the plugin.
3D Artist at Clearstory 3D Imaging Guide Tool at Winning With Sketchup Content Creator at Skapeup
-

EarthMover
- Premium Member

-
- Posts: 1801
- Joined: Fri Sep 12, 2008 9:06 pm
- Location: Eastern Pennsylvania
- Name: EarthMover
- Operating system: Windows
- SketchUp version: 2016
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by TIG » Thu Aug 09, 2012 4:26 pm
I've updated the .rb in your post and edited the post's text to match [hope you are OK with that  ] It now handles all Unit-types/Fractional/Engineering etc properly. One oddity is that 'Engineering' displays on screen in 'feet', but the API unit-type [LengthUnit] is left in 'inches' [0] - unlike all other types where the 'LengthUnit' matches the displayed-unit. Anyway it now works for all combos... I hope 
TIG
-

TIG
- Global Moderator
-
- Posts: 20308
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by EarthMover » Thu Aug 09, 2012 5:12 pm
Works great now. Thanks again.
3D Artist at Clearstory 3D Imaging Guide Tool at Winning With Sketchup Content Creator at Skapeup
-

EarthMover
- Premium Member

-
- Posts: 1801
- Joined: Fri Sep 12, 2008 9:06 pm
- Location: Eastern Pennsylvania
- Name: EarthMover
- Operating system: Windows
- SketchUp version: 2016
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by hebeijianke » Thu Aug 09, 2012 6:36 pm
TIG wrote:I've updated the .rb in your post and edited the post's text to match [hope you are OK with that  ]
This plug-in only applies to the quadrangle
-
hebeijianke
-
- Posts: 43
- Joined: Tue Apr 28, 2009 2:01 am
- Name: hebeijianke
by TIG » Thu Aug 09, 2012 7:04 pm
NO, it works on any face. The selected face is simply scaled to have the desired area. The dialog shows the current area in current units. You enter the new area and OK. The selected face is made to have that area. So if it's a square, a star or a circle it doesn't matter...
TIG
-

TIG
- Global Moderator
-
- Posts: 20308
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by bmike » Thu Aug 09, 2012 8:31 pm
This is a great little plugin. Any chance to make it work in square ft, when my units are set to Architectural?
Or do I need to divide by hand first...?
-

bmike
-
- Posts: 680
- Joined: Mon Dec 15, 2008 6:42 pm
- Location: vermont
- Name: Mike Beganyi
- Operating system: Mac
- SketchUp version: 2016
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
-
by EarthMover » Thu Aug 09, 2012 8:34 pm
Works on almost any face. Faces created by the freehand tool seem to fail to resize properly. Not sure why.
3D Artist at Clearstory 3D Imaging Guide Tool at Winning With Sketchup Content Creator at Skapeup
-

EarthMover
- Premium Member

-
- Posts: 1801
- Joined: Fri Sep 12, 2008 9:06 pm
- Location: Eastern Pennsylvania
- Name: EarthMover
- Operating system: Windows
- SketchUp version: 2016
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by jorge2011 » Thu Aug 09, 2012 9:52 pm
thomthom wrote:That's nice looking. The VCB is a nice way to control it. But I think $10 is too much for such a trivial script. 
YES thomthom. You are right, it's a plugin with a high cost. I made the post, the plugin is very interesting, and has features that can be added to the free version plugin of sr. TIG.
-
jorge2011
-
- Posts: 159
- Joined: Thu Jun 02, 2011 5:01 pm
- Name: jorge2011
- Operating system: Windows
- SketchUp version: 7
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Intermediate
by TIG » Fri Aug 10, 2012 9:46 am
bmike wrote:This is a great little plugin. Any chance to make it work in square ft, when my units are set to Architectural? Or do I need to divide by hand first...?
Here's a version of the code for users who want to work in feet OR inches [any kind] and see 'sq ft' areas; it also does 'sq m' areas if the user is using any metric units [m/cm/mm]... Copy the code and paste it into the .rb file using Notepad or similar plain-text editor - overwriting all of the original code... - Code: Select all
require 'sketchup.rb' ### module TIG ### scales a selected face about its center to a new area, in current units. def self.scale_face() model=Sketchup.active_model es=model.active_entities ss=model.selection fa=nil fa=ss[0] if ss[0] unless fa && fa.is_a?(Sketchup::Face) UI.messagebox("Scale_Face:\n\nPreSelect ONE FACE !") return nil end ar=fa.area mo=model.options["UnitsOptions"] if mo["LengthUnit"] > 1 ### metric units="m" ar=ar*25.4*25.4/1000/1000 else ### ft/" units="ft" ar=ar/12.0/12.0 end rs=inputbox(["New Area [sq "+units+"]: "], [ar], "Scale_Face") return nil unless rs na= rs[0] na= -na if na < 0 unless na>0 UI.beep return nil end ro=Math.sqrt(na/ar) pt=fa.bounds.center tr=Geom::Transformation.scaling(pt, ro) model.start_operation("Scale_Face") es.transform_entities(tr, fa.vertices) model.commit_operation end ### UI.menu("Plugins").add_item("Scale_Face"){self.scale_face()} unless file_loaded?(__FILE__) file_loaded(__FILE__) ### end ###
TIG
-

TIG
- Global Moderator
-
- Posts: 20308
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by EarthMover » Fri Aug 10, 2012 4:45 pm
Thanks TIG. That's even better!
3D Artist at Clearstory 3D Imaging Guide Tool at Winning With Sketchup Content Creator at Skapeup
-

EarthMover
- Premium Member

-
- Posts: 1801
- Joined: Fri Sep 12, 2008 9:06 pm
- Location: Eastern Pennsylvania
- Name: EarthMover
- Operating system: Windows
- SketchUp version: 2016
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by TIG » Fri Aug 10, 2012 4:46 pm
Do you want to add an alternative version .rb in the first post ?
TIG
-

TIG
- Global Moderator
-
- Posts: 20308
- Joined: Mon Nov 12, 2007 7:24 pm
- Location: Northumbria UK
- Name: TIG
- Operating system: Windows
- SketchUp version: 2021
- License type: Pro
- SketchUp use: architecture
- Level of SketchUp: Advanced
by EarthMover » Fri Aug 10, 2012 5:10 pm
Sure, I can. If you feel like dropping it in it's own thread for proper indexing, let me know and I'll remove the bracketed plugin wording. Or feel free to edit it yourself if need be. I don't mind at all.
3D Artist at Clearstory 3D Imaging Guide Tool at Winning With Sketchup Content Creator at Skapeup
-

EarthMover
- Premium Member

-
- Posts: 1801
- Joined: Fri Sep 12, 2008 9:06 pm
- Location: Eastern Pennsylvania
- Name: EarthMover
- Operating system: Windows
- SketchUp version: 2016
- License type: Pro
- SketchUp use: landscape architecture
- Level of SketchUp: Advanced
-
by irich » Thu Sep 27, 2012 9:27 pm
Hi guys!
Thank you for this plugin it’s very very useful. My question is, is it possible to make it scale texture on face too? If you for example have one projected texture on face.
-
irich
-
- Posts: 3
- Joined: Wed Sep 22, 2010 3:08 pm
- Name: irich
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Plugins
|