Community
FBX Forum
Welcome to Autodesk’s FBX Forums. Share your knowledge, ask questions, and explore popular FBX topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Specifying command line switches

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Bloodysoft
676 Views, 2 Replies

Specifying command line switches

Using the convertscene function, I want to specify the output format, rather than outputting every format.

The man states that it will try to determine the format from the files suffix, but that doesn't work, at least not in the samples.

The docs also state to use /dffFBX to specify the output format, but that as well does no good in this example.

 

I've tried setting the lFormat as a char* as well, but I receive internal errors that it doesn't match the SDK class of being an int.

 

By using this line:

int lFormat = lSdkManager->GetIOPluginRegistry()->FindWriterIDByDescription(argv[i*2+1]);

instead of:

int lFormat = lSdkManager->GetIOPluginRegistry()->FindWriterIDByDescription(lFileTypes[i*2+1]);

it outputs the file correctly, and only the format specified from command line, but also crashes the binary.

 

Any help would be appreciated.

Tags (2)
2 REPLIES 2
Message 2 of 3
Bloodysoft
in reply to: Bloodysoft

If anyone else is stumped over this like I was this morning. Here's the solution I found after trying a bazillion different symptoms.

 

// Retrieve the writer ID according to the description of file format.
int lFormat = lSdkManager->GetIOPluginRegistry()->FindWriterIDByDescription(argv[3]);
// Construct the output file name.
FBXSDK_strcpy(lNewFileName+lFileNameLength-4,60, argv[3]);

 

 

It works on Windows and Mac

and the syntax is the same but with the format as the third argument: ConvertScene box.fbx box.dae .dae

 

I'm only a few days into objective-C so hopefully next time I can figure it out faster, but instead of passing the allowed filetypes directly to the WriterID, we use a third argument from command-line. argv accepts a string and argc is the integral of the strings, which isn't neccesarry for my project, since my C# code controls the command-line arguments, but from what I gather an if statement needs to catch the third argument with an argc

 

Example:

// Retrieve the writer ID according to the description of file format.
int lFormat = lSdkManager->GetIOPluginRegistry()->FindWriterIDByDescription(argv[3]);
// Construct the output file name.
FBXSDK_strcpy(lNewFileName+lFileNameLength-4,60, argv[3]);
// Create an exporter.
FbxExporter* lExporter = FbxExporter::Create(lSdkManager, "");
// Initialize the exporter.
lResult = lExporter->Initialize(lNewFileName, lFormat, lSdkManager->GetIOSettings());
if( !lResult )
{
FBXSDK_printf("%s:\tCall to FbxExporter::Initialize() failed.\n", lFileTypes[i*2+1]);
FBXSDK_printf("Error returned: %s\n\n", lExporter->GetStatus().GetErrorString());
}
else
{
// Export the scene.
lResult = lExporter->Export(lScene);
if( !lResult )
{
FBXSDK_printf("Call to FbxExporter::Export() failed.\n");
}
}

 

 

will throw a stack overflow and call the native crash if a third argument isn't supplied, but

 

// Retrieve the writer ID according to the description of file format.
 
//Try third arg
if (argc>3){
int lFormat = lSdkManager->GetIOPluginRegistry()->FindWriterIDByDescription(argv[3]);
FBXSDK_strcpy(lNewFileName+lFileNameLength-4,60, argv[3]);
}
 
//fallback to pFormat=-1 if no third arg
else{
int lFormat = lSdkManager->GetIOPluginRegistry()->FindWriterIDByDescription(-1);
FBXSDK_strcpy(lNewFileName+lFileNameLength-4,60, -1);
}

FbxExporter* lExporter = FbxExporter::Create(lSdkManager, "");
// Initialize the exporter.
lResult = lExporter->Initialize(lNewFileName, lFormat, lSdkManager->GetIOSettings());
if( !lResult )
{
FBXSDK_printf("%s:\tCall to FbxExporter::Initialize() failed.\n", lFileTypes[i*2+1]);
FBXSDK_printf("Error returned: %s\n\n", lExporter->GetStatus().GetErrorString());
}
else
{
// Export the scene.
lResult = lExporter->Export(lScene);
if( !lResult )
{
FBXSDK_printf("Call to FbxExporter::Export() failed.\n");
}
}

 

 

will failsafe to -1 (default) and defeat the crash monkey.

 

Is any of this correct or am I making people dumber for having listened to me?Smiley LOL

 

The solution:

 

/****************************************************************************************

   Copyright (C) 2013 Autodesk, Inc.
   All rights reserved.

   Use of this software is subject to the terms of the Autodesk license agreement
   provided at the time of installation or download, or which otherwise accompanies
   this software in either electronic or hard copy form.

****************************************************************************************/

