can anyone know how to remove lines that are not edges ??
Sketchup::ConstructionLine
are the only ‘lines’ that are not a Sketchup::Edge
…
do you mean those or are you wanting to remove/hide co-planer edges that split faces…
add an image or skp file to explain better…
john
i want some plugin or script to remove all extra (push pull guide) lines to be removed at one click
As @john_drivenupthewall says they are all ‘edges’ [actually a ‘line’ is a special thing defined by a point and a vector used in Geom::]
Iterate the relevant ‘edges’ and look at each ‘edge’ in turn…
To check if an ‘edge’ is ‘faceless’ use edge.faces[0]==false
To check if an ‘edge’ supports more than one face use edge.faces[1]==true
To check if an ‘edge’ is NOT needed - e.g. to keep its faces, and its faces don’t have different materials etc - i.e. it’s ‘coplanar’ - then you need to do some tests perhaps like this…
### iterate the 'edges' as 'edge'...
if edge.faces.length==2 && edge.faces[0].normal.dot(edge.faces[1].normal)>0.9999999 && edge.faces[0].material==edge.faces[1].material && edge.faces[0].back_material==edge.faces[1].back_material
### EITHER collect edge into an array,
### for erasing in one step later, OR use this
e.erase!
end
Your posted images crossed with my earlier posted code snippet…
If your seemingly ‘coplanar’ edges across the walls support faces as partitions within the wall itself, then it’s more complicated that deleting true ‘coplanar’ which simply split a face into two parts.
You need to collect edge.faces.length==3
Then check if any two of the edge’s faces share a common ‘plane’ [or ‘normal’] and if they do then the edge can be erased, taking its inner partition face with it.
After one pass to erase such edges you need to repeat using my earlier ‘coplanar’ code, to remove some now truly ‘coplanar’ edges which are left from the first step of processing.
PS: to collect all edges use edges=group.entities.grep(Sketchup::Edge)
You can use CleanUp3 tp merge coplanar faces (remove “flat” edges).
Thank you TIG it didn’t worked
What didn’t work ?
Without the code you tried who can say what is wrong ?
Did you collect all of the edges from their entities context ?
Did you then iterate those edges by edge ?
Did you then check each of those for three faces ?
Did you then check those faces to ensure two have the same ‘normal’ ?
Did you then erase the edge if so ?
Did you then repeat the collection and iteration process to remove any ‘coplanar’ edges with just two faces ?
Maybe something like:
# Delete 'extra' edges
# run with EraseEdges.run
module EraseEdges
def self.run
am = Sketchup.active_model
edges_erase = am.entities.grep(Sketchup::Edge).select do |e|
e.faces.empty? or (e.faces.length == 2 and
face0 = e.faces[0] and face1 = e.faces[1] and
face0.normal.dot(face1.normal) > 0.9999999 and
face0.layer == face1.layer and
face0.material == face1.material and
face0.back_material == face1.back_material
)
end
unless edges_erase.empty?
am.start_operation 'Erase Extra Edges'
am.entities.erase_entities edges_erase
am.commit_operation
end
end
end
This only erases coplanar edges supporting two faces.
But I strongly suspect [NOT confirmed] that the OP’s model has internal partition faces at the various points in the walls where they look ‘coplanar’ - so then
e.faces.length == 3
so in your example these edges are skipped, that’s why I suggested firstly collecting edges with 3 faces and then checking that two of those faces share a normal vector, and if they do erasing that edge, and as a by-product its internal partition face goes too.: however, some of the edges that supported that face are now 2-face coplanar edges and need removing with a second pass of something lie your code - although I question needing a check of the two faces for sharing a layer - as you know raw geometry [edges and faces] should of course always be assigned to Layer0 !
I wasn’t sure about that (faces.length == 3
) , or whether ‘active_entities’ or ‘entities’, or layers, or is the face visible, etc, etc…
Just a starting point…
I understand.
I’d use am.active_entities because then the user can activate the tool whilst within a group/component edit. and thereby process just those edges.
Otherwise using am.entities always processes just those entities in the model.
script test.skp (554.8 KB)
can you please help me how to properly use the above script to clean this way
thank you
sorry as I’m not very used to all this coding I came here to find some solution for my problem
I think the simplest solution is to scrap the coding solution…
Erasing coplanar edges supporting two faces is simple, but doing similar edits when a model such has yours has lots of internal partition faces within walls etc is difficult to achieve in a simple snippet.
However, all is not lost.
I tried running my ‘SolidSolver’ tool on the component-instance and it worked fine.
Just selected the problem ‘container’ [compo/group] and chose it off the right-click context-menu…
It automatically reversed some wayward faces around openings, then deleted the internal partition faces and then offered the chance to delete all of the now unnecessary coplanar edges across the wall faces.
On completion [after only a few seconds] it still reports as not being a solid [and in Entity Info], BUT all of the mess you want fixing is resolved.
I also tested it with thomthom’s ‘SolidInspector²’ which reports the reversed faces and partitions and lets you choose the fix them, however, it still leaves the coplanar edges in place, and oddly then considers it a solid despite Entity Info saying that it’s not !
So I recommend you download, then install my extension from here:
Note that if you are not already a member at SCF you can easily register, and the free-membership allows you to use the PluginStore etc…
Attached is a file, download it. then open the Ruby console from the window menu, and type
load '<path to file>'
When you want to ‘clean’ a model, type the following in the Ruby console:
CleanInner.run
I tested it with the model you attached above, and it works. There may be times where it doesn’t work, all the operations it performs can be reversed from the ‘Edit/Undo’ menu.
Lastly, your model was two components. If you need to ‘clean’ a component, select it, the right-click on ‘Edit Component’…
clean_inner.rb (2.2 KB)
NOTE: The code attached seems to fix the issue you have, which is a ‘solid type’ model with inner partitions. But, it will delete faces/edges if the model has other issues. For instance, a window opening. If one adds a face to one side of an open window, then run the code, it will make a mess of things.
The problem is that creating a list/collection of all the ‘inner partitions’ is a difficult thing to do. There are always edge cases that trip up the algorithms…
3 face problem is very common.
just add some object to another object.
and hidden face is made.
and gettting hidden face programmatically is difficult.
fs = []
for f in e.faces
# A hidden face has edges, all edges has faces 3 (face edge count - 1)
inner_face = true
for eg in f.edges
if eg.faces.length < f.edges.length - 1
inner_face = false
break
end
end
if not inner_face
fs << f
end
end
face0 = fs[0]
face1 = fs[1]
face2 = fs[2]
it is not good. but works.
Why are you using regular lines to layout your windows and doors. That is what guidelines are for and they are easily deleted. Click on Edit/delete guides in the menu.
This is another example of the importance to learn basics in the beginning.
because it is easy to programming.