Jump to content

Python: paste relative references (for ramp)


JJ FX

Recommended Posts

Hi, 

So I cannot figure out how with python create a relative referenced ramp. The closest I got is to this:

# pseudocode

controller = 'my_controller_node'
target = 'polyextrude_node'
path = target.relativePathTo(controller) # or the other way around

controllerRamp = controller.parm('thicknessramp')
targetRamp = target.parm('thicknessramp')

# store the current ramp:
keys = targetRamp.evalAsRamp().keys()
values = targetRamp.evalAsRamp().values()

# set the expression on the thicknessramp parameter
expression = 'ch("' + path + '/' + controllerRamp.name() + '")'
targetRamp.setExpression(expression)

# now the ramp is all broken, so I'm restoring the control points and give them expressions too
for i in range(len(keys)):
    key = targetRamp.name() + str(i+1) + 'pos'
    value = targetRamp.name() + str(i+1) + 'value'
    interp = targetRamp.name() + str(i+1) + 'interp'

    # set the keys, values and interpolations
    controller.parm(key).set(keys[i])
    controller.parm(value).set(values[i])
    controller.parm(interp).set(2)
    
    # and finally expressions
    expression = 'ch("' + path + '/' + key + '")'
    target.parm(key).setExpression(expression)
    expression = 'ch("' + path + '/' + value + '")'
    target.parm(value).setExpression(expression)
    expression = 'ch("' + path + '/' + interp + '")'
    target.parm(interp).setExpression(expression)


So this works fine as long I don't add new points to the controller node. Then ofcourse ramp creates new parameter names 'parmname15pos' etc... So the whole thing is not working properly.

This seams to be quite overengineered already... What am I missing that I have to use to do the copy / paste relative references for a ramp parameter?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...