Message 1 of 1
Unable to change image in a material
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I was able to have it working in Python but when converting to C++ the variable 'texture' returned null.
Help please.
Ptr<Appearance> GetImageInDesign(std::string imageName) {
//Check to see if the material exists in the local appearances.
Ptr<Document> doc = app->activeDocument();
if (!doc)
return false;
Ptr<Product> product = app->activeProduct();
if (!product)
return false;
Ptr<Design> design = product;
if (!design)
return false;
Ptr<AppearanceTextureProperty> image;
Ptr<Appearance> mat = design->appearances()->itemByName(imageName);
if (!mat) {//our document does not have this material
//Get the existing appearance from fusion lib.
Ptr<MaterialLibrary> matLib = app->materialLibraries()->itemByName("Fusion 360 Appearance Library");
if (!matLib)
return false;
mat = matLib->appearances()->itemByName("Pine");
if (!mat) {
ui->messageBox("Unable to locate Pine!");
return false;
}
mat = design->appearances()->addByCopy(mat, imageName);
}
image = (mat->appearanceProperties()->itemByName("Image")); //jpeg image used in the material
if (!image)
return false;
std::string curName = image->name(); //this return "Image"
Ptr<AppearanceTexture> texture = image->value();
if (!texture)
return false;
if (!texture->changeTextureImage(ImageFolder + imageName))
return false;
//face->appearance = mat;
//Copy it to the design, giving it a new name.
return mat;
}