diff options
author | Ken Hughes <khughes@pacific.edu> | 2007-03-29 08:55:29 +0400 |
---|---|---|
committer | Ken Hughes <khughes@pacific.edu> | 2007-03-29 08:55:29 +0400 |
commit | b8e425af7c24ee24ee43205b0ce6e66e6a6a0c22 (patch) | |
tree | 7a61333dbc47eaa5c9d9bc53dd8d3b1309bf7900 /source/blender/python | |
parent | 42fa2ba00b4c5dc2427be616d64d30eaaab433f5 (diff) |
Revisions to previous change of new_id().
Note: the intent of the original modification (and these updates) is not to
change how new_id() functions. What has been done is to pull out the code
which calculates a new name for an ID in the case of duplicate, as would
happen when you copy any datablock, into a separate function. This code is
necessary in the new Python Library module, since it otherwise is extremely
difficult to locate a new datablock appended from a library. new_id() calls
this separate function to generate a name for the new ID if necessary, just
as it previously did.
To make the purpose of this new function clearer, I renamed it
check_for_dupid() and added more extensive comments. I repeat, it's not
meant to be a substitute for new_id().
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/api2_2x/Library.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/source/blender/python/api2_2x/Library.c b/source/blender/python/api2_2x/Library.c index 4251b83585d..5251f405ff5 100644 --- a/source/blender/python/api2_2x/Library.c +++ b/source/blender/python/api2_2x/Library.c @@ -570,12 +570,12 @@ PyObject *LibraryData_importLibData( BPy_LibraryData *self, char *name, int mode, Scene *scene ) { char longFilename[FILE_MAX]; - char *finalName; BlendHandle *openlib; Library *lib; LinkNode *names, *ptr; ID idtest, *id; ListBase *lb; + char newName[32]; /* try to open the library */ openlib = open_library( self->filename, longFilename ); @@ -603,16 +603,11 @@ PyObject *LibraryData_importLibData( BPy_LibraryData *self, char *name, * be renamed to. */ - if( mode == FILE_LINK ) - finalName = name; - else { /* for appends, build a fake ID block, then try to dup it */ - strncpy( idtest.name+2, name, strlen(name)+1 ); - *((short *)&idtest.name) = self->type; - idtest.newid = NULL; - idtest.lib = NULL; - dup_id( NULL, &idtest, self->name ); - finalName = idtest.name+2; - } + strncpy( newName, name, strlen(name)+1 ); + + /* for appends, see what new block will be called */ + if( mode != FILE_LINK ) + check_for_dupid( wich_libbase(G.main, self->type), NULL, newName ); /* import from the libary */ BLO_script_library_append( openlib, longFilename, name, self->type, mode, @@ -642,8 +637,8 @@ PyObject *LibraryData_importLibData( BPy_LibraryData *self, char *name, * otherwise it's NULL. */ for( id = lb->first; id; id = id->next ) { - if( id->lib == lib && id->name[2]==finalName[0] && - strcmp(id->name+2, finalName)==0 ) + if( id->lib == lib && id->name[2]==newName[0] && + strcmp(id->name+2, newName)==0 ) return GetPyObjectFromID( id ); } |