Class: Sketchup::Procedure Abstract
| Relationships | |
| Inherits: | Object |
Overview
Implement the methods described in this class to create a procedure. Your subclass
must call super from its #initialize, passing in the necessary arguments.
To create a new procedure in Ruby, you must define a new class that implements its methods.
Register the instance of your procedure class via Sketchup::register_procedure.
Example:
class MyProcedure < Sketchup::Procedure
ID = 'my_company.my_extension.my_proc_id'
DESC = 'My procedure description.'
VERSION = 1
def initialize
super(id: ID, description: DESC, version: VERSION)
end
def validate(args)
# Return true if valid, or an array of error hashes.
true
end
def run(args)
# Return true on success, or an array of error hashes.
end
def (args)
# Return a hash mapping widget IDs to their desired enabled/visible states.
{}
end
end
my_proc = MyProcedure.new
Sketchup.register_procedure(my_proc)
Class Method Summary
-
.new(id:, description:, version:) ⇒ Procedure
constructor
All arguments are required.
Instance Method Summary
- #declare_params_and_ui(args) ⇒ String abstract
- #draw(args) ⇒ nil abstract
- #get_extents(args) ⇒ Geom::BoundingBox abstract
- #get_widget_states(args) ⇒ Hash{String => Hash} abstract
- #on_button_clicked(args) ⇒ Symbol? abstract
- #on_open_close(args) ⇒ nil abstract
-
#run(args) ⇒ Boolean, Array<Hash>
abstract
You should first clear the output entities.
- #validate(args) ⇒ Boolean, Array<Hash> abstract
Constructor Details
.new(id:, description:, version:) ⇒ Procedure
All arguments are required.
Instance Method Details
#declare_params_and_ui(args) ⇒ String
Called by SketchUp to get the parameter and ::UI declaration for this procedure.
#draw(args) ⇒ nil
(Optional) Called once per view refresh while the procedural component is open for editing, allowing the procedure to draw custom feedback into the view.
Since this method is called during drawing, it should run as fast as possible. Avoid slow computations and prefer simplified representations of the final geometry when possible.
#get_extents(args) ⇒ Geom::BoundingBox
(Optional) Called while the procedural component is open for editing to get the bounds of what #draw renders. Implement this if the preview can extend beyond the bounds of the component, which could otherwise leave it clipped out of the view.
Since this method is called during drawing, it should run as fast as possible. It is strictly observational and it must not draw or modify the model.
#get_widget_states(args) ⇒ Hash{String => Hash}
Called by SketchUp after the procedure ::UI is populated and after every parameter
change to determine the enabled/visible state of each widget. A procedure does not need to
implement this method if the widget states do not change.
#on_button_clicked(args) ⇒ Symbol?
(Optional) Called when the user clicks a button widget declared in this procedure's ::UI
(a widget with "widgetType": "button"). The procedure may perform arbitrary work against the
model in response. A procedure does not need to implement this method if it does not declare
any buttons.
If the handler modifies the model it should wrap the changes in its own operation using Model#start_operation and Model#commit_operation.
#on_open_close(args) ⇒ nil
(Optional) Called when this procedure's component is opened or closed for editing.
The :action argument distinguishes the two. This can be useful if the procedure needs to
activate a custom tool when its component is opened, for instance.
This method is strictly observational. Do not modify the model from within it and do not call Model#start_operation / Model#commit_operation. It can be called while undoing or redoing an open/close and always runs inside the open/close operation.
#run(args) ⇒ Boolean, Array<Hash>
Called by SketchUp to execute the procedure.
You should first clear the output entities. Then validate the control geometry and parameters (you can call your own #validate method for this). If the input is invalid, return errors as appropriate. And finally generate the output geometry.
This method will be called with an operation already started by the framework. Do not explicitly call Model#start_operation and Model#commit_operation from within this code.
#validate(args) ⇒ Boolean, Array<Hash>
Called by SketchUp to check if the given input entities can form a valid procedural component.
Do not make model modifications within this method. Also do not call Model#start_operation and Model#commit_operation.