Jump to content
Sign in to follow this  
Fastbee

Objects on surface noob scripting

Recommended Posts

I was looking around for a plugin or something to place one object on the surface of another object.  I ran across a plugin called Target4D and also a way to do it myself.  To do it myself you put a Constraint on the object to be placed on the surface and set it to Clamp, To Surface, As Normal, pick the target for it to be placed on and set the Distance to 0.  This seemed pretty great to me, but doing that everytime can be tedious with a lot of objects.  How would I go about writing a script to do these steps for every object selected?

Share this post


Link to post
Share on other sites

Simply copy what is echoed in script log - this creates a tag on the object with all you need and only target object has to be loaded.

 

import c4d
from c4d import documents, plugins
#Welcome to the world of Python

def main():
    def tool():
        return plugins.FindPlugin(doc.GetAction(), c4d.PLUGINTYPE_TOOL)

    def object():
        return doc.GetActiveObject()

    def tag():
        return doc.GetActiveTag()

    def renderdata():
        return doc.GetActiveRenderData()

    def prefs(id):
        return plugins.FindPlugin(id, c4d.PLUGINTYPE_PREFS)

    c4d.CallCommand(100004788, 50032) # New Tag
    tag()[c4d.ID_CA_CONSTRAINT_TAG_CLAMP] = True
    tag()[50004,9] = 0
    tag()[50004,1] = 4
    tag()[50004,10] = True


if __name__=='__main__':
    main()
    c4d.EventAdd()

 


Free C4D trainings from MAXON professional on our youtube channel

 

https://www.youtube.com/c4dcafe

Share this post


Link to post
Share on other sites

This script is probably perfect, but you could also just copy the tag to the new object.  Or better yet, make all your desired objects children of an object with the Constraint tag, then right click on the tag> Copy Tag to Children.

Share this post


Link to post
Share on other sites
  • Topic Author
  • The copy tag thing occured to me, but hitting a button and having everything happen seems so much cooler.

     

    Thank you @HSrdelic

    That script log thing is cool.  Makes me feel like I know how to script.  :wackywink:

     

    The script works great when one object is selected.  When multiple objects are selected it does not put the settings on the Constraint object like setting it to Clamp and the other things. 

    Is it also possible to have it automatically initiate the object to be targeted picker?

    Is there a command to have it delete specifically the constraint tag on selected objects?

    Share this post


    Link to post
    Share on other sites

    Everything is possible, but this requires a bit of digging in python SDK...

     

    https://developers.maxon.net/docs/Cinema4DPythonSDK/html/index.html


    Free C4D trainings from MAXON professional on our youtube channel

     

    https://www.youtube.com/c4dcafe

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • Thank you HSrdelic.  I guess it's not such a noob scripting thing.  One day I might dig into some programming in c4d.

    Share this post


    Link to post
    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.

    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.

    Latest Topics

    Latest Comments

    ×
    ×
    • Create New...