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 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.
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:
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.
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.
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.