Align component boundingbox to global axis
-
I am rewriting my plugin [Comp2LayerSenes] that creates scenes for parts for making dimensioned drawings. It currently calls the makeorthoviews but I am writing my own drawing views section. A problem that is not currently addressed is how to display parts drawn at an angle to the global axis ( for example a corner brace ) Currently the part is copied to a new layer in its original orientation and then the other views are created by rotating copies of the part. See attached drawing [problem scene]. Currently the user would see it was not correct and delete all but 1 view, rotate that view to align with the global axis, then recreate the views with one of the plugin's features. See attached drawing [corrected scene].
What I would like the program to do would be inspect the boundingbox corners and if they are not aligned with the global axis to transform the part into the aligned position before creating the additional views.
Having read what I could find here with the search function I have not found much help.
Any suggestions?
Keith
-
I will piggyback on this post to ask a related question both of which will be solved with linear algebra I am sure. How can you take a group's transformation and determine which way it is pointing (the components of its internal positive x) and its up (the components of its internal z)? I think this is just a middle step to the above problem where one calclulates the "basis vectors" of the bounding box by taking differences of coordinates of the corners and then normalizes them.
Probably bad form here to answer my own subquery but what the hey. The following code snippet demonstrates that for a particular component instance of an unscaled component or group, the basis vectors (component x, component y and component z) are just the [0-2], [4-6], and [8-10] positions of the component transformation. In my own particular case I am trying to add lift, drag and thrust values to objects in sketchyphysics based on the attitude of the object.
` model = Sketchup.active_model
entities = model.entities
selection = model.selection
#this assumes only one entity in the drawing
#which would be a group or component
#the basis vectors for the component definition
#are calculated into xvdc,yvec and zvec
#and then drawn at the origin
t=entities[0].transformation.to_a
orig=[0,0,0]
xvec=[]
yvec=[]
zvec=[]
for i in 0..2 do
xvec.push(t[i])
yvec.push(t[i+4])
zvec.push(t[i+8])end
puts xvec
puts yvec
puts zvec
entities.add_line(orig,xvec)
entities.add_line(orig,yvec)
entities.add_line(orig,zvec)` -
I AM CANCELING MY REQUEST FOR THIS HELP:
After looking at posts on this subject I realize that the bounding box and selection box are 2 separate things and I am going to abort the attempt to rotate the component and align it with the global axis before making the drawing views. For most ww projects there are few parts for which the user will need to correct the drawing views and the plugin already has a feature that makes this easy so I am going to stick with that solution.
Keith
-
So just to verify, are either of you still asking any questions?, or did you both solve your own issues?
Chris
-
You are a good man Chris. ....as Rosanne Rosana Dana once so eloquently said.....never mind.
Advertisement