Using Component Instance/Definition Set Name

I am trying to set the name and description of my component.

SUComponentDefinitionSetName(component, "my component name");
const char *desc = "description";
SUComponentDefinitionSetDescription(component, desc);

SUComponentInstanceSetName(instance, "my component name");
SUComponentInstanceSetGuid(instance, "12345");

SUModelAddComponentDefinitions(model, 1, &component);
	
SUEntitiesRef mEntities = SU_INVALID;

SUModelGetEntities(model, &mEntities);

SUEntitiesAddInstance(mEntities, instance, NULL);

I initialize my component, model, and instance this way:

SKPModel(){
		model.ptr = nullptr;
		component.ptr = nullptr;
		instance.ptr = nullptr;
		
		SUInitialize();
		
		SUModelCreate(&model);

		SUComponentDefinitionCreate(&component);

		SUComponentDefinitionCreateInstance(component, &instance);

	}

I used this after I set it to see if it was set, but it returns an empty pointer.

SUStringRef myName = SU_INVALID;
SUComponentInstanceGetName(instance, &myName);

I just want to be able to set the name and decription, so when you click on component info it shows up. Am I using the set methods incorrectly?

Sketchup will not retain an empty definition.
Add entities to it - even just a cpoint - it will them persist and you can then test your desc set up on it as it displays in the component Browser…

I do fill my component entities at another point in the code. I fill the entities, then call the function to set the description and save the model. The code I have shown adds the already filled component definition to the model, then grabs the model entities and fills it with the instance of that component definition.

The flowering plant in the image is the what I filled the component entities with.

[quote=“skapp, post:1, topic:11364”]
SUComponentDefinitionSetDescription(component, desc);
[/quote] I see.
If instead of setting a reference to a string constant, you set the string in the description directly what happens ? e.g.

SUComponentDefinitionSetDescription(component, "my desc");

I’m wondering if the description needs to be an SUStringRef [with a release later] ??

Thanks for your help. I figured out what the problem is. When I create my component and export the file, and open that file everything is correct.

It is when I import the model into the current model, that the problem occurs.

It seems like my component is a component within another component.

Is this always going to happen when importing?

You can of course set:

model.description = definition.description

[cod-code] then explode the original instance ?

Is there a way to explode in the c sdk and not the ruby script?

The only reason I ask is because I tried it this way, and it did explode it correctly:

componentdefinition = definitions.load path
point = Geom::Point3d.new 10,20,30
transform = Geom::Transformation.new point
instance = entities.add_instance componentdefinition, transform
array = instance.explode

But I do not like the use of transform. I like that when my model imports it calls the placement tool and lets me click. The transform places it at the point, and I do not want that.

Components in a way is a model. When you select a component instance in SU and save it out it is saved out as a SKP model.

When you load a SKP file into another model that SKP model becomes a component.

So in your case, where you use the C API to create a component to insert into another model you want to just create the mesh directly in the model root - as the model itself will become the component definition when you import.

Ok. Is there anyway in the ruby api to add an instance without transform?

You need some kind of transformation to tell Sketchup where the component_instance is at least located ?

some_entities_context.add_instance(some_component_definition, ORIGIN)

is probably the simplest, as a point3d can be substituted for a simple transformation…

There is also the IDENTITY constant which holds an identity transformation.

This also work:

some_entities_context.add_instance(some_component_definition, IDENTITY)

But that rather sidesteps an obvious question…
What is THE IDENTITY transformation ?
In fact that ‘Constant’ transformation appears to be exactly the same as Geom::Transformation.new() when you .to_a it…
So I see no real use for it ?
The transformation.identity? method tells us if the transformation matches IDENTITY - i.e. it’s a new virginal vanilla unchanged transformation - so is that its only purpose ?
As far as I know the result is the same as:

some_entities_context.add_instance(some_component_definition, ORIGIN)

or

some_entities_context.add_instance(some_component_definition, Geom::Transformation.new())

It’s also odd to give it that name which seems disconnected with a ‘transformation’ - at least we know ORIGIN is a point3d ??

I’m not seeing the ambiguity here… what are you referring to?

Yes - Transformation.new return an identity transformation. So it would be the same as the IDENTITY constant.

Like ORIGIN being the same as Geom::Point3d.new and Geom::Point3d.new(0,0,0) and X_AXIS being the same as Geom::Vector3d.new(1,0,0) we have IDENTITY as a convenient shortcut for the identity transformation. I don’t fully understand your concern here though…

No concern per se.
It just seems an unnecessary thing to have invented - given it can be reproduced several other ways.
There were plenty more things to fix or make in the API !

ORIGIN == [0 0, 0]
Z_AXIS == [1, 0, 0]

are clearly named - at least to an English speaker.
The question is really, why did somebody who probably has/had English as their first language choose the name IDENTITY for a virgin transformation when setting up this sub-module ?
Surely something like TRANSFORMATION or just TRANS would be more clear ?
After all that is what it is.
I know it’s all set in stone now,I was just curious as to where it came from, that is all…
It doesn’t gel with the simple math definition…

IDENTITY: a function that always returns the same value that was used as its argument.
In equations, the function is given by f(x) = x.

Since IDENTITY is a Constant and also a ‘Transformation’ I fail to see how it’s naming is wholly appropriate ?
It has no input, just an output ?

Also it isn’t even clearly explained in the API docs anyway - there’s just the enigmatic transformation.identity? method !

If you apply an identity transformation then nothing changes. TRANSFORMATION would be ambiguous - IDENTITY (while it doesn’t say it’s a transformation - though you can get that from inspecting the class of the object) do indicate the particular purpose. IDENTITY isn’t there for a random new transformation - it’s specifically meant to represent the identity transformation.

This method is a bit quirky IMO. It returns true only if the transformation was created an an identity transformation and never changed. If you take an arbitrary - non-identity transformation and modify it so the matrix is equal to the Idenityt transformation it’ll still return false. Not sure that was done like that - but we have an issue to update the docs for that and possible introduce an optional argument to check the actual data.

Identity Transformation - or more commonly Identity Matrix - is a mathematical definition.