CPoints at Bounding Box corners?
-
This one liner does it, adding the 8 cpoints to the corners of the bounding-box of any selection
m=Sketchup.active_model;b=Geom;;BoundingBox.new;m.selection.each{|e|b.add(e.bounds)};8.times{|i|m.active_entities.add_cpoint(b.corner(i))}
It could probably do with some trapping etc... but you get the idea ?
-
-
If you read the code it gets the bounds of the selection and adds cpoints at the bounds corners - that's all you need to know
Select some geometry and copy/paste the code into the Ruby Console to see what it does... -
Doesn't take into account groups / components that are not aligned to the model axis.
-
@tig said:
If you read the code it gets the bounds of the selection and adds cpoints at the bounds corners - that's all you need to know
Select some geometry and copy/paste the code into the Ruby Console to see what it does...I realise how to use it. It's was the trapping comment that had me puzzled.
Thanks anyway. Both of ye
-
It does... in that it returns the bounds of the selection, and NOT individual objects within the selection, and a selection's bounding-box is always parallel to the axes irrespective of the selected objects' transformation...
Rich didn't ask for cpoints at the corners of one selected object's bounds.
I gave him cpoints at the corners of the selection's bounds - which might not be the same thing for rotated individual groups/instances... -
Being able to select a series of groups and components then it places cpoints at all bounding boxes would be sweet.
-
Try this
m=Sketchup.active_model;m.start_operation("BBcpts");m.selection.each{|e|next unless e.class==Sketchup;;Group or e.class==Sketchup;;ComponentInstance;t=e.transformation;e=e.definition if e.class==Sketchup;;ComponentInstance;b=Geom;;BoundingBox.new;e.entities.each{|a|b.add(a.bounds)};8.times{|i|m.active_entities.add_cpoint(b.corner(i).transform(t))}};m.commit_operation
adds cpoints at the 8 corners of each selected group/instance's bbox, accounting for transformations... One step undoable.
-
Is getting these control point within the group/component possible?
It's anchors for alignment that I'm looking for. If it's too much hassle forget it.
On a layer would be kinda cool too
-
I originally has them inside each container but [foolishly] assumed you wanted them outside!
m=Sketchup.active_model;m.start_operation("BBcpts");m.selection.each{|e|next unless e.class==Sketchup;;Group or e.class==Sketchup;;ComponentInstance;e=e.definition if e.class==Sketchup;;ComponentInstance;b=Geom;;BoundingBox.new;e.entities.each{|a|b.add(a.bounds)};8.times{|i|e.entities.add_cpoint(b.corner(i)).layer=m.layers.add("BBCP")}};m.commit_operation
This version puts the cpoints within each container and uses layer 'BBCP' for them.
-
Can i put it in a class then a def and load it to plugins?
Or is it a module?
Actually forget it
-
Sorry, Thanks TIG
-
module ROB menu=UI.menu("Plugins").add_item("BBcpts"){self.bbcpts()}unless file_loaded?(File.basename(__FILE__)) file_loaded(File.basename(__FILE__)) def self.bbcpts() ### paste the main code here... end end
Copy/paste the code into a file in the Plugins folder called
ROB-bbcpts.rb
Usage: typeROB.bbcpts
OR pick "BBcpts" off the Plugins menu etc...
Advertisement