# Using Component Instance/Definition Set Name

**URL:** <https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364>\
**Category:** SketchUp SDK\
**Created:** [May 18, 2015, 2:38pm UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364 "2015-05-18T14:38:34Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![skapp](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@skapp](https://forums.sketchup.com/u/skapp)\
**Post date:** [May 18, 2015, 2:38pm UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/1 "2015-05-18T14:38:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TIG](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tig/32/198_2.png) [@TIG](https://forums.sketchup.com/u/TIG)\
**Post date:** [May 18, 2015, 2:44pm UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/2 "2015-05-18T14:44:05Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![skapp](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@skapp](https://forums.sketchup.com/u/skapp)\
**Post date:** [May 18, 2015, 2:54pm UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/3 "2015-05-18T14:54:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TIG](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tig/32/198_2.png) [@TIG](https://forums.sketchup.com/u/TIG)\
**Post date:** [May 18, 2015, 4:22pm UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/4 "2015-05-18T16:22:00Z")

</div>

[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] ??

---

<div class="post-metadata">

**Author:** ![skapp](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@skapp](https://forums.sketchup.com/u/skapp)\
**Post date:** [May 18, 2015, 5:49pm UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/5 "2015-05-18T17:49:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TIG](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tig/32/198_2.png) [@TIG](https://forums.sketchup.com/u/TIG)\
**Post date:** [May 18, 2015, 6:13pm UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/6 "2015-05-18T18:13:45Z")

</div>

You can of course set:

```
model.description = definition.description

```

[cod-code] then explode the original instance ?

---

<div class="post-metadata">

**Author:** ![skapp](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@skapp](https://forums.sketchup.com/u/skapp)\
**Post date:** [May 18, 2015, 9:05pm UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/7 "2015-05-18T21:05:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [May 19, 2015, 8:39am UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/8 "2015-05-19T08:39:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![skapp](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@skapp](https://forums.sketchup.com/u/skapp)\
**Post date:** [May 19, 2015, 1:29pm UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/9 "2015-05-19T13:29:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TIG](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tig/32/198_2.png) [@TIG](https://forums.sketchup.com/u/TIG)\
**Post date:** [May 19, 2015, 2:45pm UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/10 "2015-05-19T14:45:41Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [May 20, 2015, 9:01am UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/11 "2015-05-20T09:01:15Z")

</div>

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

This also work:

```auto
some_entities_context.add_instance(some_component_definition, IDENTITY)

```

---

<div class="post-metadata">

**Author:** ![TIG](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tig/32/198_2.png) [@TIG](https://forums.sketchup.com/u/TIG)\
**Post date:** [May 20, 2015, 10:56am UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/12 "2015-05-20T10:56:14Z")

</div>

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 ??

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [May 20, 2015, 2:43pm UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/13 "2015-05-20T14:43:46Z")

</div>

> [@TIG](#):
>
> What is THE IDENTITY transformation ?

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

> [@TIG](#):
>
> In fact that ‘Constant’ transformation appears to be exactly the same as Geom::Transformation.new() when you .to\_a it…

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

> [@TIG](#):
>
> It’s also odd to give it that name which seems disconnected with a ‘transformation’ - at least we know ORIGIN is a point3d ??

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…

---

<div class="post-metadata">

**Author:** ![TIG](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tig/32/198_2.png) [@TIG](https://forums.sketchup.com/u/TIG)\
**Post date:** [May 20, 2015, 3:18pm UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/14 "2015-05-20T15:18:57Z")

</div>

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 !

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [May 21, 2015, 9:33am UTC](https://forums.sketchup.com/t/using-component-instance-definition-set-name/11364/15 "2015-05-21T09:33:28Z")

</div>

> [@TIG](#):
>
> 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 ?

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.

> [@TIG](#):
>
> Also it isn’t even clearly explained in the API docs anyway - there’s just the enigmatic transformation.identity? method !

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.

> [@TIG](#):
>
> 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 ?

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

> **[Identity matrix](https://en.wikipedia.org/wiki/Identity_matrix)**
>
> In linear algebra, the identity matrix of size 
>   
>     
>       
> n
>       
>     
> {\\displaystyle n}
>   
> is the 
>   
>     
>       
> n
> ×
> n
>       
>     
> {\\displaystyle n\\times n}
>   
> square matrix with ones on the main diagonal and zeros elsewhere. It has unique properties, for example when the identity matrix represents a geometric transformation, the object remains unchanged by the transformation. In other contexts, it is analogous to multiplying by the number 1.
> The...
