Using add_3d_text
-
Hello,
I'm using the command add_3d_text to add text to objects. How do you
change orientation of the text so that it looks like it's on the
surface of a plane? For example, I'd like the text to display at the
top and front of a rectangular cube.Here is a code snippet:
top plane
pt1 = Geom::Point3d.new(x,y,z+h)
pt2 = Geom::Point3d.new(x+w,y,z+h)
pt3 = Geom::Point3d.new(x+w,y+l,z+h)
pt4 = Geom::Point3d.new(x,y+l,z+h)
edges[0] = entities.add_line(pt1, pt2)
edges[1] = entities.add_line(pt2, pt3)
edges[2] = entities.add_line(pt3, pt4)
edges[3] = entities.add_line(pt4, pt1)
face = entities.add_face edges
face.material = mt=Geom::Transformation.new(pt1)
grp=entities.add_group(); grpEnts=grp.entities
grpEnts.add_3d_text("hey mon", 1, "Arial", false, false, 4.inch,
1.mm, 0, false, 0)
grp.move!(t)front plane
pt1 = Geom::Point3d.new(x,y,z)
pt2 = Geom::Point3d.new(x+w,y,z)
pt3 = Geom::Point3d.new(x+w,y,z+h)
pt4 = Geom::Point3d.new(x,y,z+h)
edges[0] = entities.add_line(pt1, pt2)
edges[1] = entities.add_line(pt2, pt3)
edges[2] = entities.add_line(pt3, pt4)
edges[3] = entities.add_line(pt4, pt1)
face = entities.add_face edges
face.material = mt=Geom::Transformation.new(pt4)
grp=entities.add_group(); grpEnts=grp.entities
grpEnts.add_3d_text("hey mon", 1, "Arial", false, false, 4.inch,
1.mm, 0, false, 0)
grp.move!(t)
Thank you.
Greg
-
Mods, please move this to the Ruby Forum.
-
Done.
-
Yeah, this is definitely ruby stuff.
BTW welcome, Greg, but what do you mean by "done"?
-
Done means I moved the posting to this forum, Ruby Discussions, from the 'Newbie' forum. Actually, I copied this from the 'Newbie' forum to this forum, 'Ruby Discussions'. I don't know how to move a posting.
Is there a more appropriate forum then 'Ruby Discussions'?
-
Just a follow-up to clarify my question: How do I set the (x,y,z) coordinates of the text to control it's orientation?
I am programmatically assigning 3dtext as pallet labels to the front and top of pallets in a virtual warehouse created from ruby code generated from a c# application accessing inventory data from a SQL database, 2 to 3 thousand pallets.
Right now, the text just lays flat on an x,y plane. That works for printing text on the top of pallets, but I can't orient the text upright so that it properly prints on the front of pallets.
I hope this makes sense.
Thank you.
Greg
-
@greg said:
Done means I moved the posting to this forum, Ruby Discussions, from the 'Newbie' forum. Actually, I copied this from the 'Newbie' forum to this forum, 'Ruby Discussions'. I don't know how to move a posting.
Ok, I see. I also moved your topic nd then found that you copied it here so I merged the two.
@unknownuser said:
Is there a more appropriate forum then 'Ruby Discussions'?
No, this is the finest forum for this (in the World? )
-
See my TextTag script that does this. The 3d-text is grouped, it appears at 0,0,0, it's then transformed to where you want it, snapping to faces etc as desired...
http://www.sketchucation.com/forums/scf/viewtopic.php?f=57&t=2954&p=20077&hilit=texttag#p20077
-
Thanks TIG,
I actually used your code as a guide to get as far as you see here. But I don't see how to programmatically snap the 3dtext to the front and side of a cubed-shaped object (pallet) without user intervention. I need the application to snap the text to the pallet automatically.
Is this the section of your code I should reference for the 'snapto' functionality?
%(#FF0040)[compo.behavior.always_face_camera=true if @cfacing=="Yes" ### faces camera
if @asnap=="Yes"
compo.behavior.is2d=true
compo.behavior.snapto=0 ### snaps to Any surface
end#iftag=model.place_component(compo)]
If so, I can't figure out the relationship between your compo (components) and my grpEnts (entities).
Greg
-
After you have auto-placed the grp containing the 3d-text you need to rotate it in Z, then so it's vertical. You need to make a "rotation transformation"...
transformation=Geom::Transformation.rotation(anchor_point,vector_axis,angle_radians)
e.g. for a right-angle about Z try -
rotate=Geom::Transformation.rotation(pointN.[0,0,1],90.degrees)
e.g. for a right-angle about Y try -
rotate=Geom::Transformation.rotation(pointN.[0,1,0],90.degrees)
etc
Mess around to find which you need for which group...
-
Thanks TIG, I'll do this.
Greg
-
TIG,
I have tried variations of the code but I can't get it to work.
%(#FF0040)[txtPt = Geom::Point3d.new(x+w,y,z+(h/2))
t=Geom::Transformation.new(txtPt)
grp=entities.add_group(); grpEnts=grp.entities
grpEnts.add_3d_text("hey mon", 1, "Verdana", false, false, 4.inch, 1.mm, 0, false, 0)
grp.move!(t)grp = Geom::Transformation.rotation(txtPt,[0,0,1],90.degrees) # these are variations
txtPt = Geom::Transformation.rotation(txtPt,[0,0,1],90.degrees) # these are variations
t = Geom::Transformation.rotation(txtPt,[0,0,1],90.degrees) # these are variations
rotate = Geom::Transformation.rotation(grp,[0,0,1],90.degrees) # these are variations]I don't understand the relationship of 'Geom::Transformation.rotation(point,vector,angle)' to grpEnts.add_3d_text.
What am I overlooking?
Thank you.
Greg
-
TIG,
Thanks for your help. The following code 'status = grpEnts.transform_entities t, grpEnts.collect' rotates the 3D-Text:
txtPt = Geom::Point3d.new(x+w,y,z+(h/2))
t=Geom::Transformation.new(txtPt)
grp=entities.add_group(); grpEnts=grp.entities
grpEnts.add_3d_text("hey mon", 1, "Verdana", false, false, 4.inch, 1.mm, 0, false, 0)
grp.move!(t)t = Geom::Transformation.rotation(txtPt,[1,0,0],90.degrees)
status = grpEnts.transform_entities t, grpEnts.collectThis was copied from ldraw.rb.
Greg
-
I'd expect this to work for the 't' rotation - note that I prefer to keep things inside parentheses () - although it will work without (usually):
grpEnts.transform_entities(t,grpEnts)
or for the group rather than it's entities
grp.transform!(t)
(it's similar to grp.move!(t) ...)
Now you just have to copy this group of 3d-text (grp2=grp.copy!) and move! it around the corner and rotate transform! it to suit.
In SketchUp Ruby here are often several ways of doing the same complex thing - like transformations -, BUT sometimes there's NOT one way of doing some simple thing !!! For example finding the active section-plane or finding if sections-cuts are currently being shown in the view (something I'm looking at currently) - even the SDK doesn't access these shortcomings in the API...
Glad you fixed it.
-
Thanks TIG,
I'll apply your suggestions and evaluate the results.
Greg
Advertisement