How to delete all vertical edges and horizontal faces?

I am using SU 8.

Can you please give me ruby command to delete all vertical edges?

Also I need to delete all horizontal faces which do not have material “702”.

For vertical edges something like this…

m=Sketchup.active_model
m.start_operation('VEdges',true)
m.active_entities.grep(Sketchup::Edge).each{|e|e.erase! if e.line[1].parallel?(Z_AXIS)}
m.commit_operation

For faces something like this…

m=Sketchup.active_model
m.start_operation('HFaces702',true)
m.active_entities.grep(Sketchup::Face).each{|e|e.erase! if e.normal.parallel?(Z_AXIS) && e.material && e.material.display_name!="702"}
m.commit_operation

This ignores faces which have the default-material, but it could be modified…

1 Like

Can you pls try the first code on this model, group set:

exploded.skp (2.4 MB)

For me it does not delete the edges.

Is the code for SU 8?

m.start_operation('VEdges',true)
true
m.active_entities.grep(Sketchup::Edge).each{|e|e.erase! if e.line[1].parallel?(Z_AXIS)}
Error: #<TypeError: (eval):98:in `line': reference to deleted Edge>
(eval):98
(eval):98
(eval):98:in `each'

to avoid deleted edges add in a test…

e.valid?

john

e.valid?

I do not know the ruby syntax, can you please modify the command and show me?

Do you mean like

e.line[1].parallel?(Z_AXIS)?e.valid?

put it first as any other reference to e will also cause an error and separate it using &&…

   if e.valid? && e.line[1].parallel?(Z_AXIS)}

john

Yes, this delete command worked! Thank you.

Musing about #grep and the Enumerable module ...

The Ruby Standard Library was not distributed with SketchUp until SketchUp 2014.
So I am wondering how #grep could work (in SU8) as it comes from the Enumerable library module.

EDIT: Thinking on this and half a cup of coffee later. I guess the answer is that Enumerable is within the Ruby Core and was compiled into the Ruby interpreter DLL on Windows and Ruby Framework on Mac.

It was also (as I remember) an explicit API change to mix Enumerable into the various API collection classes. (But a check of the Release Notes doesn’t find a mention of this.)


Anyway … for anyone who needs to run SketchUp versions 8 or 2013 on MS Windows, …
I packaged up the Ruby 1.8.6-p287 Standard Library as a SketchUp extension …

https://github.com/DanRathbun/sketchup-ruby186-stdlib-extension/releases/latest

… enjoy.

Sure it is SU 8 I have this in the first sentence of my post.

I am developer and I have various linux programs installed on Windows.