Hi, I’m using C API, and I need to import a model skp file into another model.
So I read a bunch of function definitions in the C API documentations page. And I end up with these example codes.
SUModelRef = model = SU_INVALID;
SUModelCreate(&model);
SUEntitiesRef entities = SU_INVALID;
SUModelGetEntities(model, &entities);
SUComponentDefinitionRef component_definition = SU_INVALID;
SUModelLoadStatus status;
// Load the external SKP file as a component definition
SUResult res = SUModelLoadDefinitionWithStatus(model, "wooden_door.skp", &component_definition, &status);
if (res != SU_ERROR_NONE) {
std::cerr << "Failed to load the external model << std::endl;
return;
}
// Add the component definition to the model
SUModelAddComponentDefinitions(model, 1, &component_definition);
// Create an instance of the component definition (imported SKP file)
SUComponentInstanceRef instance = SU_INVALID;
SUComponentDefinitionCreateInstance(component_definition, &instance);
// Apply the transformation matrix to the component instance
SUTransformation transform = ... // some transformation initializing
SUComponentInstanceSetTransform(instance, &transform);
// Optionally, set a name for the component instance (not required)
SUStringRef name = SU_INVALID;
SUStringCreate(&name);
SUEntitiesAddInstance(entities, instance, &name);
SUStringRelease(&name);
SUComponentInstanceRelease(&instance);
SUComponentDefinitionRelease(&component_definition);
SUModelSaveToFile(model, "output_model.skp");
SUModelRelease(&model);
SUTerminate();
However, I’m still struggling with this task because It doesn’t work. More specifically, the code runs with no error, but when I check the output_model.skp, There’s nothing.
I’m using Windows 11 and the latest SDK of C API.
Is this a correct way of importing skp files? Or is there any other way of doing it?