3D Text and the API


#1

I’m thinking about using the add_3d_text method to add in window and door sizes into the 2D mode of the Wall Plugin.

The documentation seems fairly self explanatory however I don’t see a way to call out the text rotation.

Any thoughts or hints on using 3D text with the API within your model or a plugin?


#2

Are you asking how to rotate the 3D text? Create an empty group, add the 3d text to that group, then rotate the group any way you like with transformations. Once created, the 3d text is just faces and edges.


#3

On that same note what is the best font to use for 3D text that is both readable and a low poly count (compact)?


#4

No, I was wondering if there was some built in parameter I was missing. I will drop into a group and then move and rotate into position, I’ve got that covered.


#5

The 3dText geometry is not rotate-able in the API methods.
But it’s easily done - initially add it into a new group, then rotate that group.
You can also consider moving that group’s origin [transformation.origin etc] - relocating its entities by a translation transformation, and then moving that group by that transformation-inverse…
Thus its container’s origin is maintained, but the text itself located as you wish…
e.g. useful if you want the text-group centered on a particular point etc…

Also consider naming the text-group logically so it can be easily found in the Outliner.

And perhaps give the text-group a layer too ?


#6

For some reason no matter what value I put in for the alignment constants I still get the text aligned to the left. Is there a known issue with this?

TextAlignLeft, TextAlignRight, and TextAlignCenter


#7

The text is aligned IF it’s multi-line.
So two lines of text justified left/center/right.
However, the group taking the text geometry will always have its origin at the text’s bottom left corner.

To change it follow the steps in my previous post.

For example, to place the 3dText centered on a given point, add an empty group to some entities context, add the 3dText into that group, using that given point.
At this stage that point is the bottom-left of the text.
To relocate the text’s geometry, find the group.bounds.center and group.bounds.min…
Then get the vector between them.
Make a transformation translation using that vector.
Transform the group.entities by that using http://ruby.sketchup.com/Sketchup/Entities.html#transform_entities-instance_method
In that case there’s no need to relocate the group as its center is at the given point…
And its text-geometry is now also centered about point.


#8

Makes sense, I will give it a whirl.


#9

Here is the code:

	#########################
	#
	# Window Callout
	#
	#########################
	
	if @Calloutoption_db == "YES"
		
		win_width_ft = (win_width/12.0).floor
		win_width_in = (win_width - (win_width_ft * 12.0)).floor
		win_height_ft = (win_height/12.0).floor
		win_height_in = (win_height - (win_height_ft * 12.0)).floor
		windowtext = "#{win_width_ft}#{win_width_in}#{win_height_ft}#{win_height_in}"

		if advwinoptions == "YES"
			if win_installoption == "YES"
				win_style = @Windowattr_install[0]
				if win_style == "Picture"
					win_desc = 'PIC'
				elsif win_style == "Slider"
					win_desc = 'XO'
				elsif win_style == "Single Hung"
					win_desc = 'SH'
				else
					win_desc = ''
				end
				
				windowtext << win_desc
			end
		end
		
		grouptext = Sketchup.active_model.active_entities.add_group
		entities2 = grouptext.entities

		entities2.add_3d_text(windowtext, TextAlignCenter, "Arial", false, false, 4.5, 0.5, @Bpltz, true, 0.0)

		# Translates to window origin

		textx = win_loc - grouptext.bounds.center.x
		texty = @Std0y1 - 8.0

		main_transformation_win = Geom::Transformation.new([textx, texty, 0])
		grouptext.transform! main_transformation_win

		if @Layersoption == "ON"
			grouptext.layer = @Wall_dim_layer
		end

		@all_groups << grouptext
	end

#10

And here is the result:


#11

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.