Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Null Pointer Issue when Generating New Material from existing material in C++

1 REPLY 1
SOLVED
Reply
Message 1 of 2
pts.user2
141 Views, 1 Reply

Null Pointer Issue when Generating New Material from existing material in C++

Hello everyone,

I'm currently working on a project where I'm attempting to create a new material from an existing one.

However, I'm encountering an issue in my C++ code where the pointer is returning NULL pointer for the new Material generated. Surprisingly, when I use the same code in Python, the new material is successfully generated. 

 

  • C++ Code

 

Ptr<MaterialLibraries> matLibs = app->materialLibraries();
Ptr<MaterialLibrary> matLib = matLibs->itemByName("Fusion 360 Material Library");
Ptr<Materials> materials = matLib->materials();
Ptr<Material> existingMaterial = materials->item(0);
Ptr<Material> newMaterial = materials->addByCopy(existingMaterial, "NewMaterial");​

 

  • Python Code

 

matlibs = app.materialLibraries
matLib = matlibs.itemByName('Fusion 360 Material Library')
materials = matLib.materials
existingMaterial = materials.item(0)
newMaterial = design.materials.addByCopy(existingMaterial, "NewMaterial")​

 

I was wondering if anyone could assist me in identifying any potential issues within the code.

Thank you in advance for your help!

1 REPLY 1
Message 2 of 2

You are not creating the material in the current design i guess which you are doing it in the python.
the code should like this

	Ptr<MaterialLibraries> matLibs = app->materialLibraries();
	Ptr<MaterialLibrary> matLib = matLibs->itemByName("Fusion 360 Material Library");
	Ptr<Materials> materials = matLib->materials();
	Ptr<Material> existingMaterial = materials->item(0);
	Ptr<Material> newMaterial = design->materials()->addByCopy(existingMaterial, "NewMaterial");

 


Boopathi Sivakumar
Senior Technology Consultant

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report