Thread: Python linking curves in text node

Reply to Thread
Results 1 to 8 of 8
  1. #1 Python linking curves in text node 
    Join Date
    Aug 2007
    Posts
    22
    Hi guys,

    Quick question, I'm 1 step away from completing this script I'm writing but I've hit a roadblock (I watch too much amazing race).

    To put it simply, I want to link data (from the CurveTool) into a text node's translate through Python, just like linking with TCL seems to do.

    Any ideas? I can get the data fine, and I can put it in there, but not the curve, never done this before in Python. Obviously need it to update if changed and stuff like that, just like if linked manually.

    I hope that is clear enough.

    I tried doing something along the lines of:
    trans = [parent.CurveTool2.autocropdata.x, parent.CurveTool2.autocropdata.y]
    text.knob('translate').setValue(trans)

    With 'trans' being the usual TCL expressions I'd normally add in x and y, but doing this in Python gives me an error.

    Thanks!

    Mick.
    Reply With Quote  

  2. #2  
    Join Date
    Sep 2004
    Posts
    1,202
    Not sure I got your point but maybe you could try using setExpression() instead.
    dg | ••• | imdb
    Reply With Quote  

  3. #3  
    Join Date
    Aug 2007
    Posts
    22
    An easier example:

    Lets say I created a crop node (Crop1), and set its boundaries.
    Then wanted create a Primatte node programmatically that has the same crop data in its own crop parameters as Crop1. So that whenever the Crop1's crop data is changed, Primatte1's crop data also changes, because its link via an expression, just like CTRL-dragging the little graph icon from one to another.

    How do I link the values from Crop1's crop data to Primatte1's crop data in the right fields using Python?

    I hope that makes more sense. All using Python by the way.
    Reply With Quote  

  4. #4  
    Join Date
    Sep 2004
    Posts
    1,202
    Like I said using the setExpression() instead of setValue() should do it.

    Try this:

    Code:
    crop = nuke.createNode('Crop', inpanel=False)
    crop['box'].setValue(0, 0)
    crop['box'].setValue(0, 1)
    crop['box'].setValue(100, 2)
    crop['box'].setValue(100, 3)
    crop['reformat'].setValue(True)
    
    primatte = nuke.createNode('Primatte', inpanel=True)
    primatte['crop'].setExpression(crop.name()+".box.x", 0)
    primatte['crop'].setExpression(crop.name()+".box.y", 1)
    primatte['crop'].setExpression(crop.name()+".box.r", 2)
    primatte['crop'].setExpression(crop.name()+".box.t", 3)
    dg | ••• | imdb
    Reply With Quote  

  5. #5  
    Join Date
    Aug 2007
    Posts
    22
    So close Diogo, you're my hero as always.

    Problem is, I'd like to put an expression in there that is offset. I assumed (wrongly) that I could just go:

    primatte['crop'].setExpression((crop.name()+".box.x")-100, 0)

    Or something along those lines. But I get an error:
    "TypeError: unsupported operand type(s) for -: 'str' and 'int'"

    Apologies if I'm making a horribly simple mistake here, I tried changing the types, but no go, and obviously can't minus 2 strings.

    Thanks for the help so far, I'm getting much much closer every line of code that works

    Mick.
    Reply With Quote  

  6. #6  
    Join Date
    Aug 2007
    Posts
    22
    Glad I apologised in there, because I fixed my own newbie mistake

    I feel like a boob.
    Reply With Quote  

  7. #7  
    Join Date
    Sep 2004
    Posts
    1,202
    Glad it worked

    Since in this case both nodes are linked you could very well just use primatte['crop'].setExpression("input.box.x-100") or whatever the contents of your expression might be. As long the setExpression() value is a string you will be fine.

    Even primatte['crop'].setExpression(crop.name()+".box.x"+str(-100), 0) would work, you just can't "join" strings and numeric values without converting the numeric values to a string beforehand.

    Code:
    offset = 25
    
    crop = nuke.createNode('Crop', inpanel=False)
    crop['box'].setValue(0, 0)
    crop['box'].setValue(0, 1)
    crop['box'].setValue(100, 2)
    crop['box'].setValue(100, 3)
    crop['reformat'].setValue(True)
    
    primatte = nuke.createNode('Primatte', inpanel=True)
    primatte['crop'].setExpression("input.box.x+"+str(offset), 0)
    primatte['crop'].setExpression("input.box.y+"+str(offset), 1)
    primatte['crop'].setExpression("input.box.r-"+str(offset), 2)
    primatte['crop'].setExpression("input.box.t-"+str(offset), 3)
    dg | ••• | imdb
    Reply With Quote  

  8. #8  
    Join Date
    Aug 2007
    Posts
    22
    Yep yep, all works thanks so much again Diogo.

    Though I left Nuke processing my script and it appears to have frozen at some point during the computing last night. Is there a Python equivalent to some kind of do events? I'm worried that I'm getting Nuke to do too many events after one another without allowing it time to think about it all. Or perhaps it just needs some waking up now and again.

    Any ideas?
    Reply With Quote  

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Nuke 5.1 v1 Released
    By shot_grable in forum NUKE from The Foundry
    Replies: 36
    Last Post: July 17th, 2010, 01:33 AM
  2. Text Node Expression Help
    By mclemens in forum NUKE from The Foundry
    Replies: 3
    Last Post: December 17th, 2008, 10:14 PM
  3. Add Channel in Shuffel Node with python
    By idioteque in forum NUKE from The Foundry
    Replies: 1
    Last Post: November 21st, 2008, 08:16 AM
  4. Adding parameter expression in TEXT Node
    By mclemens in forum NUKE from The Foundry
    Replies: 1
    Last Post: September 19th, 2008, 04:59 AM
  5. Multiple text sizes within 1 text node
    By Furnace in forum NUKE from The Foundry
    Replies: 3
    Last Post: June 29th, 2008, 07:15 PM
Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts