Add_face from edges??
-
Hi, I'm pretty new to ruby coding in sketchup so i'm just trying to get my head around a few bits of basic code. I'm trying to make a face from two straight edges and a curve.... the edges are drawing fine but i'm getting an error when I try to make a face from the edges??
this is my code atm...
%(#004080)[radius =10
startangle =90.degrees
endangle =0.degreescenterpoint = Geom::Point3d.new
vector = [0,0,1]
vector2 = [1,0,0]
vector3 = vector.normalize!
model = Sketchup.active_model
entities = model.active_entities
curve = entities.add_arc centerpoint, vector2, vector3, radius, endangle, startangleedge1 = entities.add_edges [0,0,0],[0,radius,0]
edge2 = entities.add_edges [0,0,0], [radius,0,0]
face = entities.add_face (edge1,curve,edge2)]In the API documentation it says I should be able to make a face from a bunch of edges...
%(#0000BF)[entities.add_face(edge1, edge2, edge3, ...)
entities.add_face(edgearray)
entities.add_face(pt1, pt2, pt3, ...)
entities.add_face([pt1, pt2, pt3,...])
entities.add_face(curve)]Does anyone know why this won't work?
Thanks in advance
Matt
-
@wawmsey7 said:
Hi, I'm pretty new to ruby coding in sketchup so i'm just trying to get my head around a few bits of basic code. I'm trying to make a face from two straight edges and a curve.... the edges are drawing fine but i'm getting an error when I try to make a face from the edges??
this is my code atm...
%(#004080)[
radius =10 > startangle =90.degrees > endangle =0.degrees > > centerpoint = Geom;;Point3d.new > vector = [0,0,1] > vector2 = [1,0,0] > vector3 = vector.normalize! > model = Sketchup.active_model > entities = model.active_entities > curve = entities.add_arc centerpoint, vector2, vector3, radius, endangle, startangle > > edge1 = entities.add_edges [0,0,0],[0,radius,0] > edge2 = entities.add_edges [0,0,0], [radius,0,0] > face = entities.add_face (edge1,curve,edge2)
]
In the API documentation it says I should be able to make a face from a bunch of edges...
%(#0000BF)[entities.add_face(edge1, edge2, edge3, ...)
entities.add_face(edgearray)
entities.add_face(pt1, pt2, pt3, ...)
entities.add_face([pt1, pt2, pt3,...])
entities.add_face(curve)]Does anyone know why this won't work?
Thanks in advance
Matt
The problem is that you have a mixture of edges and an edge array. It will work if you combine them into a single array
face = entities.add_face (edge1+curve+edge2)
For future reference, always use a code block to simplify the selecting and copying.
-
thanks for your quick response, that worked perfectly!
-
You should also be able to use Ruby's parameter expansion operator
*
.
It expands arrays into parameter lists:face = entities.add_face(edge1,*curve,edge2)
Also, do not put a space between the method name and the opening parenthesis when making method calls. (Ruby 2.0 will generate an error, whereas Ruby 1.8 just spit out a warning.)
-
Thanks.
Just another quick one...
I'm also struggling to make a simple rotation on an edge
my code atm is...
model = Sketchup.active_model entities = model.active_entities edge1 = entities.add_edges [0,0,0], [0,10,0] tr = Geom;;Transformation.rotation([0,0,0],[0,1,0],40.degrees) edge1.transform!(tr)
again the edge draws fine but my rotation code throws up an error!
anyone got any ideas?
Thanks again
Matt -
@wawmsey7 said:
Thanks.
Just another quick one...
I'm also struggling to make a simple rotation on an edge
my code atm is...
model = Sketchup.active_model > entities = model.active_entities > edge1 = entities.add_edges [0,0,0], [0,10,0] > > tr = Geom;;Transformation.rotation([0,0,0],[0,1,0],40.degrees) > edge1.transform!(tr) >
again the edge draws fine but my rotation code throws up an error!
anyone got any ideas?
Thanks again
Mattrotation of an edge on the Y axis around the Y axis makes no sense.
.transform! is for groups,components,vectors,points,etc. but not edges.
model = Sketchup.active_model entities = model.active_entities edge1 = entities.add_edges [0,0,0], [0,10,0] #tr = Geom;;Transformation.rotation([0,0,0],[0,1,0],40.degrees)#rotation around Y axis? tr = Geom;;Transformation.rotation([0,0,0],[0,0,1],40.degrees) #edge1.transform!(tr)#transform! not allowed for edge. entities.transform_entities(tr,edge1)
-
thanks again for your help - that makes a lot more sense!
-
@wawmsey7 said:
> edge1.transform!(tr) >
again the edge draws fine but my rotation code throws up an error!
Matt, have the Ruby Console open when testing code, and paste the error message in the post, if your asking about Ruby errors.
The first error message line in the backtrace will contain a sub-string like:
“filename:lineNo: in
method'”or
“filename:lineNo.”`
which tells you exactly what ruby script, it's line number, and possibly the method that it occurred within.The message tells you (usually) exactly what went wrong.
For example,
Error: #<NoMethodError: undefined method
transform!' for #Sketchup::Edge:0x00000009e8e690>... tells you that the
Sketchup::Edgeclass has no instance method named "
transform!`".So at that point your quickest way to resolve your dilemma, is to go to the API's Method index, and find methods in the "T" category that have to do with transformations.
See Exception class, backtrace() method.
And more generally dealing with exceptions.
Advertisement