Is there a screen text method?


#1

Hi all,
I need to export the name of the scene when I export an image and I dont’ find add_screen_text function:
Is there a screen text api ? (text fixed on the screen)
I tried “ad_text” but the function need the point.
Best regards !


draw_text - not displaying text?
#2

why not add it to the filename?

    title = Sketchup.active_model.title
    pages = Sketchup.active_model.pages
    if not pages.length == 0
          name = pages.selected_page.name.gsub(/[\s\[\]\{\}\(\)\/\\\<\>]/,"_")
          # deal with pages by appending name to title...
          title = title + '_' + name
    end

then use title in your image export code…


#3

there is also

     model = Sketchup.active_model
 # Add a note 1/10 ways down the screen and 1/10 ways right from the
 # upper left corner of model window.
 note = Sketchup.active_model.add_note('Hello World', 0.1, 0.1)

so you could combine the to and add the name to the screen note…


#4

Any technique you use to display text on the screen is going to need to know where to place it! view#draw_text is an alternative that ties the location to the viewport, not to the model.


#5

@slbaumgartner,
Steve, does text written to view show in ‘export’ of an image?
john


#6

Maybe - but on rechecking, it isn’t of much use anyway because it is one of those poorly documented API methods that only works from within the draw method of a Tool.


#7

that also crossed my mind, bit of a pain just to tag an image…


#8

If @denis_bolomier needs a visible, on-image label, add_note may be the best existing alternative. The “note” it creates is actually a special Text Entity that is fixed at a screen location. It doesn’t need to be in a Tool draw method.


#9

… and he needs to add each note to a scene specific layer, as I explained in “Adding text to a scene”, via the manual tool:


#10

Thanks all !
I was looking into entities documentation. Tehe following code need to be complete but works for me.

  def createOrUpadteNote(newName)
    entities = @model.entities
    textes = entities.grep(Sketchup::Text)
    if textes.length > 0
      textes.first.text = (createOrUpadteNote)
    else
      @model.add_note(createOrUpadteNote, 0.1, 0.1)
    end
  end

#11

Don’t you want newName not createOrUpadteNote in the two places where you set the text? As written, you have an endless recursion. Also, you have a built-in assumption that the only reason there will be any Text Entities in the model is that you have added them as notes.


#12
if text_obj.point.nil? && !text_obj.has_leader? 

ADD:

More on the eccentricities of view anchored Text notes:
http://forums.sketchup.com/t/ruby-api-documentation-errors-suggestions/10958/7
and
http://forums.sketchup.com/t/ruby-api-documentation-errors-suggestions/10958/9


#13

Yes it’s a mistake due to translation “createOrUpadteNote” should be replace by “newName”

and
if text_obj.point.nil? && !text_obj.has_leader? is better