A new version of Cineversity has been launched. This legacy site and its tutorials will remain accessible for a limited transition period

Visit the New Cineversity
   
 
Python Newbie Question. How to select an object from the object manager?
Posted: 20 November 2012 04:22 PM   [ Ignore ]  
Total Posts:  2
Joined  2012-11-16

Hi Guys,

I’m getting into python, I’ve watched and read every tutorial I could so far, and managed to create and edit simple objects etc…
What I would like to do is to select (make active) a certain object from the object manager.

Something like..

I have a cube object called “part one” that is not selected.

How can I tell through scripting to make that certain object selected ?

I’ve tried a bunch of different things but no success so far.

Thanks!
Raul

Profile
 
 
Posted: 20 November 2012 06:14 PM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
Total Posts:  365
Joined  2006-05-17

Hi Raul,

If you are using a set naming convention you can go for “BaseDocument.SearchObject(name)”

you then need to find the selection functions:
BaseDocument.SetSelection(bl[, mode=SELECTION_NEW])
These are the option you can use for the selection
The selection mode:
SELECTION_NEW   Starts a new selection.
SELECTION_ADD   Adds to the current selection
SELECTION_SUB   Subtracts from the current selection.

so then you can write it out like this:

  name = “Part One” #defines the name that you would like to search for
  if doc.SearchObject(name) == None: return #if the object that you are looking for is not found return
  obj = doc.SearchObject(name) #set the object as a variable
  doc.SetSelection(obj, mode=c4d.SELECTION_NEW) #now pass that object through to the selection function, in this case a NEW selection is created.
  c4d.EventAdd() #refresh the scene.

Profile
 
 
Posted: 20 November 2012 06:52 PM   [ Ignore ]   [ # 2 ]  
Total Posts:  2
Joined  2012-11-16

Hi Patrick!

Works like a charm wink
Many Tks!

Profile