Sketchup::Face reference args become #<Deleted Entity> after transform_entities() call

deleted_entity
transform_entities
entities
transform
transformation

#1

Hi,

Imagine having a component with a face. When “puts myface” it says #Sketchup::Face:0x000000003ff318> in Ruby Console.

But when the face is moved inside the component with ‘entities_to_transform’, it now says #Deleted Entity:0x3ff318> in Ruby Console?

It still shows in the 3d model, and it can still read the attributes with get_attribute. But when trying to set_attribute the program generates an error because it cant set an attribute to an deleted entity.

Have anyone a work around this?


#2

How did you get a reference to the original Face?


#3

when creating the face it was put into a variable, like:

@front_face_1[i] = @wallcomponent_layer_defs[i].entities.add_face front_base_line_1[i],front_corner_line_1_4[i],front_top_line_1[i],front_corner_line_1_2[i]


#4

Do you mean the method #transform_entities(transform, entities)?


#5

entities_to_transform = []
entities_to_transform[i] = []
entities_to_transform[i].push(@front_base_line_2[i])
entities_to_transform[i].push(@front_top_line_2[i])
entities_to_transform[i].push(@front_corner_line_2_3[i])
entities_to_transform[i].push(@back_base_line_2[i])
entities_to_transform[i].push(@back_top_line_2[i])
entities_to_transform[i].push(@back_corner_line_2_3[i])

				transform = Geom::Transformation.new([delta_x,0,0])
				@wallcomponent_layer_defs[i].entities.transform_entities(transform, entities_to_transform[i])

#6

As you edit or modify a model, it is not unusual for SketchUp to delete existing geometry and subsequently regenerate visually identical geometry. The reasons SU does this are buried deep in the logic of its geometry management and are undocumented. I can dream up scenarios in which SU might conclude that the edge loop defining a face has become altered so the face can’t exist any more but then “re-find” an equivalent face later when cleaning up. For me the bottom line has always been that it is unsafe to retain a reference to geometry across an operation that might alter that geometry.


#7

@slbaumgartner ok, but that gives a problem when working with attributes. It means you can only set an attribute when initializing a face.


#8

It says you have to be sure that part of the model is stable before setting attributes else risk they may be abandoned.


#9

Like Steve says, SketchUp does not have any API methods for keeping track of changed or deleted geometry. It’s up to you to figure out a way to “re-find” the Face you need.

There are a number of metrics that could be used to find the Face - orientation, area, etc.


#10

So the solution will be, NOT to change the attribute after the face has been initialized.

Thanks both of you - you answered the question.