How to change text font via ruby?

1,495 views
Skip to first unread message

maria.s

unread,
Feb 17, 2010, 9:46:26 AM2/17/10
to Google SketchUp Developers - SketchUp Ruby API
Hi, ruby experts!

How can I change my text object font via ruby API?
Appreciate your suggestions!

Dan Rathbun

unread,
Feb 17, 2010, 4:37:30 PM2/17/10
to Google SketchUp Developers - SketchUp Ruby API
On Feb 17, 9:46 am, "maria.s" wrote:
> How can I change my text object font via ruby API?

What platform are you programming for:
Apple-Mac OSX?
PC Windows?
BOTH (cross-platform)?


What is the text object used for:
WebDialog (HTML) ?
Model.add_note ?
View.tooltip ?
View.draw_text ?
Sketchup::Text class ?

maria.s

unread,
Feb 18, 2010, 6:53:56 AM2/18/10
to Google SketchUp Developers - SketchUp Ruby API
I'm using Windows and Sketchup::Text class.

Dan Rathbun

unread,
Feb 19, 2010, 4:00:25 AM2/19/10
to Google SketchUp Developers - SketchUp Ruby API
On Feb 18, 6:53 am, "maria.s" wrote:
> I'm using Windows and Sketchup::Text class.

I also.

And I wish to also change Sketchup::Text attribute
(:fontface, :fontsize, :bold, :italic, :align, :color),
both before adding text and later to change them.

I find no easy solution via Instance Methods for the Text class.

Will have to add to the API Wishlist.

maria.s

unread,
Feb 19, 2010, 6:29:26 AM2/19/10
to Google SketchUp Developers - SketchUp Ruby API
Thanks for your answer!

And is there any document such as Ruby SU API Wishlist?=)

TIG

unread,
Feb 19, 2010, 9:37:04 AM2/19/10
to Google SketchUp Developers - SketchUp Ruby API
I put Text.font & Text.font= on list a while ago with several other
things like Text.height and Text.height= ...

Dan Rathbun

unread,
Feb 19, 2010, 6:52:25 PM2/19/10
to Google SketchUp Developers - SketchUp Ruby API
On Feb 19, 9:37 am, TIG wrote:
> I put Text.font & Text.font= on list a while ago with several other
> things like Text.height and Text.height= ...
>
> On Feb 19, 11:29 am, "maria.s" wrote:
> > And is there any document such as Ruby SU API Wishlist?=)

SketchUp RUBY API Wishlist
http://forums.sketchucation.com/viewtopic.php?f=180&t=13666

Dan Rathbun

unread,
Feb 20, 2010, 4:50:14 AM2/20/10
to Google SketchUp Developers - SketchUp Ruby API
On Feb 19, 4:00 am, Dan Rathbun wrote:
> On Feb 18, 6:53 am, "maria.s" wrote:
>
> > I'm using Windows and Sketchup::Text class.
>
> I also.
> And I wish to also change Sketchup::Text attribute
> (:fontface, :fontsize, :bold, :italic, :align, :color),
>
> I find no easy solution via Instance Methods for the Text class.

I realized how to at least, change Text Color, after creation, using
DrawingElement.material=
The Sketchup::Text class is a subclass of Sketchup::DrawingElement, so
inherits it's parent's methods.

# --- ruby ---
model = Sketchup.active_model
ents = model.entities
pt = Geom::Point3d.new(10,10,10)
t1 = ents.add_text('This is a Test', pt)
t1.vector=[10,10,10]
# change Text color to Magenta
t1.material=Sketchup::Color.new(200,0,200)
# --- end ruby ---

.material= also takes a Sketchup::Color Name

TIG

unread,
Feb 20, 2010, 5:17:45 AM2/20/10
to Google SketchUp Developers - SketchUp Ruby API
If you want complex Text with changeable attributes then you could
look at my 2Dtools > 2Dtext or my older TextTag.rb. These make a
piece of 'flat' 3D text [='2D'] to your specifications of text/font/
height/color/various_style_settings etc. It is then made/placed as a
component - you can edited it later on by selecting an instance, right-
click, context-menu - and then any if these original attributes can be
changed...