/////////////////////////////////////////////////////////////////////////
//
// This program converts any file in a format supported by the FBX SDK 
// into DAE, FBX, 3DS, OBJ and DXF files. 
//
// Steps:
// 1. Initialize SDK objects.
// 2. Load a file(fbx, obj,...) to a FBX scene.
// 3. Create a exporter.
// 4. Retrieve the writer ID according to the description of file format.
// 5. Initialize exporter with specified file format
// 6. Export.
// 7. Destroy the exporter
// 8. Destroy the FBX SDK manager
//
/////////////////////////////////////////////////////////////////////////

#include <fbxsdk.h>

#include "../Common/Common.h"

#define SAMPLE_FILENAME "X-Port.obj"

const char* lFileTypes[] =
{
	"_dae.dae", "Collada DAE (*.dae)",
	"_fbx7binary.fbx", "FBX binary (*.fbx)",
	"_fbx7ascii.fbx", "FBX ascii (*.fbx)",
	"_fbx6binary.fbx", "FBX 6.0 binary (*.fbx)",
	"_fbx6ascii.fbx", "FBX 6.0 ascii (*.fbx)",
	"_obj.obj", "Alias OBJ (*.obj)",
	"_dxf.dxf", "AutoCAD DXF (*.dxf)",
	".3ds", "Autodesk 3DS (*.3ds)"
};

int main(int argc, char** argv)
{
	FbxString lFilePath("");
	for( int i = 1, c = argc; i < c; ++i )
	{
		if( FbxString(argv[i]) == "-test" ) continue;
		else if( lFilePath.IsEmpty() ) lFilePath = argv[i];
	}
	if( lFilePath.IsEmpty() ) lFilePath = SAMPLE_FILENAME;

    FbxManager* lSdkManager = NULL;
    FbxScene* lScene = NULL;
	int lFormat;
    // Prepare the FBX SDK.
    InitializeSdkObjects(lSdkManager, lScene);

	bool lResult = LoadScene(lSdkManager, lScene, lFilePath.Buffer());
    if( lResult )
    {		
		const size_t lFileNameLength = strlen((argc>=3)?argv[2]:lFilePath.Buffer());
        char* lNewFileName = new char[lFileNameLength+64];
        FBXSDK_strcpy(lNewFileName,lFileNameLength+64,(argc>=3)?argv[2]:lFilePath.Buffer());

        const size_t lFileTypeCount = sizeof(lFileTypes)/sizeof(lFileTypes[0])/2;

        for(size_t i=0; i<lFileTypeCount; ++i)
        {
			if (argc >= 4)
			{
				lFormat = lSdkManager->GetIOPluginRegistry()->FindWriterIDByDescription(argv[3]);
				FBXSDK_strcpy(lNewFileName + lFileNameLength - 4, 60, argv[3]);
			}
			else
			{
				lFormat = lSdkManager->GetIOPluginRegistry()->FindWriterIDByDescription(lFileTypes[i * 2 + 1]);
				FBXSDK_strcpy(lNewFileName + lFileNameLength - 4, 60, lFileTypes[i * 2]);
			}

            // Create an exporter.
            FbxExporter* lExporter = FbxExporter::Create(lSdkManager, "Vampyre");

            // Initialize the exporter.
			lResult = lExporter->Initialize(lNewFileName, lFormat, lSdkManager->GetIOSettings());
            if( !lResult )
            {
                FBXSDK_printf("%s:\tCall to FbxExporter::Initialize() failed.\n", lFileTypes[i*2+1]);
                FBXSDK_printf("Error returned: %s\n\n", lExporter->GetStatus().GetErrorString());
            }
            else
            {
                // Export the scene.
				lResult = lExporter->Export(lScene);
                if( !lResult )
                {
                    FBXSDK_printf("Call to FbxExporter::Export() failed.\n");
                }
            }

            // Destroy the exporter.
            lExporter->Destroy();
        }
        delete[] lNewFileName;
    }
	else
    {
        FBXSDK_printf("Call to LoadScene() failed.\n");
    }

    // Delete the FBX SDK manager. All the objects that have been allocated 
    // using the FBX SDK manager and that haven't been explicitly destroyed 
    // are automatically destroyed at the same time.
    DestroySdkObjects(lSdkManager, lResult);
    return 0;
}

 

Message 3 of 3
Bloodysoft
in reply to: Bloodysoft

Just one more thing....

The .3ds format exports as fbx; is the syntax for it in lFileTypes array wrong? I have it as "Autodesk 3DS (*.3ds)"

 

Edit: nvm, I should learn how to read. Supports importing 3ds but not exporting.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report