[Plugin] Select by Z

[Plugin] Select by Z

Postby EarthMover » Thu Jul 16, 2009 10:29 pm

Does a plugin exist that will allow you select all edges and faces have have the same Z coordinate in world space? It would select all coplanar object based on a given height in world space.....edges or faces.

Update - Select by Z .rb files. - Thanks TIG & BTM

Select Faces by Z - Choose a face and run select faces by Z to select every other face on the same XY plane.

Select Edges by Z - Select an edge and run script to select all other edges that have been drawn on the same XY plane. Would be a good script for CAD cleanup and identifying edges that are non coplanar.

MADE BY TIG:
0
Last edited by TIG on Mon Oct 08, 2012 1:47 pm, edited 4 times in total.
Reason: Just cleaning up and organizing the Plugin forum. Correcting [Plugin] tag
3D Artist at Clearstory 3D Imaging
Guide Tool at Winning With Sketchup
Content Creator at Skapeup
User avatar
EarthMover 
Premium Member
Premium Member
 

Re: REQ - Select by Z?

Postby TIG » Fri Jul 17, 2009 10:08 am

I don't know of one, but it's quite easily done...

Do you want a starting dialog to specify the Z value in [current units] ?
Do you want to select all co-planar faces OR all co-normal [angle of slope] faces ? Do you want to treat any 'reversed' faces as being co-planar/co-normal ?
Do you want to select all co-planar edges ?
Do you want to select all faces with any part of themselves at a given Z height ?
Do you want to select all faces with their lowest bounds at a given Z height ?
Do you want to select all faces with their highest bounds at a given Z height ?
Do you want to select all edges with any part of themselves at a given Z height ?
Do you want to select all edges with a start at a given Z height ?
Do you want to select all edges with an end at a given Z height ?
Do you want to select all of the selected faces' edges or include 'unfaced' edges too ?
etc

We could probably quickly hack something together, once it's clarified...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: REQ - Select by Z?

Postby EarthMover » Fri Jul 17, 2009 3:19 pm

Thanks TIG! I guess there are a lot more variables than I considered.

In thinking about how it would work, a couple scenarios come to mind.

1) Click on a face or edge, then right click and choose "select similar by Z". The script would search and find all similar faces or edges that register at the same coordinate on the Z.

2) Another more interesting option, would be having the ability to draw out a selection rectangle that is locked on a plane. Similar to a section cut plane, or grid of some kind, that would be used to select everything coplanar that falls completely within that plane or grid. If you could then move or rotate that selection plane, you could align it on any Z height or angle and use it to select all that intersects it. Don't know if it's possible, but that would be an amazing tool.

As far as your questions-

Do you want a starting dialog to specify the Z value in [current units] ?
I think it would make more sense to select an existing entity and match the rest of the selection to that, or else you would have to spend time figuring out the height from zero, which may require a few steps and slow down the process.
Do you want to select all co-planar faces OR all co-normal [angle of slope] faces ? Do you want to treat any 'reversed' faces as being co-planar/co-normal ? Just co-planar would work for me, but I'm sure co-normal would be useful in some situations to some people. Yes, I would say reversed faces should be treated as co-planar.
Do you want to select all co-planar edges ? YES
Do you want to select all faces with any part of themselves at a given Z height ? NO
Do you want to select all faces with their lowest bounds at a given Z height ? No, but perhaps optionally. Might be useful for selecting everything above a certain height.
Do you want to select all faces with their highest bounds at a given Z height ? No, but perhaps optionally. Might be useful for selecting everything below a certain height.
Do you want to select all edges with any part of themselves at a given Z height ? No, can't think of a situation this would be useful for.
Do you want to select all edges with a start at a given Z height ? Yes, this would be useful
Do you want to select all edges with an end at a given Z height ? Yes to this also
Do you want to select all of the selected faces' edges or include 'unfaced' edges too ? Yes, unfaced edges too.
0
3D Artist at Clearstory 3D Imaging
Guide Tool at Winning With Sketchup
Content Creator at Skapeup
User avatar
EarthMover 
Premium Member
Premium Member
 

Re: REQ - Select by Z?

Postby TIG » Fri Jul 17, 2009 5:06 pm

I'll try at look at it some time next week...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: REQ - Select by Z?

Postby EarthMover » Fri Jul 17, 2009 6:06 pm

Thanks TIG!!!! I'm working on a tutorial for some new users on another forum that are continually having problems with getting certain faces to close. I thought this script would be particularly useful to select all the edges and faces on a certain plane, moving a copy of them to an open space, then running the stray lines plugin to identify any non co-planar lines.
0
3D Artist at Clearstory 3D Imaging
Guide Tool at Winning With Sketchup
Content Creator at Skapeup
User avatar
EarthMover 
Premium Member
Premium Member
 

