# Programmatically creating Geometry problems

This may or may not prove my hypothesis correct. [quote=“Neil_Burkholder, post:18, topic:29852”]
and becomes a deleted entity
[/quote]

After running the steps shown in my last post, select File>Revert. Try to create the face again (from points only. Right?) See the resulting error. Hmm… (No entities involved. Right?) You might want to tag this as a bug.

Now redefining pts again silently fails.

``````pts = [
[5.65553, 11.15667, 0.0], [5.65553, 6.15667, 0.0], [5.65553, 6.15667, 2.7],
[5.65553, 11.15667, 2.7], [5.65553, 11.15667, 0.0], [5.65553, 10.33172, 0.87517],
[5.65553, 10.33172, 2.09517], [5.65553, 7.18172, 2.09517], [5.65553, 7.18172, 0.87517],
[5.65553, 10.33172, 0.87517]]
ent = Sketchup.active_model.entities
``````

Oh! thanks @Neil_Burkholder, that’s cool; if it’s indeed a bug that’d be hilarious as my night frustrations were not in vain!

Now what’s the correct way of filling a bug report? Report this thread in support forum?

Click the pencil icon beside the main post heading. Click the tag box, and select the ‘bug’ tag from the list. Click the check mark to save your edit.

More interesting info after further testing. It seams like this only occurs when there is already an edge identical to the first one being created. So in you original model select the bottom edge and divide it. Works fine. Or starting your points so the first edge created is the diagonal line, also works fine.

``````pts = [[5.65553, 11.15667, 0.0], [5.65553, 10.33172, 0.87517],
[5.65553, 10.33172, 2.09517], [5.65553, 7.18172, 2.09517], [5.65553, 7.18172, 0.87517],
[5.65553, 10.33172, 0.87517],[5.65553, 11.15667, 0.0], [5.65553, 6.15667, 0.0], [5.65553, 6.15667, 2.7],
[5.65553, 11.15667, 2.7]]
ent = Sketchup.active_model.entities
``````

Erasing the bottom edge, and redrawing it with the line tool also works, so no guarantees. As I said before, “Drawing over existing geometry can produce inconsistent results.” I’ve also had trouble with faces being reversed, but haven’t pinpointed the reproduction steps this far.

@Neil_Burkholder thanks awesome work, if you do find anything else do let me know… hopefully a Sketchup representative will chip in to shed some light…

I still think it’s wrong to try and use SketchUp like an Etch-a-Sketch …

Personally, I don’t think that this is a bug. Using a set of points that don’t create a properly-defined face can only lead to unexpected results.

That is correct - SketchUp will attempt to merge and split overlapping geometry.

May I ask why you try to create faces like this? Is it part of imported data? Might be worth that we briefly talk about this so we are all on the same page. I’ve seen quite a few integration attempts with SketchUp where things have gotten complicated because one attempted to do thing in a manner familiar to another application - but which isn’t how one would ideally do it in SketchUp.

I am just importing geometry exported by another program, it spits out the face in those 10 vertices; although if I can get a solid pattern of how and why this happens I can maybe make a special case about it. What’s weird is that if I push the object a bit back I can create the face as is no problem… (you can see that in the other attached scene)

hmm… maybe there is an tolerance issue in play here…

@thomthom any clue on what might that be? How can I push for a Sketchup developer to look at this?

Can you provide example to when the object is pushed back - where it works? As a comparison to when it doesn’t work?

@thomthom The second included file in the original post (link again here) demonstrates exactly this.You can also easily do that with the provided problematic scene if you take the object in it and move it back a couple of points in the x-axis…

Mystery solved!

It seems that if the face starts at an ‘end’ point of an edge that is flipped (edges have a ‘start’ and ‘end’ position) it doesn’t work. Not sure if I described it right but this gif should demonstrate.

EDIT:

Further testing reveals that this only occurs if the edges is exactly the same length, and position as the first edge created when making the face, but, the edge has the start and end positions reversed.

@Neil_Burkholder is this then… a bug?

IMHO Yes

@Neil_Burkholder if I flip the faces, will this get rid of the problem? Also is there any way of flipping faces from the Ruby API?

If you mean exchange the front and back, yes: Face#reverse!

No, but changing your starting point will, as shown in one of my previous posts.

You could check for and split any edges that are reverse oriented from your starting point.

This works on your original model.

``````ent = SketchUp.active_model.entities
pts = [
[5.65553, 11.15667, 0.0], [5.65553, 6.15667, 0.0], [5.65553, 6.15667, 2.7],
[5.65553, 11.15667, 2.7], [5.65553, 11.15667, 0.0], [5.65553, 10.33172, 0.87517],
[5.65553, 10.33172, 2.09517], [5.65553, 7.18172, 2.09517], [5.65553, 7.18172, 0.87517],
[5.65553, 10.33172, 0.87517]]

e = ent.grep(Sketchup::Edge).find_all {|e| e.end.position==pts[0] && e.start.position==pts[1]}
e.each{|e| e.split(0.5)}

``````

Or if you always want to prevent this you could create a refinement. Thanks to @DanRathbun for showing me how to fix things with refinements.

``````module Author

module Author::RefinedComponents

refine ::Sketchup::Entities do

# fixes a bug that prevents faces from being created, when the first edge already exists in a reverse orientation.
#split the offending edge to allow the new face to be created always.

e = parent.entities.grep(Sketchup::Edge).find_all {|e| e.end.position==pts[0] && e.start.position==pts[1]}
e.each{|e| e.split(0.5)}
end

end # class refinement

end # refinement module

end #Author Module

using Author::RefinedComponents

module Author::SomePlugin

pts = [
[5.65553, 11.15667, 0.0], [5.65553, 6.15667, 0.0], [5.65553, 6.15667, 2.7],
[5.65553, 11.15667, 2.7], [5.65553, 11.15667, 0.0], [5.65553, 10.33172, 0.87517],
[5.65553, 10.33172, 2.09517], [5.65553, 7.18172, 2.09517], [5.65553, 7.18172, 0.87517],
[5.65553, 10.33172, 0.87517]]