GetName
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/08/2008 at 11:14, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 10
Platform: Windows ;
Language(s) : C++ ;---------
Hi,
i've tried to write a plugin for cinema 4d, which exports the names and types of the objects. But anyway, i can't get valid names from the objects. I hope the mistake is not too noobish and i'm very thankfully for everybody who knows the solution or may help me. Thx, Firefly
LONG StrikeSaverData::Save(PluginSceneSaver *node, const Filename &name, BaseDocument *doc, LONG filterflags)
{
if(!(filterflags & SCENEFILTER_OBJECTS))return FILEERROR_NONE;
if(!doc)return FILEERROR_MEMORY;
file = BaseFile::Alloc();
file->Open(name, GE_WRITE);
BaseObject *pObject = NULL;
pObject = doc->GetFirstObject();
if(!pObject)return FILEERROR_NONE;
while(pObject)
{
if(!pObject->GetName().Content())file->WriteString("no name there...");
else file->WriteString(pObject->GetName());
pObject = pObject->GetNext();
}
file->Close();
return file->GetError();
} -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/08/2008 at 15:41, xxxxxxxx wrote:
Remember that the objects in the Object Manager are not a linear list but a tree hierarchy. In other words, objects can be children and have parents so you'll want to do a recursive function to traverse the tree:
// First call to get it started
TraverseObjects(doc->GetFirstObject());//*---------------------------------------------------------------------------*
void TraverseObjects(BaseObject* obj)
//*---------------------------------------------------------------------------*
{
for (; obj; obj = obj->GetNext())
{
// Do your thing here (write the string to file)
// This traverses the children
if (obj->GetDown()) TraverseObjects(obj->GetDown());
}
}Also realize that WriteString() writes a Cinema 4D String to file and not a plain text string. To do the latter, set up a char buffer into which to extract the String characters and use WriteBytes() instead.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/08/2008 at 04:33, xxxxxxxx wrote:
I've implemented such an function but when i test this version with a separate recursive function, cinema 4d leaves me with an error. I've then implemented a version, where file writes directly an C-String with writebytes,
but the result in the written file is none.
Here the code:
if(!(filterflags & SCENEFILTER_OBJECTS))return FILEERROR_NONE;
if(!doc)return FILEERROR_MEMORY;
file = BaseFile::Alloc();
file->Open(name, GE_WRITE);
BaseObject *pObject = NULL;
pObject = doc->GetFirstObject();
if(!pObject)return FILEERROR_NONE;
while(pObject)
{
CHAR acName[256];
//
for(int i = 0; i < 256; i++)acName[i] = 0;
pObject->GetName().GetCString(acName, 254, St7bit);
file->WriteBytes((void* )&acName, 256);
pObject = pObject->GetNext();
}
file->Close();
return file->GetError(); -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/08/2008 at 05:34, xxxxxxxx wrote:
Here is a function I wrote some time ago to write strings to a file.
>
\> Bool WriteString(const String line, BaseFile\* file) \> { \> if(!file) return FALSE; \> \> CHAR \*charline = NULL; \> LONG strlength = line.GetCStringLen(St7bithex); \> charline = (CHAR\* )GeAlloc(strlength+1); \> \> if(!charline) return FALSE; \> \> strlength = line.GetCString(charline, strlength+1, St7bithex); \> \> LONG i; \> for(i=0; i<strlength; i++) \> { \> if(!file->WriteChar(charline[i])) return FALSE; \> } \> \> GeFree(charline); \> \> return TRUE; \> } \>
cheers,
Matthias -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/08/2008 at 10:18, xxxxxxxx wrote:
What kind of error? I have a dozen or so recursive methods like this in my plugin and haven't had an 'error' in years. So it isn't the recursion. Maybe you didn't send the BaseFile* as an argument and it would not compile?
Also, you shouldn't write the ENTIRE buffer. The result of GetCString() is a null-terminated C/C++ string. Only write this, not the whole thing (as Matthias does). I don't use the WriteChar() for my string write routine instead using WriteBytes(). Either is sufficient. Note the similarities? I'm using a static buffer and only resort to further allocations if the string length exceeds it (very rarely if ever).
>
// CreateMorphs.Write - Write to file \> //\*---------------------------------------------------------------------------\* \> Bool CreateMorphs::Write(BaseFile\* bfile, const String& str) \> //\*---------------------------------------------------------------------------\* \> { \> LONG strLen; \> BOOL retval = FALSE; \> LONG len = str.GetCStringLen()+1L; \> if (len > 4096L) \> { \> CHAR\* buffer = (CHAR\* )GeAlloc(len); \> if (buffer) \> { \> strLen = str.GetCString(buffer, len); \> if (strLen) retval = bfile->WriteBytes(buffer, strLen); \> GeFree(buffer); \> } \> else ErrorException::Throw(EE_NODIALOG, GeLoadString(IPPERR_MEMORY_TEXT), "CreateMorphs.Write.buffer"); \> } \> else \> { \> strLen = str.GetCString(&strBuf;[0], len); \> if (strLen) retval = bfile->WriteBytes(&strBuf;[0], strLen); \> } \> return retval; \> }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/08/2008 at 10:25, xxxxxxxx wrote:
Before jumping right into the file write, you should do a test with GePrint() and see what shows in the Console window. That would eliminate or uncover one problem (the object names from GetName()). This should work - again, I've never had any problem with GetName() in many years.
1. Make sure that your build settings were from the 'cinemasdk' project that comes with Cinema 4D (in the plugins folder) and that you're building against the api.lib build that matches (debug vs release vs intel).
2. Make sure that you are using 10.102/.111 and not 10.008. You're just asking for trouble with 10.008.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/08/2008 at 11:17, xxxxxxxx wrote:
okay...thx for all replies. I've updated my cinema and now it works.