My code is not running, and I don't know what is wrong

hi~I’m John,.
I try to make the face I select follow the specified path with ruby code, but it did not work.
what should i do?

mod = Sketchup.active_model 
ent = mod.entities 
edges = model.selection.grep(Sketchup::Edge)
face = model.selection.grep(Sketchup::Face)
path = edges
face.followme path

Tell us more.
What you have been selected and what exactly you want to achieve. Pictures, screenshots, screen records are welcome :wink:

Most probably when you are getting the edges

edges = model.selection.grep(Sketchup::Edge)

these are also will include the boundary edges of the face. If you wan to use the face.followme on a face and path with all edges, that will not work.


Ah. I just see also that you defined
mod = Sketchup.active_model

but you use other variable in 2nd and 3rd line (model)


Edit 2
Perhaps:

mod = Sketchup.active_model 
ent = mod.entities 
edges = mod.selection.grep(Sketchup::Edge)
faces = mod.selection.grep(Sketchup::Face)
path = edges.select{ |e| e.faces.size == 0 }
faces[0].followme path
2 Likes

It really helps everyone if you detail what isn’t working and what happened instead of the thing you expected to happen. Otherwise we have to guess

Looking at the code I’m guessing you are getting a NoMethodError when you call fade.followme, because you actually have an Array instead of a Sketchup::Face.

Instead of this:

face = model.selection.grep(Sketchup::Face)

You probably want:

face = model.selection.grep(Sketchup::Face).first

This is grabbing the first item in the enumerable that grep is returning.

thank you for you

Thank you for you advice.
I figure out what you’re trying to say
I think I need to use the same variable, and tell computer how to distinguish face and path next time.

Sorry,this is my fist time use the Community, I will tell more details next time.
I really appreciate the advice that you give me.

1 Like

Not sure I understood that. Here’s a complete snippet of what I mean:

model = Sketchup.active_model 
edges = model.selection.grep(Sketchup::Edge)
face = model.selection.grep(Sketchup::Face)[0] # Only change, I'm picking the first face
path = edges
face.followme path

image

The model variable have not been defined, as well as the followme will return false, because the path including the face boundary edges too.
Please check my snippet in my earlier post above. That will work. :wink:

1 Like

This topic was automatically closed after 186 days. New replies are no longer allowed.