Dan,
Thanks I finally got it to work using the code you provided.
Derek
Dan,
Thanks I finally got it to work using the code you provided.
Derek
TIG, what do you mean by "create them in the same module"?
@chris fullmer said:
create_submenu.add_item("PluginB")
That should do it!
The plugins are two separate ruby files plugina.rb & pluginb.rb. They load independently.
plugina.rb will load first and create the "Create..." submenu under "Plugins".
I'm just not sure how to code pluginb.rb to use the same submenu created in plugina.rb
I've developed a Plugin (PluginA) which creates a submenu called "Create..." under the main menu "Plugins"
plugins_menu = UI.menu("PlugIns")
create_submenu = plugins_menu.add_submenu("Create...")
create_submenu.add_item("PluginA")
Then I created a second separate plugin (PluginB) that I also want to place in the "Create..." submenu. I can't figure out how to place the second plugin (PluginB) in the submenu "Create...".
Anyone have any ideas?
Thanks
Derek
thanks, great explanation. I'm guessing nothing in parametric.rb is actually specifically changed to work with windows.rb and it is the windows.rb script that utilizes the methods and variables in the parametric.rb script. i'll keep working at it
so my question now is if I require another script, such as, parametric.rb does that mean it loads the script and allows me to pass methods and variables back and forth between the two scripts?
@tig said:
which looks suspiciously like the code for a context-menu ?
yeah i did another test and some how its passing the class name to parametric.rb but how? is it through the following code?
**```
def create_entity(model)
#TODO; try to find existing definition matching the parameters
@entity = model.definitions.add self.compute_name
@unknownuser said:
require 'parametric.rb'
Thanks I did check that and there was no sign of anything, I still have no clue.
@unknownuser said:
That code in the first post is the entire script?
Yup thats the entire script. sure it requires sketchup.rb and parametric.rb, but a lot of scripts do.
I downloaded it right from the google website Window Maker http://sketchup.google.com/download/rubyscripts.html
hey thanks I tried that and it worked... but when i look over this code I only see the context menu listed at the beginning as a comment. How does the script run it if it is only a comment? Is this script calling another external script that i am overlooking?
**```
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
Can someone explain to me what bit of code in this following script gives the user the ability to right click a component and edit its input variables? I have been looking this over for days and still can't figure it out.
# Copyright 2004-2005, @Last Software, Inc.
# This software is provided as an example of using the Ruby interface
# to SketchUp.
# Permission to use, copy, modify, and distribute this software for
# any purpose and without fee is hereby granted, provided that the above
# copyright notice appear in all copies.
# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#-----------------------------------------------------------------------------
# Name ; Window Maker 1.0
# Description ; A tool to create parametric Double Hung and Slider windows.
# Menu Item ; Tools->Windows
# Context Menu; Edit Window
# Usage ; Select window type and then specify the size.
# ; If the size needs to be changed after inserting into the model,
# ; right click on the window and select "Edit Window".
# Date ; 9/10/2004
# Type ; Dialog Box
#-----------------------------------------------------------------------------
# Classes for creating and editing parametric windows
require 'sketchup.rb'
require 'parametric.rb'
#=============================================================================
# Define the main parametric window class
class Window < Parametric
# Create windows as components rather than groups
def class_of_object
Sketchup;;ComponentInstance
end
def create_entities(data, container)
width = data["w"]
height = data["h"]
type = data["t"]
Window.create_window(width, height, type, container)
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
@@defaults = {"w", 4.feet, "h", 5.feet, "t", 0}
def default_parameters
@@defaults.clone
end
def translate_key(key)
prompt = key
case( key )
when "w"
prompt = "Width"
when "h"
prompt = "Height"
end
prompt
end
# Show a dialog and get the values from the user
# The default implementation of this in the Parametric class doesn't support
# having a popup list. Maybe I should consider adding something that would
# allow doing that in a more generic way.
def prompt(operation)
# get the parameters
if( @entity )
data = self.parameters
else
data = self.default_parameters
end
if( not data )
puts "No parameters attached to the entity"
return nil
end
title = operation + " " + self.class.name
prompts = ["Width", "Height", "Type"]
types = ["Double Hung", "Slider"]
values = [data["w"], data["h"], types[data["t"]]]
popups = [nil, nil, types.join("|")]
results = inputbox( prompts, values, popups, title )
return nil if not results
# Store the results back into data
data["w"] = results[0]
data["h"] = results[1]
t = types.index(results[2])
data["t"] = t ? t ; 0
# update the defaults values
if( not @entity )
data.each {|k, v| @@defaults[k] = v }
end
data
end
#-----------------------------------------------------------------------
# Create a rectangular face at a given location
def Window.rectangle(origin, width, height, container, close)
v1 = Geom;;Vector3d.new(width,0,0)
v2 = Geom;;Vector3d.new(0,height,0)
p1 = origin;
p2 = origin + v1
p3 = p2 + v2
p4 = origin + v2
edges = []
edges[0]=container.add_line p1, p2
edges[1]=container.add_line p2, p3
edges[2]=container.add_line p3, p4
edges[3]=container.add_line p4, p1
if( close )
f = container.add_face edges
else
edges
end
end
#-----------------------------------
# Create a simple rectangluar frame
def Window.simple_frame(p1, width, height, thickness, frameWidth, container)
# create a group for the frame
frame = container.add_group
v = Geom;;Vector3d.new(frameWidth, frameWidth, 0)
p2 = p1 + v
holeWidth = width - (2.0 * frameWidth)
holeHeight = height - (2.0 * frameWidth)
# Create the outer frame and the hole
outer = Window.rectangle(p1, width, height, frame.entities, true)
hole = Window.rectangle(p2, holeWidth, holeHeight, frame.entities, true)
hole.erase!
# Extrude the window
outer.pushpull(-thickness)
frame
end
#-----------------------------------
# Create a basic window
def Window.create_window(width, height, type, container)
depth = 3
outsideFrameWidth = 2.25
insideFrameWidth = 1.25
sliderThickness = 1.25
bHorizontal = (type == 1)
# Create the outer frame
pt = Geom;;Point3d.new(0,0,0)
Window.simple_frame(pt, width, height, depth, outsideFrameWidth, container)
# For a component to cut an opening it must have real geometry in it - not
# just groups, so create the cutting gometry
Window.rectangle(pt, width, height, container, false)
# Create the two sliding windows
z = ((depth - (2.0 * sliderThickness)) / 2.0) + sliderThickness
pt = pt + Geom;;Vector3d.new(outsideFrameWidth, outsideFrameWidth, z)
if bHorizontal
wh = (width - (2.0 * outsideFrameWidth)) / 2.0
w = wh + + insideFrameWidth
h = height - (2.0 * outsideFrameWidth)
else
w = width - (2.0 * outsideFrameWidth)
wh = (height - (2.0 * outsideFrameWidth)) / 2.0
h = wh + + insideFrameWidth
pt.y = pt.y + wh
end
Window.simple_frame(pt, w, h, sliderThickness, insideFrameWidth, container)
if bHorizontal
pt.x = pt.x + wh
else
pt.y = pt.y - wh
end
pt.z = pt.z + sliderThickness
Window.simple_frame(pt, w, h, sliderThickness, insideFrameWidth, container)
end
#-----------------------------------------------------------------------
# Prompt for parameters and then insert windows
def Window.create
window = Window.new
definition= window.entity
Sketchup.active_model.place_component definition, true
end
# add a menu with the window types
if( not $windows_menu_loaded )
UI.menu("Tools").add_item("Windows") { Window.create }
$windows_menu_loaded = true
end
#-----------------------------------------------------------------------
end # module Window