amazing how easy things are sometimes.
guess i have a long way to go
thanks!
D
amazing how easy things are sometimes.
guess i have a long way to go
thanks!
D
Hey all.
One day, I'll get good enough at this to offer help instead of only asking question.
But for now:
I would like to be able to use variables from one function inside a different function. Please forgive my poor scripting - but as an example...
module Plugin
unless file_loaded?("program.rb")
mymenu = UI.menu('Plugins').add_submenu('test')
mymenu.add_item('Test Program') {self.Box}
mymenu.add_item('Test Program 2') {self.Circle}
file_loaded("program.rb")
end #unless
def self.Box()
a = 5
b = 6
c = a * b
end #Box
def self.Circle()
d = 12
e = d * a ##this won't work of course, because (a) is not defined within this function... how do you pull the value of (a) from Box?
end #failCircle
end #module
Thanks much!
Derek
I moved the vol.erase! line to just after
vol.set_attribute("Volume","Tag",true) ### v1.8
in Volume::process
and it seems to be working.
Is there something between
vol.set_attribute("Volume","Tag",true) ### v1.8
and the end of that defwhich makes volno longer available?
D
I spoke too soon!!!!
I think I followed your instructions well (though, I don't rule out user error) - but when I run the script and actually pay attention I noticed that the volume and text are NOT being deleted.
In the ruby console I get an error that:
Error: #<NameError: undefined local variable or method `vol' for Volume:Class>
Have I put the vol.erase! line in the wrong place? I located it, as you said, just before the Process code ends.
Any ideas?
Thanks
D
Hey folks.
I've been messing around with the VolumeCalculator21 plugin, trying to figure out what controls the addition of the copied volume to a new layer. I'd like to have the plugin NOT create the new layer and copied volume (or, alternatively, delete them after they are created and used).
Is there a way to delete a layer and its contents from within ruby?
Can anyone tell me which lines of this plugin are "copying" the selected volume into the newly created layer within the plugin?
I've attached the plugin for reference.
Thanks!
Derek
Hey folks,
I've searched around, and I'm sure I missed an easy answer - but how can you determine the operating system of a computer within a ruby script? I really just want to know if whoever is using my plugin is on a Mac or PC - is this possible?
Thanks much, as always!
Derek
I've searched the web for quite some time now, stumbling over the various explanations on how to import CSV files into arrays in Sketchup's Ruby.
I think, if it's possible, I just need a dumbed down explanation on how to do it; my Ruby force is very very weak.
Let's say I have the following as a CSV:
1,2,3,4,5
yes,no,2
I would like to then create an array to hold each of the rows of values, such that I end up with:
array_1 = [1, 2, 3, 4, 5]
array_2 = ["yes", "no", 2]
When I follow http://groups.google.com/group/sketchupruby/browse_thread/thread/d25a302dece3b21b/7c11cb4541613773?lnk=gst&q=foltz+csv#7c11cb4541613773
using:
csv_data = []
f = File.open(path,'r')
f.each_line{|line| csv_data.push line.split(",")}
I end up with:
csv_data = [["1.0", "2.0", "3.0", "4.0", "5.0\n"], ["yes", "no", "2.0\n"]]
note the end of line indicators still being present (\n)
Using the next line:
headers = csv_data.shift.map {|i| i.to_s }
returns:
headers = ["1.0", "2.0", "3.0", "4.0", "5.0\n"]
where headers[0] = 1.0, headers[1] = 2.0, etc.
That's pretty good.
The last line:
string_data = csv_data.map {|row| row.map {|cell| cell.to_s } }
returns:
string_data = [["yes", "no", "2.0\n"]]
where string_data[0] = ["yes", "no", "2.0\n"]
Not great.
using a similar line as for "headers":
headers2 = string_data.shift.map {|i| i.to_s }
gets me to:
headers2 = ["yes", "no", "2.0\n"]
Better,
but still with that pesky \n.
Is there a better way to do this? And how do I avoid the \n?
What about if there are more than 2 lines?
I looked over Jim Foltz/Dan Rathbun's method, but I don't understand the code well enough to manipulate the parts that I want to use (it includes an IO schmealy that I'm not familiar with).
Any hints would be greatly appreciated. Thanks much as always!
Derek
Hello!
I have two questions:
Is it possible to have check boxes (instead of fill-in-the-blanks or drop-down lists) in the UI input box in SketchUP?
Is it possible to have two UI input boxes open at one time (as in, clicking on something in one UI box will open another input box, which must be closed before the first UI box can be manipulated again) ?
As always, thanks!!!
Derek
Hey all.
I have a general understand of how to move entities using transformations.
But here's what I don't know how to do.
I have a group.
group_shell=model.active_entities.add_group()
ents=group_shell.entities
points_box=[[0,0,0],[5,0,0],[5,10,0],[0,10,0]]
face_box=ents.add_face(points_box)
face_box.pushpull(-20)
I'd like to make a copy of that group and move it to a different location. (I want two identical boxes sitting next to each other)
(yes, it's more complicated than just a box )
That's it.
Any hints?
Thanks!
Derek
I knew it had to be easy.
Speaking of which - does anyone have recommendation for good learning resources, that I might at some point get to asking useful questions?
Thanks a bunch for all the help!
Derek
Bit of an update:
I've hacked my "plugin" a bit more.
Can't figure out how to "paint" an object, though.
I want the initial rectangle to be translucent glass. The box doesn't need to have any special material assignment.
Any tips for assigning a material to an entity if that material is not in the model already?
And by creating the box after the "window" - will the translucency be lost?
(TO DO: Learn how to create layers. Learn how to set entity attributes like layer.)
I'll keep trying
Derek
Well - it's never as simple as that.
Using sketch_talk (can't find the post where it was mentioned, but the website where it lives is http://www.martinrinehart.com/models/tutorial/tutorial_11.html I managed to stitch together another program that can call sketch_talk, ask users for some inputs, create a box and a rectangle on the box based on the size of the box. (so many rectangles).
Let me begin by saying that I have never programmed in Ruby before (let alone any other language, really... a C++ class 10 years ago count?). Have mercy
This is the code in Sketch_Talk I can find related to creating a box and a rectangle.
def box( near, far, pushpull )
b = Box.new( near, far, pushpull )
b.draw()
return b
end # of box()
def draw()
Sketchup.active_model().active_view().invalidate()
end
def r( *args )
if args.length == 2
r = Rectangle.new( args[0], args[1] )
r.draw
return r
elsif args.length == 4
return face( args[0], args[1], args[2], args[3] )
else
raise "Command r requires two or four points."
end
end # of r()
class Box
=begin
A box is a rectangular parallelepiped; six faces, all rectangular, all meeting at right angles. A box is defined by near and far corners of a rectangle plus a distance to PushPull the rectangle, creating the box shape. If the rectangle is orthogonal, a positive PushPull is done toward the positive end of the perpendicular axis. All six faces of the box will face the outside of the box.
=end
attr_reader ;rectangle, ;pushpull_distance
def initialize( near, far, pushpull_distance )
@rectangle = Rectangle.new( near, far )
@pushpull_distance = pushpull_distance
end
def draw
@rectangle.draw()
@rectangle.face().pushpull( pushpull_distance )
end
end # of class Box
class Rectangle
=begin
A Rectangle is created from a near corner and a far corner.
The corners are [r,g,b] arrays.
An orthogonal rectangle is created, if possible.
The rectangle's @plane is one of 'rg', 'gb', 'br' or 'no' (Not Orthogonal).
An orthogonal Rectangle's normal points toward the positive end of the
perpendicular axis.
A non-orthogonal Rectangle's outside face will face the positive end
of the blue axis, except that Rectangles parallel to the blue axis face the positive end of the green axis.
=end
attr_reader ;near, ;far, ;plane, ;face, ;group
def initialize( near, far )
r = 0; g = 1; b = 2;
@near = near; @far = far
if near[r] == far[r]
@plane = 'gb'
elsif near[g] == far[g]
@plane = 'rb'
elsif near[b] == far[b]
@plane = 'rg'
else
@plane = 'no'
end
end # of initialize()
def draw( *args ) # args == none or optional group
corners = get_corners()
if args.length == 1
corners.insert( 0, args[0] )
end
@group = add_face_group( corners )
@face = find_face( @group.entities )
return @group
end # of draw()
def get_corners()
r = 0; g = 1; b = 2;
ret = []
ret[0] = @near
ret[2] = @far
if ( @plane == 'rg' ) || ( @plane == 'no' )
ret[1] = [ @near[r], @far[g], @far[b] ]
ret[3] = [ @far[r], @near[g], @near[b] ]
elsif @plane == 'gb'
ret[1] = [ @near[r], @near[g], @far[b] ]
ret[3] = [ @near[r], @far[g], @near[b] ]
else # @plane == 'rb'
ret[1] = [ @near[r], @near[g] ,@far[b] ]
ret[3] = [ @far[r], @near[g], @near[b] ]
end
return ret
end # get_corners()
end # of class Rectangle
And here's what I was messing around with last night:
########################
# blackbox.rb
########################
require 'sketchup'
load '/r/martins_sketch_talk2.rb'
#unless file_loaded?("blackbox.rb")
# mymenu = UI.menu('Plugins').add_submenu('Dereks #Plugin Collection')
# mymenu.add_item('Black Box Creator')
# {(Blackbox.new(true))}
# file_loaded("blackbox.rb")
#end
def boxes()
all
del
glazing_ratio = 0.5
building_height = 15.0
eW_NsRatio = 1.5
width = 25
inputs = [0,0,0]
prompts = ['Glazing Ratio;', 'Building Height;', 'EW to NS ratio;']
defaults = [glazing_ratio, building_height, eW_NsRatio]
inputs = UI.inputbox(prompts, defaults, 'blackbox')
glazing_ratio = inputs[0].to_f
building_height = 12*inputs[1].to_f
eW_NsRatio = inputs[2].to_f
width *= 12
#create initial box
box ([0,0,0], [width,width/(eW_NsRatio),0], building_height)
#add windows to front side based on glazing area
area_front = building_height * width
window_area_front = area_front * glazing_ratio
window_ratio = width/building_height
window_height = (window_area_front/window_ratio)**0.5
window_width = window_area_front/window_height
r ([(width-window_width)/2,0,(building_height-window_height)/2],[(width+window_width)/2,0,(building_height+window_height)/2])
end
# End of blackbox.rb
You'll note a bunch of things, I'm sure - but here are my most immediate questions:
The box and rectangle are each created as a group, but I can't understand from the code WHY they are created as a group. How would I change this? Even just exploding them after creation would be fine for me at this point...
I was trying to follow some other scripts to understand how one puts a plugin into the Plugins dropdown, but couldn't figure it out. Using the Ruby Code Editor plugin from this site - I got as far as you can see in the code above. But don't understand the {My_module::my_method} line (assume is has to do with "when you click on this - what is supposed to happen")
Finally - is there a way to set materials through a Ruby script? Let's say I wanted the box to be wood, but the rectangle to be glass, for instance
There you have it - I want to make a box with a window. Anyone feel like pointing a n00b in the right direction?
Great forum - btw.
Derek