Changing View with Ruby
-
I want to create some 2D section rubies, which require either a front/back or right/left orientation
to be set at the time the ruby is run. How do I incorporate the correct statement?Sketchup.send_action(CMD_VIEW_RIGHT).....does not work!
Sketchup.send_action(viewFront) .....does not work!
Sketchup.send_action(viewFront:).....does not work!Help!
-
tomot - use a String (quotes)
Sketchup.send_action("viewFront:")
-
Note as the API doc says... the enclosing
"..."
AND a terminating':'
Sketchup.send_action(****"****viewFront****:"****)
-
tomot.. are you on a Mac?
(It would help if you put your OS and Sketchup version into your profile, so it's displayed beneath your name on every post.)
This thread belongs in the Developers forum.
-
I'll move it...
EDIT: Moved! -
@dan rathbun said:
tomot.. are you on a Mac?
(It would help if you put your OS and Sketchup version into your profile, so it's displayed beneath your name on every post.)
This thread belongs in the Developers forum.
Done!
-
Is there a reason why the following Sketchup.send_action("viewFront:") code will work only under def initialize ?
def initialize (some code and dialog boxes) if( $view == "Front" ) Sketchup.send_action("viewFront;") $orient = Geom;;Vector3d.new(0,1,0) $normal = Geom;;Vector3d.new(0,1,0) end #if end #end initialize
But using Sketchup.send_action("viewFront:") code under def create_geometry(p1, p2, view) will not work....why?
def initialize (some code and dialog boxes) end #end initialize def create_geometry(p1, p2, view) if( $view == "Front" ) Sketchup.send_action("viewFront;") $orient = Geom;;Vector3d.new(0,1,0) $normal = Geom;;Vector3d.new(0,1,0) end #if end #end create_geometry
-
Well, first of all, what kind of class are you writing ?? A
Sketchup::Tool
class or just a generic class (a subclass ofClass
?)Secondly... your breaking a cardinal rule of global variables. DO NOT create them only for use by one single plugin, or for only YOUR own use.
Create either Constants, or Module or Class variables, within YOUR namespaces. (That way they will not conflict with other sloppy scripts that are using globals of the same name.)Thirdly... when you write a class... and create an instance of that class, your class's constructor method, usually named
new()
, automatically calls theinitialize()
method WITHIN the newly created instance.This is why you get an automatic change in the view to "Front", when you make a new instance of your class in the first example, and not in the second.
-
@dan rathbun said:
Secondly... your breaking a cardinal rule of global variables. DO NOT create them only for use by one single plugin, or for only YOUR own use.
Create either Constants, or Module or Class variables, within YOUR namespaces. (That way they will not conflict with other sloppy scripts that are using globals of the same name.)My bad! I only use global variables to confirm values in the Ruby console, If the console could evaluate @ variables I would never, never ever use $ variables.
Advertisement