Problems defining a method
-
I am encountering an mysterious issue while defining a method.
Code goes as follows:mod = Sketchup.active_model # Open model ent = mod.entities # All entities in model sel = mod.selection # Current selection u = [1,0,0] apoint = [1,0,0] face1 = sel[0] def classifiy(u, point1, face1) # σημείο προβολής pt = Geom;;Point3d.new pt result = faces_array[0].classify_point(pt) ent.add_cpoint pt if result == Sketchup;;Face;;PointOutside UI.messagebox(pt.to_s + ' is outside the face') elsif result == Sketchup;;Face;;PointInside UI.messagebox(pt.to_s + ' is inside the face') elsif result == Sketchup;;Face;;PointOnVertex UI.messagebox(pt.to_s + ' is on a vertex') elsif result == Sketchup;;Face;;PointOnEdge UI.messagebox(pt.to_s + ' is on an edge of the face') elsif result == Sketchup;;Face;;PointNotOnPlane UI.messagebox(pt.to_s + ' is not on the same plane as the face') end result end classify (u, apoint, face1)
I get an error:
@unknownuser said:Error: #<SyntaxError: C:/my_path.../3.rb:27: syntax error, unexpected ',', expecting ')'
classify (u, point, face1)^
C:/ProgramData/SketchUp/SketchUp 2014/SketchUp/Plugins/test.rb:27: syntax error, unexpected ')', expecting '='
classify (u, point, face1)^>
<main>:in
load' <main>:in
<main>'
-e:1:in `eval'
nilWhy is this happening? Other methods with multiple arguments work just fine..
I cant figure this out on my own.. Can anyone help? -
hi you have a spelling typo...
and a couple of things outside of scope.
once the typo is fixed, the errors show the scope issues
mod = Sketchup.active_model # Open model @ent = mod.entities # All entities in model sel = mod.selection # Current selection u = [1,0,0] apoint = [1,0,0] face1 = sel[0] def classifiy(u, point1, face1) # σημείο προβολής pt = Geom;;Point3d.new #pt result = face1.classify_point(pt) @ent.add_cpoint pt if result == Sketchup;;Face;;PointOutside UI.messagebox(pt.to_s + ' is outside the face') elsif result == Sketchup;;Face;;PointInside UI.messagebox(pt.to_s + ' is inside the face') elsif result == Sketchup;;Face;;PointOnVertex UI.messagebox(pt.to_s + ' is on a vertex') elsif result == Sketchup;;Face;;PointOnEdge UI.messagebox(pt.to_s + ' is on an edge of the face') elsif result == Sketchup;;Face;;PointNotOnPlane UI.messagebox(pt.to_s + ' is not on the same plane as the face') end #result end classifiy(u, apoint, face1)
john
-
Thank you John. I actually worked it out after trying really hard to see whats going wrong.
I guess you can see I am a starter in ruby scripting, though it is really fulfilling to see my code actually work! -
Your error message pointed to the last line in your code:
classify (u, apoint, face1)
I suspect it was the space between the method name and parentheses. Especially when you encounter syntax error it's good to go over your code and make sure the code style is consistent. Checking that there are no spaces between parentheses in method calls and making sure you have parentheses around all arguments etc.
Advertisement