delete and update add_note don't work

delete and update add_note don't work

Postby mr_Creator » Fri Aug 21, 2020 9:20 pm

Hello,
I create note:
Code: Select all
@note = Sketchup.active_model.add_note 'Note', 0.8, 0.9

But I cannot delete and change the note. Help please, I used different methods, but none helped.
0

mr_Creator 
 

Re: delete and update add_note don't work

Postby dezmo » Sat Aug 22, 2020 4:43 pm

Code: Select all
@note = Sketchup.active_model.add_note 'Note', 0.8, 0.9

You may realised that is creating Sketchup::Text https://ruby.sketchup.com/Sketchup/Text.html
To change:
Code: Select all
@note.set_text "This is another note"

Most probably to see changes, the view need to redraw.
Code: Select all
Sketchup.active_model.active_view.invalidate

do delete:
Code: Select all
@note.erase!
1
Man can do everything. Only a matter of time and money.

dezmo 
 

Re: delete and update add_note don't work

Postby mr_Creator » Sat Aug 22, 2020 8:37 pm

dezmo wrote:
Code: Select all
@note = Sketchup.active_model.add_note 'Note', 0.8, 0.9

You may realised that is creating Sketchup::Text https://ruby.sketchup.com/Sketchup/Text.html
To change:
Code: Select all
@note.set_text "This is another note"

Most probably to see changes, the view need to redraw.
Code: Select all
Sketchup.active_model.active_view.invalidate

do delete:
Code: Select all
@note.erase!

When i use:
Code: Select all
@note.set_text "This is another note"
Sketchup.active_model.active_view.invalidate

then I get this (check image)

the text is superimposed on each other. Sketchup 2020
0

mr_Creator 
 

Re: delete and update add_note don't work

Postby dezmo » Sun Aug 23, 2020 1:30 pm

mr_Creator wrote:When i use:
Code: Select all
@note.set_text "This is another note"
Sketchup.active_model.active_view.invalidate



You didn't say what you did before.
I guess you actually did something like this:
Code: Select all
@note = Sketchup.active_model.add_note 'Note', 0.8, 0.9
@note = Sketchup.active_model.add_note 'Note', 0.8, 0.9
@note.set_text "This is another note"
Sketchup.active_model.active_view.invalidate


If you can tell me what your goal is at all, I might be better able to suggest something... ;)
0
Man can do everything. Only a matter of time and money.

dezmo 
 

Re: delete and update add_note don't work

Postby TIG » Sun Aug 23, 2020 1:50 pm

The bare bones code is:
Code: Select all
note=Sketchup.active_model.add_note("The initial note", 0.8, 0.9)
### where 'note' is a reference to that newly made text-entity
Sketchup.active_model.active_view.invalidate
### refreshes the view
later on you can use
Code: Select all
note.text="This is the changed note"
Sketchup.active_model.active_view.invalidate

The @note would only apply if you are reusing variables between methods etc.
Also the set_text(...) method operates outside of the undo-stack, whereas the text= works within it.
Also, please parenthesize your arguments...
To erase the note use note.erase!
0
TIG
User avatar
TIG 
Global Moderator
 

Re: delete and update add_note don't work

Postby Dan Rathbun » Sat Oct 17, 2020 2:20 pm

Just tested Sketchup::Text#set_text on SU2020 and it (as Dezmo says) does not display the change until the view is redrawn. So Sketchup.active_model.active_view.invalidate is necessary to see the change.

I'll open a documentation issue for this "quirk".
1
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    SketchUcation One-Liner Adverts

    by Ad Machine » 5 minutes ago



    Ad Machine 
    Robot
     



     

    Return to Developers' Forum

    Who is online

    Users browsing this forum: matarazzodesign and 18 guests

    Visit our sponsors: