It is dangerous to retain a Ruby reference to a SketchUp Entity across an operation that may modify that entity. Beneath the covers, SketchUp feels free to delete Entities and redraw identical ones as necessary to generate the final geometry. It also may reuse an existing Entity for some part of new geometry. For example, if a Face gets split into pieces, SketchUp may keep the original Face Entity to use as one of the new (smaller) Faces and create new Faces for the rest.

i used this same method in another code and it works every time but when i organized my code and divided it into methods it doesnât work now.
why did it work before but not now also is it possible to keep pointing at that entity ?

SketchUpâs internal decisions about whether to retain vs delete an Entity (and when) are undocumented and sensitive to fine details. Itâs a bit like saying âI walked across this street yesterday and didnât get hit by a car. Why did I get killed today?â. It was a bad idea in any case, but you just got lucky the first time.

@slbaumgartner also it worked for another model just now, mm i used the reference to get the intersection edges created after intersect_with, and until now it still helps getting them for some models.
Is there any way to retrieve the intersection edges ? as the intersect_with method doesnât return them ?

The Ruby API documentation is in error: intersect_with returns an Array of the Edges it creates. If there are none, it returns an empty Array. It never returns nil!

hello @slbaumgartner i tried the returned values by intersect_with as you said but for the model below, there is only one intersection edge but in the messagebox it shows that it returns 3 edges and sometimes 2 edges for the same model.
so my question is does this function returns the intersection edges created or even the edges that were changed ? and why it shows 3 edges instead of 1 ?
thnx

Your âroofâ plane touches the âwallâ = 1 edge intersected [same size as it was]
It also cuts another roof plane = 1 new edge at 'hipâ
It also splits its top edge where the âhipâ touches = 2 new edges

That adds up to 4 edges resulting from the intersectionâŚ

but each time it shows different number of edges ? for example in the image bellow there should be an edge that has 4 faces (ones showed in the image) which is the one showed by the arrow, but when i test it shows 2 edges sometimes and sometimes it shows 3 edges but none of them has 4 faces ?

i did zoom that part and i found that even if i draw an edge manually it devids the edge into 2 parts as in the image below.
i donât know this happens even if i draw it manually from point to point ?

This is because your #base is poorly drawn.
If you donât want a short edge then fix it.
Use a Style with endpoints so itâs easier to see,
I also added a short cline to each edges start so I could see what there are 8 edges when I can see only 7 !
Use the Move tool to relocate the rogue vertex so the two edges merge into one.

This issue has got nothing to do with your coding attempts.
The poorly form base simply needs fixingâŚ

Your ruby code must define 8 vertices, not the expected 7.
It needs fixing at that level, before getting to the roof intersection phaseâŚ

You can merge colinear vertices, but not having them would be easier !
Fredo has a tool to do thisâŚ

To find colinear vertices you need to collect the edges you have made for the âbaseâ.
Iâd use a hash, referencing each edge and taking its value as its edge.line
Then step through the edges and take each start point [from its line or start.position] and use distance_to_line stepping through each of the other edgeâs line - if itâs == 0 then the tested edgeâs start is on that line - if the lineâs vector == edgeâs lineâs vector then the two edges are colinear.
Find the shortest edge.
The vertex shared with the other colinear edge can be found.
Make a transformation - translation - using the vector from that shared vertex position to the shortest edgeâs other vertex.position; now use transform_entities to transform the shared vertex by the translation and the two edges will merge.
Of course you need to reduce the tested edges as you go to avoid looking at now non-existent entities etcâŚ

As I said itâs best to draw it right rather than fix it later !!

@TIG thank you for your answer, yes i agree with you so i tried to find the origin of the problem but the only thing that i found and that may lead to that problem, is that I calculate the vertices values using user inputs in meter, and when i need to convert the result of the calculation i multiply by 39,37 instead of using the to_inch method, as it didnât work. When i try variable.to_inch it keeps the same value of the variable without conversion.
same fo the to_m method, for example the result of this code (point is a Point3D):

p=point.x/39.37
UI.messagebox("point to x is by #{point.x} the p value is #{p}")

can this lead to the problem i posted ? also why does the to_inch method not work for a calculation result ?
thnx a lot

Why not get the userâs input as âlengthâ ?
e.g.

x = 0.m

Then if they input a value in their current units [anything! == m/cm/mm/inch/feet etc] OR append a units suffx - so if they are working in mm, typing 1m assumes 1m etcâŚ

You are making your life far more complicated than it needs to be !

If you are expecting an input âpointâ in the form x,y,z
then default it as a string "0,0,0"
Why worry about units at all ?
Let the user specify their own unitsâŚ
Split at the â,â and then convert to length ?

point=str.split(',') px=point.x.to_l

returns the enter value as a âlengthâ - allowing the user to work in any units they like, if they want to work in âmâ while set to âmmâ they simply add a âmâ after the numberâŚ

@TIG actually the user will only use meter but thatâs not the problem, i need to take the length in meters (width and heigth ) of the face then draw it thatâs why i need to convert it to inch to represent the vertices of the face, as when i draw the face using the values entered by the user it draws verry small shapes.