Re: REQ - Select by Z?

Postby EarthMover » Sun Aug 30, 2009 2:01 am

Just wondering if this were possibly still in the works? TIG?

I had a few times this week that I needed to select all the faces at a given height and this script would've been very useful. No hurry, just wondering. Thanks!
0
3D Artist at Clearstory 3D Imaging
Guide Tool at Winning With Sketchup
Content Creator at Skapeup
User avatar
EarthMover 
Premium Member
Premium Member
 

Re: REQ - Select by Z?

Postby MartinRinehart » Sun Aug 30, 2009 3:31 pm

EarthMover wrote:I had a few times this week that I needed to select all the faces at a given height ...


Have you visited the Ruby Console? You could get this done there without waiting on a Ruby.
0
Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

MartinRinehart 
 

Re: REQ - Select by Z?

Postby TIG » Tue Sep 01, 2009 12:00 am

EarthMover wrote:Just wondering if this were possibly still in the works? TIG?

I had a few times this week that I needed to select all the faces at a given height and this script would've been very useful. No hurry, just wondering. Thanks!


Time flies when you are enjoying yourself... ;)

These are the lines of code you need...
Code: Select all
def selectfacesbyz()
  model=Sketchup.active_model
  ss=model.selection; face=ss[0]; ss.clear
  model.active_entities.each{|e|ss.add(e)if e.class==Sketchup::Face and e.bounds.min.z==face.bounds.min.z}
end#if

[Untested !]
Paste all of it into a selectfacesbyz.rb file, restart SUp and see what happens...
Usage:
Select a face... then in Ruby Console type/paste:

selectfacesbyz

it selects every face at same height.

You can make the menu by copying similar code ?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: REQ - Select by Z?

Postby EarthMover » Tue Sep 01, 2009 12:41 am

Thanks TIG! It indeed works. I tried this for adding to the menu as an option, but it didn't work. What am I missing?

Code: Select all
def selectfacesbyz()
  model=Sketchup.active_model
  ss=model.selection; face=ss[0]; ss.clear
  model.active_entities.each{|e|ss.add(e)if e.class==Sketchup::Face and e.bounds.min.z==face.bounds.min.z}
### Menu ###
    UI.menu("Plugins").add_item("Select Faces by Z"){selectfacesbyz}
end#if
0
3D Artist at Clearstory 3D Imaging
Guide Tool at Winning With Sketchup
Content Creator at Skapeup
User avatar
EarthMover 
Premium Member
Premium Member
 

Re: REQ - Select by Z?

Postby TIG » Tue Sep 01, 2009 10:09 am

Put the menu OUTSIDE of the def...end thus:
Code: Select all
def selectfacesbyz()
  model=Sketchup.active_model
  ss=model.selection; face=ss[0]; ss.clear
  model.active_entities.each{|e|ss.add(e)if e.class==Sketchup::Face and e.bounds.min.z==face.bounds.min.z}
end#def
UI.menu("Plugins").add_item("Select Faces by Z"){selectfacesbyz} if not file_loaded?(File.basename(__FILE__))
file_loaded(File.basename(__FILE__))

The file_loded bit ensures it only loads into menu if you reload the Ruby manually later...

You're now a scripter ! ;)

Next: test if ss[0], test if ss[0] is a Face etc and if not UI.messagebox()... "Must Select a Face First.."
0
TIG
User avatar
TIG 
Global Moderator
 

Re: REQ - Select by Z?

Postby EarthMover » Tue Sep 01, 2009 11:35 pm

TIG wrote:
Next: test if ss[0], test if ss[0] is a Face etc and if not UI.messagebox()... "Must Select a Face First.."


Would this work?
Code: Select all
def selectfacesbyz
   mo=Sketchup.active_model()
   ss = mo.selection()

   if ss.empty?
      UI.messagebox("Must Select a Face First")
   else
      mo.start_operation "selectfacesbyz"
0
3D Artist at Clearstory 3D Imaging
Guide Tool at Winning With Sketchup
Content Creator at Skapeup
User avatar
EarthMover 
Premium Member
Premium Member
 

Re: REQ - Select by Z?

Postby TIG » Tue Sep 01, 2009 11:43 pm

Yes, that's OK.
But I'd just use this:
Code: Select all
###...
if ss.empty? or not ss[0].class==Sketchup::Face
  UI.messagebox("Must Select a Face First...")
  return nil
