Make box using Rectangle tool

def self.activate_rectangle_tool
  Sketchup.active_model.select_tool(RectangleTool.new)
  #and how to active face that is created by rectangle tool???
  face.pushpull(100.mm)
end

activate_rectangle_tool

I want to make box directly using rectangle(face)tool

Could you give me some help to edit code?

You can’t do this.
Simply put… your tool needs to add a face from 4 specified corner points, then use pushpull on that new face [taking into account the face’s normal which is not definable if z=0 and needs trapping for]

If already you have some API code to make a rectangle then use that and add on your pushpull code for the created face…

If you have the Rotated Rectangle Tool Example extension installed …

… then from within your extension’s namespace you’d need to call …

  Sketchup.active_model.select_tool(
    ::Sketchup::Samples::Rectangle::RectangleTool.new
  )

The reason that the Rotated Rectangle Tool Example extension can do this …

    UI.menu("Draw").add_item("Rotated Rectangle") {
        Sketchup.active_model.select_tool RectangleTool.new
    }

… is because it is making the call from within it’s own extension sub-module where RectangleTool is a locally defined constant identifier.

But outside that namespace, in your own namespace(s), you need to fully qualify the constructor method call.

However, this rectangle extension is an example and you would be better to change it to be within your own namespace modules, and perhaps modify it to dynamically extrude the box. (It would need to be renamed as a DrawBox tool.)


You can also see a parametric Box example (using a inputbox for dimensions) in the Community Shapes extension …

Extension:

Code:


1 Like