Simple Scripting Question

34 views
Skip to first unread message

Tim Fuller

unread,
Jul 31, 2015, 10:04:36 AM7/31/15
to leo-editor
Hello All,

I've recently discovered Leo and really loving it.  I am trying to get into the scripting but I'm having trouble doing a simple operation.  Could someone please help me out or point me to the documentation that would lead to the answer?

I'm wanting to write a simple script that would take the highlighted node and clone it to an action item list.  

So, I'm wanting to clone a node as a child to ActionItems.  I've gotten as far as tmpNode = c.p.clone()  And tmpNode.paste() works exactly as expected.  I just can't figure out how to dictate where to paste it.

Thanks

Edward K. Ream

unread,
Jul 31, 2015, 10:11:13 AM7/31/15
to leo-editor

​Let p = tmpNode Try p.moveToLastChildOf(​ActionItems) or p.moveToNthChildOf(ActionItems, n)

You must also do a c.redraw() to make the change visible.

If you use the standard nomenclature (p, p2) etc, you can use typing completion (Alt-1) to discover appropriate methods.

Edward

Edward K. Ream

unread,
Jul 31, 2015, 10:19:41 AM7/31/15
to leo-editor, tful...@gmail.com

On Friday, July 31, 2015 at 9:04:36 AM UTC-5, Tim Fuller wrote:

I am trying to get into the scripting but I'm having trouble doing a simple operation.  Could someone please help me out or point me to the documentation that would lead to the answer?

Tim Fuller

unread,
Jul 31, 2015, 12:01:15 PM7/31/15
to leo-editor, tful...@gmail.com, edre...@gmail.com
Thank you very much for the quick reply.  I'm feeling quite dumb right now as I'm still unable to get this to work.  I have the following script:


p = c.p.clone()


p.moveToLastChildOf(ActionItems)


c.redraw()


But it only pastes the clone directly underneath the current.  I get an error in the log stating.  

exception executing script
NameError: name 'ActionItems' is not defined

Can I not call a Node directly by it's name?  Or have I done something else incorrectly?

Thank you

Jacob Peck

unread,
Jul 31, 2015, 12:37:44 PM7/31/15
to leo-e...@googlegroups.com
Try this:

----
p = c.p.clone()
dest = g.findNodeAnywhere(c,'ActionItems')
p.moveToLastChildOf(dest)
c.redraw()
---

moveToLastChildOf is expecting a position, not a name. :)

Hope this helps,
-->Jake
--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+...@googlegroups.com.
To post to this group, send email to leo-e...@googlegroups.com.
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Terry Brown

unread,
Jul 31, 2015, 12:42:47 PM7/31/15
to leo-e...@googlegroups.com
On Fri, 31 Jul 2015 09:01:15 -0700 (PDT)
Tim Fuller <tful...@gmail.com> wrote:

> p.moveToLastChildOf(ActionItems)

p.moveToLastChildOf(g.findNodeAnywhere(c, 'ActionItems'))

is probably what you want. 'ActionItems' is a str(ing) literal, whereas
ActionItems is an undefined variable.

Cheers -Terry

Tim Fuller

unread,
Jul 31, 2015, 1:53:29 PM7/31/15
to leo-editor, tful...@gmail.com
Thanks everybody, I got it working.  Starting to wrap my head around how all this works.  I appreciate all the help.

Terry Brown

unread,
Jul 31, 2015, 2:14:07 PM7/31/15
to leo-e...@googlegroups.com
On Fri, 31 Jul 2015 10:53:29 -0700 (PDT)
Tim Fuller <tful...@gmail.com> wrote:

> Thanks everybody, I got it working. Starting to wrap my head around
> how all this works. I appreciate all the help.

Good. Although working out how to code these things yourself is far
more valuable than using plugins :-) I'll just point out that the
quick_move plugin and make transient or permanent buttons which copy /
clone / move the current node to designated places.

Cheers -Terry

Tim Fuller

unread,
Jul 31, 2015, 5:47:06 PM7/31/15
to leo-editor
Thanks again. Super impressed with the community here.
Reply all
Reply to author
Forward
0 new messages