end
### then rest of code assuming it does get past this test...

'return nil' simply stops the process...
Note how I also added a test to see if the first thing in the selection is not a Face...
You will winkle a script out of me bit by bit... ;)
0
TIG
User avatar
TIG 
Global Moderator
 

Re: REQ - Select by Z?

Postby EarthMover » Wed Sep 02, 2009 12:28 am

So kind my friend. Thanks for making me work for it! I'm looking through code to try and determine how to also have the selection apply to edges, but the variables for edges are greater. If I could figure out how to apply it to just work with edges that exist solely on an xy plane....
0
3D Artist at Clearstory 3D Imaging
Guide Tool at Winning With Sketchup
Content Creator at Skapeup
User avatar
EarthMover 
Premium Member
Premium Member
 

Re: REQ - Select by Z?

Postby TIG » Wed Sep 02, 2009 12:38 am

Code: Select all
edge.start.position.z==edge.end.position.z

is 'flat'
you could also get the lower value with
Code: Select all
edge.bounds.min.z
?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: REQ - Select by Z?

Postby EarthMover » Wed Sep 02, 2009 1:40 am

ss=model.selection; face=ss[0]; ss.clear

So I assume this lines tells sketchup if the selection is a face then process this line

model.active_entities.each{|e|ss.add(e)if e.class==Sketchup::Face and e.bounds.min.z==face.bounds.min.z}

And this says to add to the selection all other faces with the with z bounds.


To translate this to apply for edges, is it as simple as changing the name face to edges and defining it further with the xy constraint code you provided? I tried it a few different ways and I keep getting errors.
0
3D Artist at Clearstory 3D Imaging
Guide Tool at Winning With Sketchup
Content Creator at Skapeup
User avatar
EarthMover 
Premium Member
Premium Member
 

Re: REQ - Select by Z?

Postby TIG » Wed Sep 02, 2009 9:03 am

Correct - test that the entities are Edges...
Code: Select all
e.class==Sketchup::Edge

Then test to see if same height as edge=ss[0] ###you need to have got edge's min.z...
There are several ways of testing for entity types - the [probable] fastest is e.class==Sketchup::Edge but there are also
e.is_a?("Edge")
e.kind_of?("Edge")
e.typename=="Edge"

etc...
Now you can also try code to manipulate a selection so that say only edges or faces are left in it...
For example:
Code: Select all
ss.each{|e|ss.remove(e) if not e.class==Sketchup::Face}### leaves only faces
### OR
ss.each{|e|ss.remove(e) if not e.class==Sketchup::Edge}### leaves only edges
0
TIG
User avatar
TIG 
Global Moderator
 

Re: REQ - Select by Z?

Postby EarthMover » Wed Sep 02, 2009 12:20 pm

Code: Select all
def selectedgesbyz()
  model=Sketchup.active_model
  ss=model.selection; Edge=ss[0]; ss.clear
  model.active_entities.each{|e|ss.add(e)if e.class==Sketchup::Edge and e.bounds.min.z==edge.start.position.z==edge.end.position.z}
end#if
UI.menu("Plugins").add_item("Select Edges by Z"){selectedgesbyz} if not file_loaded?(File.basename(__FILE__))
file_loaded(File.basename(__FILE__))


Got this so far. Something is wrong in the syntax. Can you show me the error to my ways. I have no idea how the language works, but it's been a good mental exercise and I'd love to learn more. Thanks for your help.
0
3D Artist at Clearstory 3D Imaging
Guide Tool at Winning With Sketchup
Content Creator at Skapeup
User avatar
EarthMover 
Premium Member
Premium Member
 

Re: REQ - Select by Z?

Postby •BTM » Wed Sep 02, 2009 12:50 pm

EarthMover wrote:
Code: Select all
def selectedgesbyz()
  model=Sketchup.active_model
  ss=model.selection; Edge=ss[0]; ss.clear
  model.active_entities.each{|e|ss.add(e)if e.class==Sketchup::Edge and e.bounds.min.z==edge.start.position.z==edge.end.position.z}
end#if
UI.menu("Plugins").add_item("Select Edges by Z"){selectedgesbyz} if not file_loaded?(File.basename(__FILE__))
file_loaded(File.basename(__FILE__))


Got this so far. Something is wrong in the syntax. Can you show me the error to my ways. I have no idea how the language works, but it's been a good mental exercise and I'd love to learn more. Thanks for your help.

Well, first problem is that you capitalized edge in edge=ss[0]. Second, you can't have something like 'if a==b==c'. You have to seperate it into 'if a==b and a==c'. Here's a working example.

