add_3d_text to arbitrary location?


#1

Hi,

I know that add_3d_text adds 3d text to the center of the origin. Unfortunately, it also doesn’t return a handle. How can I reference this object and place it in an arbitrary place in the world (x,y,z,r,p,y) programmatically?

-Andy S.


#2

Create an empty group instance, and add the 3D text to this group’s entities collection.
Then transform the group instance where ever you wish.


#3

Hi Dan,

That sounds like a very reasonable thing to do. But how do I actually add the 3D text to the group’s entities collection? It sounds from the API documentation that the function call just returns success or failure. How do I get a reference to the 3d text?

-Andy S.


#4

For example:

group=model.active_entities.add_group
group.entities.add_3d_text('test', TextAlignLeft, "Arial", true, false, 1.0, 0.0, 0.5, true, 5.0)

Now ‘group’ contains the 3d_text.

Make some transformations…

tr=Geom::Transformation.rotation(ORIGIN, Z_AXIS, angle.degrees)
tp=Geom::Transformation.new(some_point)

Apply those to the group…

group.transform!(tp*tr)

The order in which you combine your transformations affects the final result - right-hand-most first?..


#5

The SketchUp design does not allow entities that don’t belong to a parent entities collection (different from HTML entities and document fragments). This is very sensible and avoids edge cases.
So there are “factory methods” on entity collections that produce new entities directly inside of that collection:

You initially have some reference to an entity collection (like model.active_entities or model.entities).

group = entities.add_group
group.add_3d_text('test', TextAlignLeft, 'Liberation',  true, false, 1.0, 0.0, 0.5, true, 5.0)
transformation = Geom::Transformation.rotation(ORIGIN, Y_AXIS, 45.degrees)
transformation *= Geom::Transformation.translation([10, 10, 0]) 
group.transform!(transformation)

#6

Ah, I understand, thank you both, I will try that now.