Dan Rathbun

unread,
Feb 20, 2010, 7:16:40 AM2/20/10
to Google SketchUp Developers - SketchUp Ruby API
On Feb 20, 5:17 am, TIG <t...@revitrev.org> wrote:
> If you want complex Text with changeable attributes then you could
> look at my 2Dtools > 2Dtext or my older TextTag.rb.  These make a
> piece of 'flat' 3D text [='2D'] to your specifications ...

But it's a 3DText object still. Made up of Edges and Faces.

Can you change the text string after the fact?
Does it stay rotated to face the view like 2DText?
Does it have leaders and arrows like 2DText?

Basically Sketchup::Text is actually a Dimension Callout, and really
doesn't have much other use. (If we want to display a textnote on the
viewport we use Model.add_note instead.)

3DText I use for any text (flat or otherwise,) that needs to have a 3D
location, and stay oriented to the model, not the viewport.

In the Windows Registry there are 2 Keys, one 'TextStyle' (which I
think is for 2DText, and is empty of attributes;) and 'ThreeDText'
which holds the settings from the 3DText Edit dialog.
I'm wondering why there are no Options to do with Text settings in the
OptionsManager/OptionsProvider Interfaces?
The Text Settings get saved in the Model... but it would be nice to
have a global override saved in the Registry.

David Tuška

unread,
Feb 22, 2010, 4:04:44 AM2/22/10
to Google SketchUp Developers - SketchUp Ruby API
What is the "no easy solution via Instance Methods" ??,
you find the way to change this attribute
(:fontface, :fontsize, :bold, :italic, :align, :color) ?

I'm need change other 'hidden' attribute, which is not documented in
APi :(

Dan Rathbun

unread,
Feb 22, 2010, 6:54:52 AM2/22/10
to Google SketchUp Developers - SketchUp Ruby API
On Feb 22, 4:04 am, David Tuška wrote:
> What is the "no easy solution via Instance Methods" ??,

The API does NOT define Instance Methods to change Text attributes.

> you find the way to change this attribute
> (:fontface, :fontsize, :bold, :italic, :align, :color) ?

Those names are 'common' names I suggest, but NOT what the attribute
names may be in the C code of Sketchup.

> I'm need change other 'hidden' attribute, which is not documented in
> APi :(

ALL subclasses of DrawingElement class, inherit methods to access
attributes: 'hidden', 'visible', 'casts_shadows', 'receives_shadows',
'layer'
http://code.google.com/apis/sketchup/docs/ourdoc/drawingelement.html

.

Dan Rathbun

unread,
Feb 22, 2010, 8:58:13 AM2/22/10
to Google SketchUp Developers - SketchUp Ruby API
On Feb 22, 4:04 am, David Tuška wrote:

> I'm need change other 'hidden' attribute, which is not documented in
> APi :(

[Czech]
ALL podtřídy třídy DrawingElement, dědí metody přístupu
atributy:


'hidden', 'visible', 'casts_shadows', 'receives_shadows', 'layer'
http://code.google.com/apis/sketchup/docs/ourdoc/drawingelement.html

(...translated with Google Translate:
http://translate.google.com/?hl=en&tab=wT#en|cs| )
.

Sannerwind

unread,
Jul 31, 2017, 8:08:44 PM7/31/17
to SketchUp Ruby API
Thanx to all.
Can some expert please give me a full example using
Sketchup::Text attribute (:fontface, :fontsize, :bold, :italic, :align, :color)
with all the arguments filled in. Perhaps with [a,b,c..]  where are common choices;  SU seems to balk
THx in advance

Also an example to open and list the attribute dictionaries this type of method 
Reply all
Reply to author
Forward
0 new messages