Code: Select all
def selectedgesbyz()
  model=Sketchup.active_model
  ss=model.selection; edge=ss[0]; ss.clear
  model.active_entities.each{|e|ss.add(e)if e.class==Sketchup::Edge and (e.bounds.min.z)==(edge.start.position.z) and (e.bounds.min.z)==(edge.end.position.z)}
end#if
UI.menu("Plugins").add_item("Select Edges by Z"){selectedgesbyz} if not file_loaded?(File.basename(__FILE__))
file_loaded(File.basename(__FILE__))
0

•BTM 
PluginStore Author
PluginStore Author
 

Re: REQ - Select by Z?

Postby TIG » Wed Sep 02, 2009 10:40 pm

Thanks - BTM ... all variables must start with a lower-case letter and test 'x==y and z==a' are both the correct way forward... We'' make a scripter out of EarthMover yet :lol:
0
TIG
User avatar
TIG 
Global Moderator
 

Re: REQ - Select by Z?

Postby EarthMover » Thu Sep 03, 2009 12:41 am

Thanks BTM - that makes sense and I follow the logic behind the code. Perhaps I will try and find time to learn the language. I am good at obsessing and not so good at multi-tasking, so it may have to wait till the snow is falling and my work slows down.

Regarding the script, it indeed is working. However, it is not properly defining the edges end bounds. The script is selecting any edge which has one of the their bounds (verticies) corresponding with the selection, so it is thus selecting also vertical lines and diagonal lines who's start bounds is on the Z in relevance to the selection. Any suggestions for further defining the end bounds so that the script will only select lines only completely on the same XY plane as the selection?
0
3D Artist at Clearstory 3D Imaging
Guide Tool at Winning With Sketchup
Content Creator at Skapeup
User avatar
EarthMover 
Premium Member
Premium Member
 

Re: REQ - Select by Z?

Postby •BTM » Thu Sep 03, 2009 2:07 am

EarthMover wrote:Thanks BTM - that makes sense and I follow the logic behind the code. Perhaps I will try and find time to learn the language. I am good at obsessing and not so good at multi-tasking, so it may have to wait till the snow is falling and my work slows down.

Regarding the script, it indeed is working. However, it is not properly defining the edges end bounds. The script is selecting any edge which has one of the their bounds (verticies) corresponding with the selection, so it is thus selecting also vertical lines and diagonal lines who's start bounds is on the Z in relevance to the selection. Any suggestions for further defining the end bounds so that the script will only select lines only completely on the same XY plane as the selection?

Ah, here:

Code: Select all
def selectedgesbyz()
  model=Sketchup.active_model
  ss=model.selection; edge=ss[0]; ss.clear
  model.active_entities.each{|e|ss.add(e)if e.class==Sketchup::Edge and (edge.start.position.z)== (edge.end.position.z) and (e.bounds.min.z)==(edge.start.position.z) and (e.bounds.max.z)==(edge.start.position.z)}
end#if
UI.menu("Plugins").add_item("Select Edges by Z"){selectedgesbyz} if not file_loaded?(File.basename(__FILE__))
file_loaded(File.basename(__FILE__))
1

•BTM 
PluginStore Author
PluginStore Author
 

Re: REQ - Select by Z?

Postby EarthMover » Thu Sep 03, 2009 2:37 am

Thanks BTM! It's working great. I see defining the max bounds for the edges was the trick!
1
3D Artist at Clearstory 3D Imaging
Guide Tool at Winning With Sketchup
Content Creator at Skapeup
User avatar
EarthMover 
Premium Member
Premium Member
 

Re: [Plugin] Select by Z

Postby conconbrr » Sat Aug 07, 2010 12:55 pm

Hello,

I was searching for long for such a plugin. So, first of all thanks for it, it's quite useful to select all the contour lines at one level (topography).

I just wondered if it is possible to make a small improvement on the execution procedure.

In addition of the current method (select one edge or face and then execute the plugin), could it be possible to execute the plugin first and then enter a Z value on the VCB (I don't know if the name is correct, the little box on the right bottom ;)) and finally validate with "enter"?

In order to keep the current method, the general procedure could be:
1. Execute the plugin
2. Enter a value on the VCB OR select an edge or a face
3. Push "enter"

At each step some short information could be displayed on the status bar.

I just discover ruby and its power and unfortunately I don't really have the time to learn it so that I can make this modification.

Thank you
0

conconbrr 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Plugins

Who is online

Users browsing this forum: thinga, zul6041 and 24 guests

Visit our sponsors: