How to scale a component definition with C SDK?

Hi, all.

I want to rescale the component defination which is filled with SUEntitiesFill(comp_def_entities, GeometryInput, true).

And I have tried this with the following code.

			SUTransformation transform_scale = SU_INVALID;
			SU_CALL(SUTransformationScale(&transform_scale, 1.0/extend_scale));
			SUEntityListRef list = SU_INVALID;
			SUEntityListIteratorRef iterator = SU_INVALID;
			bool in_range = true;
			SUEntityRef entity = SU_INVALID;
			SUResult res = SUEntitiesEntityListFill(comp_def_entities, SURefType::SURefType_Entity, list);
			for (SUEntityListBegin(list, &iterator); SUEntityListIteratorIsInRange(iterator, &in_range) == SU_ERROR_NONE; SUEntityListIteratorNext(iterator)) {
				if (in_range != true) { break; }
				entity = SU_INVALID;
				SU_CALL(SUEntityListIteratorGetEntity(iterator, &entity));
				SU_CALL(SUEntitiesTransformMultiple(comp_def_entities, 1, &entity, &transform_scale));

However, the mesh structure has been changed by that, and the scale is not also reset correctly.

So, what’s the right way to change the scale of a component defination? Or is it supported by Sketchup?

Appreciate for any suggestion about my issue.Thanks!

One simpler way would be to create a new definition.
Create an instance of the old definition inside the entities of the new definition.
Scale the instance of the old definition.
Explode the old instance.
Now your new definition’s entities are a scaled copy of the old definition’s entities.

EDIT: I am not finding an explode function. Thought the C API had it, but it may still be a requested feature. (Oh it was myself that filed the request more than a year ago …)

You may not need an iterator if it is only a face/edge mesh.

If so, try passing just the mesh’s face array from SUEntitiesGetFaces into SUEntitiesTransform() with the scaling transformation.
The edges of the faces should also get scaled as faces cannot exist without edges.

If you have other types of objects in the definition’s entities, perhaps instead just collect the entities into an array using the iterator, then (as above) pass the array into SUEntitiesTransform() with the scaling transformation.

Hey, Dan, thanks !

Actually, it’s just a face/edge mesh. I have tried your advice, and the code as following, I can’t work well…

    SUTransformation transform_scale = SU_INVALID;
  	SU_CALL(SUTransformationScale(&transform_scale, 1/2));
  	size_t len = 0;
  	size_t count = 0;

  	SUFaceRef *faces = new SUFaceRef[len];
  	SUEntityRef *elements = new SUEntityRef[len];

  	SU_CALL(SUEntitiesGetNumFaces(comp_def_entities, &len));
  	SU_CALL(SUEntitiesGetFaces(comp_def_entities, len, faces, &count));
  	for (int i = 0; i < len; i++) {
  		elements[i] = SUFaceToEntity(faces[i]);
  	SU_CALL(SUEntitiesTransform(comp_def_entities, len, elements, &transform_scale)); 

Is any logic error? Or just the faces of component defination can’t be scaled…

What is the result ? Can you post a image of what the before and after look like in SketchUp ?

Can you clarify what you mean by this? What isn’t working and what are you observing?

Also here, can you describe what isn’t working well? What are you observing vs what you expect?

Is this for exporter with different units? In those cases I scale the coordinates I put into SUGeometryInput.