Is there a screen text method?

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 !

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…

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…

1 Like

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.

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

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.

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

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.

… 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:

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

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.

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

ADD:

More on the eccentricities of view anchored Text notes:
Ruby API Documentation - Errors & Suggestions - #7 by slbaumgartner
and
Ruby API Documentation - Errors & Suggestions - #9 by DanRathbun

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