etjones/LiveParametric — Issue #20: Components and LiveParametric
Author: FrancisGerard
Created: 2012-02-27 20:28:22+00:00
State: open

Evan,
Thanks for your most recent reply. There is one issue you could maybe advise me on.
I'm having difficulty converting my LiveParametric objects into a component instance within the script.
Here are 2 short programs which show my problem. The non-component version works fine except I need to convert it to a component ( like a window or door would be). The component version produces an insert-able component but can't be edited. In a nutshell, how do I write the script so that I get an editable parametric component. The code in testy1.rb is based on windows.rb which ships as an example program with SketchUp.

class Testy2 < LiveParametric
# This script does not make a component but LiveParametric works.
@@decideWhichStr = "Pick a Number"

def default_variables
[
DropdownList.new( @@decideWhichStr,["1","2"],"1")
]
end

def create_entities( data, container)

decideWhich = data[@@decideWhichStr]
decideWhich = decideWhich.to_i
puts decideWhich

case(decideWhich)
when 1
puts("decideWhich is 1")
Testy2.drawBlocks1(container)
when 2
puts("decideWhich is 2")
Testy2.drawBlocks2(container)
end
end

def Testy2.drawBlocks1(container)
d = 100.cm
h = 100.cm
w = 100.cm
g = container.add_group

f = g.entities.add_face([0,0,0], [w,0,0], [w,d,0], [0,d,0])
f.pushpull(-h)

end

def Testy2.drawBlocks2(container)
d = 100.cm
h = 100.cm
w = 100.cm
g = container.add_group

f = g.entities.add_face([0,0,0], [w,0,0], [w,d,0], [0,d,0])
f.pushpull(h)

end

def Testy2.create
testy2 = Testy2.new
end

end

And the next script is :-

class Testy1 < LiveParametric
# This script makes a component but LiveParametric does not work.

def class_of_object
Sketchup::ComponentInstance
end
def create_entity(model)
#TODO: try to find existing definition matching the parameters
@entity = model.definitions.add self.compute_name

# Set the behavior
behavior = @entity.behavior
behavior.is2d = true
behavior.snapto = 0
behavior.cuts_opening = true
@entity
end

@@decideWhichStr = "Pick a Number"

def default_variables
[
DropdownList.new( @@decideWhichStr,["1","2"],"1")
]
end

def create_entities( data, container)

decideWhich = data[@@decideWhichStr]
decideWhich = decideWhich.to_i
puts decideWhich

case(decideWhich)
when 1
puts("decideWhich is 1")
Testy1.drawBlocks1(container)
when 2
puts("decideWhich is 2")
Testy1.drawBlocks2(container)
end
end

def Testy1.drawBlocks1(container)
d = 100.cm
h = 100.cm
w = 100.cm
g = container.add_group

f = g.entities.add_face([0,0,0], [w,0,0], [w,d,0], [0,d,0])
f.pushpull(-h)

end

def Testy1.drawBlocks2(container)
d = 100.cm
h = 100.cm
w = 100.cm
g = container.add_group

f = g.entities.add_face([0,0,0], [w,0,0], [w,d,0], [0,d,0])
f.pushpull(h)

end

def Testy1.create
testy1 = Testy1.new
definition = testy1.entity
Sketchup.active_model.place_component definition, true
end

end

Thanks for any help you can give me with this.

Francis