Copying individual models to new documents
-
On 17/01/2014 at 07:55, xxxxxxxx wrote:
Hi - I'm having a bit of trouble with a script I am working on. I have a file with 100 models in it and I want a script that will copy each individual model and place it in its own new document. I've grabbed a list of the models and then tried to use a loop to pull each model out and insert it into a new document. I keep getting an "AssertionError: Found next objects. Please add them separately." If I don't try to pull models from the list and instead create a new cube object in the same loop it works.
For testing purposes I created a new document and put 3 cube objects in it with unique names (1, 2, 3) so I can tell them apart as the script runs.
The script is a work in progress but this is where I'm stuck at the moment.
Any help would be appreciated.
import c4d
from c4d import gui
from c4d import documentsdef main() : models = doc.GetObjects()#get list of models in document for i in (models) : #obj = c4d.BaseObject(c4d.Ocube) obj = i newDoc = c4d.documents.BaseDocument() #Initialize a new base document newDoc.SetDocumentName("MyNewDoc") #set the name of the new document c4d.documents.InsertBaseDocument(newDoc) #makes the document visible in the editor newDoc.InsertObject(obj) c4d.EventAdd() if __name__=='__main__': main()
-
On 17/01/2014 at 11:27, xxxxxxxx wrote:
I tried reducing my project to one model in the object manager and then the script works. Why would it work with one item but not more than one?
-
On 17/01/2014 at 11:40, xxxxxxxx wrote:
You should remove the object from the old document before inserting it into the new one.
-
On 17/01/2014 at 11:44, xxxxxxxx wrote:
I'll give that a try.
Is there a way to make a copy of the object rather than using the original? I would prefer not to alter the original project if possible.
-
On 17/01/2014 at 11:53, xxxxxxxx wrote:
BaseList2D.GetClone(), see the API reference
-
On 17/01/2014 at 11:59, xxxxxxxx wrote:
I appreciate your help but I was unable to find that function in the sdk documentation. I looked in the BaseList2D section and came up with nothing so I tried using the search feature and it couldn't be found. May I ask where did you find it?
thanks again for your help.
-
On 17/01/2014 at 12:10, xxxxxxxx wrote:
My fault, sorry.
It's in the C4DAtom class.Best,
-Niklas -
On 17/01/2014 at 12:12, xxxxxxxx wrote:
I had seen that one but I'm a little fuzzy on the Atom class. I'll see what I can figure out.
I tried removing the object like you suggested and the script is now functioning. If I can't get the cloning aspect to work I'll at least have something working even if it isn't ideal.
Thank you.
-
On 17/01/2014 at 12:16, xxxxxxxx wrote:
You would not even need to look up the function, just give it a try already.
>
> import c4d
>
> def main() :
> for op in doc.GetObjects() :
> newDoc = c4d.documents.BaseDocument()
> newDoc.SetDocumentName(op.GetName())
> c4d.documents.InsertBaseDocument(newDoc)
> newDoc.InsertObject(op.GetClone())
>
> main() -
On 17/01/2014 at 12:27, xxxxxxxx wrote:
Niklas - that is sooooo much more streamlined than what I have right now. I hope to be as skilled with this at some point. I was on the right path but I'm using more variables instead of just putting the methods right into the functions.
If I understand this correctly I can use functions from higher up in the hierarchy and apply them to the lower class object as if it were documented that way? (as if the clone command was listed down the hierarchy with the rest of the object commands)
Can we use our MSA training for Python?
-
On 17/01/2014 at 14:19, xxxxxxxx wrote:
Everything is working from the model standpoint but the textures don't follow. I've created a script that identifies which of the objects tags are textures and then gets the associated material and transfers it to the new project but the texture tags still come up with question marks in them for missing textures. Am I missing something or do I need to continue scripting to associate the material with the texture again?