Skip to content

Instantly share code, notes, and snippets.

Created November 3, 2016 23:25
Show Gist options
  • Save anonymous/787eaf514c64bf43d074e56d4ce94e4c to your computer and use it in GitHub Desktop.
Save anonymous/787eaf514c64bf43d074e56d4ce94e4c to your computer and use it in GitHub Desktop.
Cube test class
# Cube test class
class Cube
attr_accessor :x, :y, :z
@@numberOfCubes = 0
def initialize
@x = 2
@y = 2
@z = 2
@isInModel = false
@refToModel = nil
@@numberOfCubes += 1
@thisCubeId = @@numberOfCubes
end
def drawToModel
model = Sketchup.active_model
# draw the cube to the model
pts = []
pts[0] = [0, 0, 0]
pts[1] = [@x, 0, 0]
pts[2] = [@x, @y, 0]
pts[3] = [0, @y, 0]
cube_definition = model.definitions.add("Test Cube")
cube = cube_definition.entities.add_face(pts)
cube.pushpull(-@z)
@refToModel = model.active_entities.add_instance(cube_definition, Geom::Transformation.new)
@isInModel = true
ModelRefContainer::insert(@refToModel, self)
end
def selectInModel
if @isInModel
puts "Selecting Cube from code"
selection = Sketchup.active_model.selection
selection.clear
selection.add(@refToModel)
end
end
def selectFromModel
puts "Selecting Cube #{@thisCubeId} class from Model!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment