Transforming Entities and Make Unique

Once again I seem to have run up against something that I can’t quite figure out and this doesn’t happen very often anymore.

This is part of my “Extend” tool in my Project plugin. The tool does not seem to have any issues when the member it is extending is unique in the model, however if there are several instances using the same definition (group) then I get the following strange behavior and corrupted geometry:

What is weird is that I am first employing the make_unique method but regardless it doesn’t seem to work, see code below:

entityi2 = entityi.make_unique
definitioni = entityi2.definition

if typei == "ComponentInstance"
	@group_entities = definitioni.entities
else
	@group_entities = entityi2.entities
end

@group_entities.transform_by_vectors(@face_vertices, @vec_extend_array)

I’ve also tried just using the transform_entities method instead of the transform_by_vectors method but it also yields the same result:

counter = 0
for xi in @face_vertices2
	vi = @vec_extend_array[counter]
	tri = Geom::Transformation.translation(vi)
	@group_entities.transform_entities(tri, xi)
	counter = counter + 1
end

I know the make_unique method is working because when the result is produced the group I originally selected is now unique in the model and the remaining groups still belong to the shared definition however I can’t figure out why I am getting the strange results.

I’m now wondering if anyone else has come across a similar or the same issue.

What is bewildering me even more is my very similar “Trim” tool uses the exact same code to make the group or component unique and it appears to work flawlessly. However it doesn’t use the transform_entities or transform_by_vectors methods, it uses my own home grown algorithm for the trimming process.

I am thinking the issue must somehow be related to these two methods…

If you make unique a Componen Instance, it remains a component Instance.

Also, the vertices will be different in the unique Component.

1 Like

:thinking: I would try to use definition entities for the group too…

entityi2 = entityi.make_unique
definitioni = entityi2.definition
@group_entities = definitioni.entities

@group_entities.transform_by_vectors(@face_vertices, @vec_extend_array)
1 Like

I just tried this and the result is the same as before.

I’m going to try to make this work for groups first that all share the same definition.

If I remove the make_unique line of code and use the definition entities for groups (as Dezmo suggested), I don’t get the weird geometry, however this defeats the purpose make unique line and all of the studs get extended the same as one would expect:

I suppose this is better than my original result but it would be nice to extend a member, and even if it is using the same definition as any number of other members, it would be able to make the member unique and only extend that specific member.

Have you tried adding:

definitioni.invalidate_bounds

after the geometry is changed ?

1 Like

I’ve tried this line in various places:

1.) Right after I make the group/component unique
2.) After the transform_by_vectors

It doesn’t seem to have any affect.

I haven’t shown the details of how I obtain the vertices and vectors for the transform_by_vectors method, but needless to say I do this after I make the group unique.

The second face to use for the extend operation is obtained by the pick handler:

@Face2 = @ph.picked_face
@face_vertices = @Face2.vertices

There must be something simple I am doing wrong here, I just can’t quite put my finger on it.

I also thought, maybe SketchUp just needs some time to update the definition before proceeding with the next step. So I put in some delays (sleep command was one option I tried) but this does not seem to be the problem.

After further testing I’m beginning to think the issue may be due this single line:

@Face2 = @ph.picked_face

Since the pick handler is probably referencing the original face (before the group is made unique) it is causing confusion.

The question is how to re-find the face after making the group unique, and then delineate those vertices.

1 Like

I think you’ve found the problem. If you comment out line 248 in the attached code for a Stretch Tool you’ll see the same error.

stretch_tool.rb (11.8 KB)

3 Likes

That was the issue. If the make_unique does indeed make the group or component unique then the face that was selected is no longer the same face. So in this case I have to find the new face. Once I’ve found the new face then it all works.

1 Like

And there’s the explanation: to make unique, SketchUp creates a new component definition with a new entities collection. A face, edge, or other entity can exist in only one entities collection at a time, so SketchUp has to create a new one either in the original context or in the new one. It does the latter.

2 Likes