Jump to content

thunderdoc

Put multiple objects selected under null

Recommended Posts

Hi, I'm starting to learn Python inside C4D and got some exciting progress, but I'm struggling with a small detail.

 

It's a simple script to create a null object and then move the selected objects under the null. The null object has its visibility in viewport and render turned off.

it does work well when selecting one object and running the script, but when I select more than one object and try to run, the script return an error.

 

Here's a GIF showing what happens:

HTqZCID.gif

 

I suspect I have to create a list of the selected objects and for each of the selected objects I should to assign a InsertUnder command, but I'm not getting how it could be done or if it's the solution.

 

Here's the code, I suspect the error is in the line 27 / 28.

 

import c4d


def checknull():
    nullexist = doc.SearchObject('FD Backup')
    if nullexist == None:
        insertfdbackupnull()



def insertfdbackupnull():
    fdbackup = c4d.BaseObject(c4d.Onull) #Assign the FDBackup null object to a name: fdbackup.
    doc.InsertObject(fdbackup) #inset the FDBackup null object in the current document.
    fdbackupcolor = c4d.Vector(0.875, 0.2461, 0.3203) #The color of the FDBackup null object
    fdbackup[c4d.ID_BASELIST_NAME]='FD Backup' #Rename the FDBackup null Object.
    fdbackup[c4d.ID_BASEOBJECT_VISIBILITY_EDITOR]=1 #Set the viewport visibility of the FDBackup null object to off.
    fdbackup[c4d.ID_BASEOBJECT_VISIBILITY_RENDER]=1 #Set the render visibility of the FDBackup null object to off.
    fdbackup[c4d.ID_BASEOBJECT_USECOLOR]=2 #Enable FDBackup null color.
    fdbackup[c4d.NULLOBJECT_ICONCOL]=True #Enable FDBackup null icon color.
    fdbackup[c4d.ID_BASEOBJECT_COLOR]= fdbackupcolor


def tonull():
    nullexist = doc.SearchObject('FD Backup') #check if the FDBackup null object exists.
    if nullexist != None: #if the FDBackup null object is foundo, then...
        fdnull = doc.SearchObject('FD Backup') #get the FDBackup null object.
        objselected = doc.GetActiveObject() #get the active selected object
        objselected.InsertUnder(fdnull) #insert under the FBDackup null object.

if __name__=='__main__':
    checknull()
    tonull()
    c4d.EventAdd()

Error returned when selected more than one object:

Quote

Traceback (most recent call last):
  File "'scriptmanager'", line 32, in <module>
  File "'scriptmanager'", line 28, in tonull
AttributeError: 'NoneType' object has no attribute 'InsertUnder'

 

 

I have tried to change the lines 27 and 28 to the following, but no success...

        fdnull = doc.SearchObject('FD Backup') #get the FDBackup null object.
        objselected = doc.GetActiveObject() #get the active selected object
        for obj in objselected: #for each object selected
            objselected.InsertUnder(fdnull) #insert under the FBDackup null object.

error returned:

Quote

Traceback (most recent call last):
File "'scriptmanager'", line 33, in <module>
File "'scriptmanager'", line 29, in tonull
AttributeError: 'list' object has no attribute 'InsertUnder'

 

 

Does anyone have any hint of what is happening and how to solve it ?

 

 

 

 

 

Share this post


Link to post
Share on other sites

Only registered users can see replies - please register for full access!

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.


  • Recently Browsing   0 members

    No registered users viewing this page.

YOUTUBE CHANNEL:

ABOUT US:

C4D Cafe is the largest CINEMA 4D community. We provide facilities for discussion, showcasing and learning our favorite software :) Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, get your own private messenger, post status updates, manage your profile and much more. If you need to find solution to your problem or otherwise ask for help, Cafe is the right place.
×
×
  • Create New...