Transformation Newbie...
-
Martin says this is the best newbie forum on Earth!
http://www.martinrinehart.com/models/tutorial/tutorial_toc.htmlAlthough I can't consider myself a complete newbie - transformations make me feel that way:
I'm trying to add a face entity to an existing group nested within a
component instance. The model structure looks like this:model > dynamic component instance > group
I'm trying to add a new face to the nested group through Ruby. There
is no edit context when the ruby tool is initialized.the code:
#@ip2,@ip3,@ip4 are input points defining three corners of the
rectangular face
#@ptCalculated is the fourth computed corner of the rectangular
face
#@spacegroupdef is the existing group inside a DC instance#put the rectangle in a group temporarily so the face and 4 edges
can be transformed as a unit
bumpgroup = @spacegroupdef.entities.add_group
bumpgroup.name = "temp bumpgroup"
#insert the new face
face1 =
bumpgroup.entities.add_face(@ip2.position,@ip3.position,@ip4.position,@ptCalculated)trans_array = Array.[](1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1) #first, rotate - no rotation required #second, scale trans_array[0]= trans_spacegroup.inverse.to_a()[0] trans_array[5]= trans_spacegroup.inverse.to_a()[5] #If the transform! is conducted at this time, the scaling is
correct
#I'm sure the input point comes from within the existing face that
is in the nested group
trans_array[12] = -(@ip2_transformation.to_a()[12]) #Xt
trans_array[13] = -(@ip2_transformation.to_a()[13]) #Ytnew_transform_2 = Geom::Transformation.new(trans_array) bumpgroup.transform! new_transform_2
The translation executes but it is not correct.
I have tried using two separate transformations in different orders.
First scale, then translate as above with the same result.Also first translate, then scale. In this case the translate works,
but after applying the scale I get incorrect results.Not sure where I am going wrong. Any ideas about what I need to do to
get the X and Y translation correct?Kind thanks!
-
You are picking the points in the model.
The group has a transformation within the component-definition
The component-instance has a transformation within the model.
You have four points.
Make a transformation that uses the instance and group transformations [inverse] and apply that to the points [got from the ip's or calculated]
Then add the face to the group from the transformed points...
p2=@ip2.position
p3=@ip3.position
p4=@ip4.position
p5=@ptCalculated
tr=@spacegroupdef.transformation.inverse * spacegroup.transformation.inverse
[p2,p3,p4,p5].each{|p|p.transform!(tr)}
bumpgroup.entities.add_face(p2,p3,p4,p5)I haven't tested this but you need to somehow apply the containers' transformations backwards onto the face's points...
-
Thank you TIG,
I understand the concept - and will let you know how it goes.
T
-
InputPoint.transformation
http://code.google.com/intl/no/apis/sketchup/docs/ourdoc/inputpoint.html#transformationGives you the transformation for the input point. Will probably be useful to you for converting between local and model co-ordinates.
Advertisement