Jump to content
Sign in to follow this  
robinnasif

Link parameters using python

Recommended Posts

Hi,

Is it possible to link parameter of two objects using python? Same as like 'Set Driver', 'Set Driven' in XPresso. If it is possible please help me out. I don't know much about python.

 

Thanks

Share this post


Link to post

Sure is... use a Python tag, search for the "other" object, assign parameter values from the other object to the tag's object... simple, but you will need at least a little Python knowledge. (Also, you need to look out for priorities; the source object needs to be evaluated before the tag.)

 

Here's some simple code that connects the y position of the tag's object (a sphere, but it doesn't really matter) to another object called "Cube". Move Cube and Sphere will follow in y direction with an offset of 200 units.

import c4d

def main():
    myCube = doc.SearchObject("Cube")
    mySphere = op.GetObject()
    if myCube == None or mySphere == None: return
    mySphere[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y] = myCube[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y] + 200.0

For the parameters, just use drag and drop of a label into the Python console.

 

----------
Learn more about Python for C4D scripting:
https://www.patreon.com/cairyn

 

Share this post


Link to post
  • Topic Author
  • Author of the topic Posted

    Many many thanks for your support. 

    Share this post


    Link to post
  • Topic Author
  • Author of the topic Posted

    I have another question. how can i gray out or lock a user data field?

    gray out.png

    Share this post


    Link to post

    To retrieve the actual descriptions for the user data, you can use GetUserDataContainer() on the object.

    However, with not much knowledge of Python and probably not much knowledge of the C4D API, this is quite a challenging task for you.

    You need to know about BaseContainer, DescID, DynamicDescription and other foundational concepts. I don't have a simple one-liner that would change the status of a user data field.

    Share this post


    Link to post
  • Topic Author
  • Author of the topic Posted

    Thanks a lot. i have already figure it out.

     

    import c4d
    from c4d import gui

     

    obj = op.GetObject()
    UD = obj.GetUserDataContainer()

    def main():

        mode = 1
        randomPoint = 2
        Field = 3


        for descId, container in UD:
            theID = descId[1].id
            if theID == randomPoint:


                if obj[c4d.ID_USERDATA, mode] == 0:
                    container[c4d.DESC_HIDE] = False
                    obj.SetUserDataContainer(descId, container)

                
                if obj[c4d.ID_USERDATA, mode] == 1:
                    container[c4d.DESC_HIDE] = True
                    obj.SetUserDataContainer(descId, container)

          
            if theID == Field:

          
                if obj[c4d.ID_USERDATA, mode] == 1:
                    container[c4d.DESC_HIDE] = False
                    obj.SetUserDataContainer(descId, container)

            
                if obj[c4d.ID_USERDATA, mode] == 0:
                    container[c4d.DESC_HIDE] = True
                    obj.SetUserDataContainer(descId, container)

    Share this post


    Link to post

    Great. So, you know more about Python than you gave yourself credit for 😁

    Share this post


    Link to post
  • Topic Author
  • Author of the topic Posted

    i am new in python and learning by myself. If you have any suggestion please help me out.

     

    Thanks 

    Share this post


    Link to post

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    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.

    Sign in to follow this  

    • Recently Browsing   0 members

      No registered users viewing this page.

    ×
    ×
    • Create New...

    FORUMS INFO:

    Dear members, we are aware of few more bugs that are still present withing the theme.We just wanted to let you know that we are working to fix them as soon as possible.
     

    NEW MEMBERS:

    Please be aware that we are manually approving all new registrations, due to spam prevention. Please be patient in case you cannot login right away, we will approve you within 12h or less if we decide you are not potential spammer. 

     

    Thanks for understanding! :cowboypistol: