Ruby api - Get the thickness of component
-
Hi everyone,
This is my very first post in this great forum. I encounter some problem when finding and using ruby api.
What I want to do know is duplicate a component - (by selecting it using model.selection[0] ), and put the duplicated one on top of the original one. I have problem with find the x,y,z of a component in space and its thickness.
I think this should be an easy issue for experienced sketchup users here
-
<drunkcode><span class="syntaxdefault"><br />model </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model<br />instance </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">selection</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]<br /></span><span class="syntaxdefault">point </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">instance</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">bounds</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">corner</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">4</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">tr </span><span class="syntaxkeyword">= </span><span class="syntaxdefault">Geom</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Transformation</span><span class="syntaxkeyword">.new( </span><span class="syntaxdefault">point </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_instance</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">instance</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">definition</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">tr </span><span class="syntaxkeyword">)<br /> </span><span class="syntaxdefault"></span></drunkcode> -
You have
instance1.
That hasbounds.
So to find its vertical extent use
zz=instance1.bounds.depth
Note that the three values for a bounding-box are counter-intuitive - following the old CAD conventions when z/depth was out of the screen - it's NOT the 'height' !
Sobounds
.width>>> x Red
.height>>> y Green
.depth>>> z Blue
You can also get its transformation
tr=instance1.transformation
Use that to insert your duplicate.
instance2=instance1.parent.entities.add_instance(instance1,definition, tr)
This now overlays the two exactly.
To move the new instance up in the 'z' by 'zz' make a vector and apply a second transformation to it - you could apply it as you insert it BUT this is perhaps an easier way to get your head around...
ve=Z_AXIS.clone ve.length=z tv=Geom::Transformation.translation(ve) instance2.transform!(tv)
The second instance should now rise up so its bottom-most part aligns with the original's top-most part. -
@TIG
Thanks for the great long and damn useful answer. I will try it today
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement