Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Errors while importing FBX or Alembic

0 REPLIES 0
Reply
Message 1 of 1
mbartosiakB78XR
238 Views, 0 Replies

Errors while importing FBX or Alembic

Hi guys, I'm trying to implement a .fbx or .abc import logic in a c++ plugin and i have encountered some strange errors.
I use ImportFromFile() function and it seems to work until some point. It recognises what file to import but cant crashes wile doing it. In .abc the code opens the Alembic Import Options but then after clicking import is says "Improper file format", when doing the same thing but with .fbx it just gives a blank error. The code also has a result check implemented that shows me that the file was imported successfully (when it certainly was not). Additionally when using CanImportFile() instead of ImportFromFile() it throws out FALSE so it cant even import those files. Here is the whole code. I'll add that it needs to be done in C++ as it will be a part of the bigger plugin so doing it in the maxScript is a no go. I also tried to implement this logic as a maxScript insert but it just did nothing. Surely I have to be doing something wrong, but I can't seem to find what.
Thanks for help guys and gals!

#include "ObjectImporter.h"

#include "ui_plugin_form.h"
#include "qmessagebox.h"
#include "qobject.h"
#include "maxscript\maxscript.h"
#include "maxscript\macros\define_instantiation_functions.h"

#define ObjectImporter_CLASS_ID Class_ID(0x859e8ae4, 0x6b2b1e41)
using namespace MAXScript;

class ObjectImporter : public UtilityObj, public QObject
{
public:
	IUtil* iu;
	Interface* ip;
	// Constructor/Destructor
	ObjectImporter();
	virtual ~ObjectImporter();

	void DeleteThis() override {}

	void BeginEditParams(Interface* ip, IUtil* iu) override;
	void EndEditParams(Interface* ip, IUtil* iu) override;

	virtual void Init(HWND hWnd);
	virtual void Destroy(HWND hWnd);

	// Singleton access
	static ObjectImporter* GetInstance()
	{
		static ObjectImporter theObjectImporter;
		return &theObjectImporter;
	}

private:
	void ImportFromPath(const wchar_t* filePath);
	void ImportFileFromMaxscript(const MCHAR* filePath);
	QWidget* widget;
	Ui::PluginRollup ui;
};


class ObjectImporterClassDesc : public ClassDesc2
{
public:
	int           IsPublic() override { return TRUE; }
	void* Create(BOOL /*loading = FALSE*/) override { return ObjectImporter::GetInstance(); }
	const TCHAR* ClassName() override { return GetString(IDS_CLASS_NAME); }
	const TCHAR* NonLocalizedClassName() override { return _T("ObjectImporter"); }
	SClass_ID     SuperClassID() override { return UTILITY_CLASS_ID; }
	Class_ID      ClassID() override { return ObjectImporter_CLASS_ID; }
	const TCHAR* Category() override { return GetString(IDS_CATEGORY); }

	const TCHAR* InternalName() override { return _T("ObjectImporter"); } // Returns fixed parsable name (scripter-visible name)
	HINSTANCE     HInstance() override { return hInstance; } // Returns owning module handle


};

ClassDesc2* GetObjectImporterDesc()
{
	static ObjectImporterClassDesc ObjectImporterDesc;
	return &ObjectImporterDesc;
}

//--- ObjectImporter -------------------------------------------------------
ObjectImporter::ObjectImporter()
	: iu(nullptr)
{

}

ObjectImporter::~ObjectImporter()
{

}

void ObjectImporter::BeginEditParams(Interface* ip, IUtil* iu)
{
	this->iu = iu;
	this->ip = ip;
	widget = new QWidget;
	ui.setupUi(widget);


	// We can connect UI signals here using Qt Functor syntax
	QObject::connect(ui.pushButton, &QPushButton::clicked, this, [this]
		{
			ImportFromPath(_T("D:\\projects\\\3dsMax\\res\\ConeABC.abc"));
		});
	ip->AddRollupPage(*widget, L"Plug-in Rollup");
}

void ObjectImporter::EndEditParams(Interface* ip, IUtil*)
{
	this->iu = nullptr;
	ip->DeleteRollupPage(*widget);
}

void ObjectImporter::Init(HWND /*handle*/)
{

}

void ObjectImporter::Destroy(HWND /*handle*/)
{

}

void ObjectImporter::ImportFromPath(const wchar_t* filePath)
{
	int result = ip->ImportFromFile(filePath, FALSE);

	if(result != IO_OK)
	{
		MessageBox(GetCOREInterface()->GetMAXHWnd(), _T("Error importing file."), _T("Import Error"), MB_OK | MB_ICONERROR);
	}
	else
	{
		MessageBox(GetCOREInterface()->GetMAXHWnd(), _T("File imported successfully."), _T("Import Successful"), MB_OK | MB_ICONINFORMATION);
	}
}

void ObjectImporter::ImportFileFromMaxscript(const MCHAR* filePath)
{
	std::wstring scriptMessage = L"importFile ";
	std::wstring endMessage = L" #noPrompt";
	scriptMessage += filePath;
	scriptMessage += endMessage;
	const wchar_t* scriptMessageChar = scriptMessage.c_str();
	ExecuteMAXScriptScript(scriptMessageChar, MAXScript::ScriptSource::DynamicAlways, FALSE);
	ip->LoadFromFile(filePath);
}

 

Labels (3)
0 REPLIES 0

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

Post to forums  

Autodesk Design & Make Report