ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
  • [info] Using Ruby Modules

    6
    0 Votes
    6 Posts
    3k Views
    Dan RathbunD
    Condensed, Simplified and Reposted from another topic thread. Modules are important and very necessary. If you (speaking generally to all readers and especially newbies,) do not understand the importance of modules, then you do not understand how Ruby operates and how code is (and should be,) loaded. Modules separate your code from other people's code, and prevent your code from "crapping" on the ObjectSpace (which is the same as "crapping" on everyone else's modules and classes, including Google's and Ruby's.) ANY script that defines methods, instance variables, class variables or constants in the ObjectSpace IS "crap." It does not matter if Google did it in their examples, it is still "crap." Not only should you be using A module around your script... you should be using nested modules. The outermost is your TOP_LEVEL namespace. Any tool or plugin you create should be in a nested module (submodule,) of your TOP_LEVEL namespace. This also allows individual tools or plugins to be removed from memory when they are no longer being used. (It also means Google incorrectly put their modules at the toplevel, when they should have been within module Google. What happens in the future when Layout gets an API, and/or Picasa gets a Ruby API that integrates to Sketchup and Layout? But that could be a whole other discussion topic.) Concerning indenting... anticpating a chorus of whiney voices, thus: "Oh man, nested modules mean I have to waste so much space on the left of my code, and push the "meat" of my rubies way to the right! And then I have to hit that TAB key all the time on every line... boohoo!" No you don't! Ruby allows multiple scope defintions ! If I wish to define a class within a submodule of my toplevel module, I can do so and only have 1 indent: # The Outer namespace modules must exist before referencing them. require('myfolder/MyTopLevel.rb') require('myfolder/myplugin/MyPlugin.rb') class MyTopLevel;;MyPlugin;;ThisClass def initialize(*args) # INIT CODE GOES HERE end # def end # class MyTopLevel;;MyPlugin;;ThisClass I can also save an indent when defining a plugin module by doing: # The Outer namespace module must exist before referencing it. require('myfolder/MyTopLevel.rb') module MyTopLevel;;MyPluginTwo class<<self private def method_one # .. code .. end public def method_two # .. code .. end # .. etc .. end # self end # module MyTopLevel;;MyPluginTwo EDIT: Ruby v1.8.0 does not allow the TopLevel scope operator prefix, ie: class **::**MyTopLevel::MyPlugin::ThisClass %(#4000BF)[v1.8.6 does allow it. It basically tells Ruby to start looking at the TopLevel for an indentifier, instead of backing up thru each nesting level from the current level. (I've removed the use of it in these examples, as many users will be running v1.8.0 on Win32, and not know how to update their Sketchup Ruby.)] instead of doing this: module MyTopLevel module MyPluginTwo class<<self private def method_one # .. code .. end public def method_two # .. code .. end # .. etc .. end # self end # module MyPluginTwo end # module MyTopLevel So choose a TopLevel namespace (module name,) that is unique. Use part of your surname. Or if your plugins will be distributed under a brand or company name, then that would be a good toplevel module name. Or you could use your SCF screen name, as long as it's unique. Just don't use a trademarked brandname(s) if your not the owner of the trademark!! Please do not use this thread to discuss issues relating to Using Ruby Modules, instead please use the talk thread: [talk] Using Ruby Modules
  • Right Click-&gt;Hide

    16
    0 Votes
    16 Posts
    829 Views
    K
    never mind i got it working, thanks for the help
  • Windowizer

    86
    0 Votes
    86 Posts
    8k Views
    3
    Can't wait for this window maker..I just made some 3d bricks....
  • Automating Sketchup from Excel

    6
    0 Votes
    6 Posts
    7k Views
    Dan RathbunD
    Here's another forum link along these lines: Excel to SU ( 29/7/08 version ) [has code for download]
  • Ruby scripts lack style

    24
    0 Votes
    24 Posts
    1k Views
    J
    @thomthom said: Watch it Jesse - behave yourself. You will get nowhere fast with this attitude. What attitude? @thomthom said: Chris has a very good point: where are your examples? Where is the work you have done for the community? Don't try to discredit me by questioning my resolve ThomThom. I have been preaching freedom to slaves on this list for ~1.5 years. I have been trying to open your minds to new possibilities, out of the box thinking styles, clean coding styles, better API, better languages, etc, etc. But most importantly i have tried to bring freedom to the slave mindset around here. @thomthom said: If you really want to be helpful and guide people - then start producing something yourself. Provide a starting point of what you want to achieve - then you might get people listening. Sure i want to help, but with all the negative energy why should i? Instead trying so hard to discredit me, how about saying Yes, i would like to help keep the code base clean and written in a proper style. Yes i would like to make the API better. Yes i would like to make the Docs better. @thomthom said: Right now, and given your history, I can't help but feel that you are trolling and have no intention do any other than that. I really hope you are not one of these people that are entertained by starting quarrels. I can't believe you would call ME a troll. All i have ever done was come here to help. Givin out my spare time and for what? Just because you don't agree with my statements does not mean i am a troll.
  • Any way to show/hide component axes via Ruby

    3
    0 Votes
    3 Posts
    697 Views
    DavidBoulderD
    Thanks! I would have searched a while for that.
  • Taking pictures with cameras

    20
    0 Votes
    20 Posts
    3k Views
    DavidBoulderD
    Ben, I had some time to post a video demonstrating how to use OpenStudio, EnergyPlus and ResultsViewer to study window shading over the entire year. The video doesn't have any annotation yet, but I'll add that soon. Below are some screenshots. The first is from SketchUp/OpenStudio. The color of the windows relate to the fraction of the window in the sun. While typically viewing simulation data in SketchUp is ideal, here the sketchUp shadows work well on their own. We can look at a window and see that about half of it is in the sun. In this case ResultsViewer's flood maps are an excellent way to study the entire year at a glance. You can quickly see which times of day or year are the problem times. I have shown a Type A and Type B window for the south and east. The Type A and B windows are the same except the Type A has the shade directly above it, while the Type B windows have the same shade offset five feet vertically. This is a simple example, but you can imagine how you can quickly study a variety of window designs and look at the strengths and weakness of each one. YouTube link (may not work yet) http://www.youtube.com/watch?v=60lmAnY81ds [image: jtrT_sunlitfraction_SUresults.png] [image: IFpv_win_type_b_south.png] [image: whm5_win_type_a_south.png] [image: duL8_win_type_b_east.png] [image: KtfZ_win_type_a_east.png]
  • Access OpenStudio with Ruby console

    10
    0 Votes
    10 Posts
    2k Views
    B
    Thanks !!!
  • InHalfspace?

    4
    0 Votes
    4 Posts
    331 Views
    Dan RathbunD
    Don't forget the Geom module methods. Geom.point_in_polygon_2D can be used to narrow down even further where the point is, once you know whether it's ventral (anterior) or dorsal (posterior.) For instance, reference your view from the other thread, where you show the viewing cone(s) looking downward. Getting the 3 vertices of the horizontal conic section defines a triangular face that can be used with Geom.point_in_polygon_2D, to see if a point should be within the projected section (without regard to z position.) Repeat the exercise using the vertical conic section, and if both return true, then the point is inside the viewing pyramid that curcumscribes the viewing cone.
  • Get Default Material

    3
    0 Votes
    3 Posts
    244 Views
    TIGT
    The default material is 'nil'. So face.material=nil makes face have no material and face.back_material=nil makes face have no back material You can get the color used for the two types of default face material from model.rendering_options["FaceFrontColor"] and model.rendering_options["FaceBackColor"] which both return a Color object, you can then get its RGB values in the normal way etc... You can also set these vales to a new color with []=
  • Anyone with non-english Sketchup?

    13
    0 Votes
    13 Posts
    2k Views
    TIGT
    @thomthom said: SketchUp reads GIF images - no problem. It's just the filedialog that doesn't list it. If you type * in the filename when you try to insert an image then you can select GIFs and it works. I can't select * as an image file-type, only from a list of types or 'all' - neither of which cover 'gif'. I know you can load a gif by renaming it as a png - though I never saw why it wasn't a supported image extension otherwise - Is being able to load a gif a Mac thing? Interestingly the gif renamed png works fine and is listed in the path and skm as a png and can be saved as png too ??? Gif-ness disappears completely on the rename??? I had this problem SKP file from someone that wouldn't export the texture properly [overlaid on this Dutch translation confusion I outlined earlier!] where in a material's texture in the SKM it was a gif BUT it said it was a png in the texture-path text-box on the dialog [or when you asked it what it was via the API] BUT it texture-wrote a gif as the output... caused presumably by a manual edit that confused it? I can't see how it became a gif inside the skm [unless it was manually edited as if a zip file] as making one my way it always says it's a png whatever way you slice it !
  • Strange warning from Face.vertices

    15
    0 Votes
    15 Posts
    767 Views
    AdamBA
    You can guard against not getting what you expect all you like, but once you get this kind of result, the internal structure of SU is toast. It always seems to comes down to Ruby coding errors on your part. I believe the issue is that (possibly for performance reasons?) SU isn't at all defensive in its API. You give it a bunch of crap and it dutifully carries on using it resulting in increasingly wrong behaviour. So if you ever enumerate winged edge structres etc and get crazy objects, don't guard against it, go back and find your mistake - and it can be a real PITA to find.. Adam
  • My First Plugin questions

    10
    0 Votes
    10 Posts
    470 Views
    J
    It did cross my mind that you could setup a DC for the entire house, but I feel that may get hairy, especially when working with Nested and/or Intersecting options. Also the fact that Free Users cannot author DC's is a draw back. I do want to take advantage of DC's for some optioning, but dont see it as an efficient solution for complex production homes. Thanks again for you help so far!!
  • Help for Macfriendlying a plugin (Jim's custom toolbar)

    3
    0 Votes
    3 Posts
    343 Views
    M
    Thanks! Yeah I know about the different files and such and this one is such a complex branched one, a beautifully programmed one. As for the sketchup API (toolbar, command and menu) I'm not 100% fluent yet, but getting there, already fixed many plugins. The thing is it seems to me that it's a difference in file behavior from the PC to the Mac, as if I understand comments made it behaves properly on the PC (looks in the plugin folder) but doesn't seem to on the Mac. Since Jim wrote it for PC there may be a quirk on Mac for which there is a way around that someone had already encountered. Of course I won't hack without backup and protections and what not, and without understanding the behavior of the original program, but I can only imagine what it does on a PC and see what it does or doesn't on the Mac. In this case the program and the UI work great. OK I know you're right I'll do more homework! Thanks for the links.
  • Module Wrapper for Your Ruby

    7
    0 Votes
    7 Posts
    730 Views
    Dan RathbunD
    @martinrinehart said: Your class names are not protected, even though your classes are defined in the module. Absolutely and totally WRONG ! A module namespace protects evrything inside it. It can have it's OWN constant of the same name as another constant in a higher namespace. The same for variables and method names. YOUR module can have a class Matrix, and MINE can have a class Matrix, and they are different. @martinrinehart said: By the way, your "xxx.rb" file provides a namespace wrapper for its variables. Next time you see Matz, ask him why its just for variables. Clarification: Only local_variables NOT instance_variables (@var), class_varaibles (@@avr) or Constants ( MSG, Value etc.) Running unwrapped code corrupts the ObjectSpace, with: Constants will be left behind in Object and become globally available. @vars will be left behind in Object and even when set nil, GC does not clean them up. @@vars will be left behind in Object and even when set nil, GC does not clean them up, AND worse... every class inherits them.
  • Instance @variable vs class @@variable

    19
    0 Votes
    19 Posts
    2k Views
    Dan RathbunD
    @martinrinehart said: @unknownuser said: Within the class statement, you can declare methods with their name, without any prefixing. I find Ruby's insistence on self.xxx to define module-level functions is quite a nuisance. On the other hand, if you create a singleton instance of your class, then to manipulate anything you have to instance.xxx() whereas in the module you can call your functions without a prefix. You don't need to prefix methodnames in modules. Use a class << self block wrapper around all the methods inside the module. See my post: [info] Using Ruby Modules
  • Entering components

    7
    0 Votes
    7 Posts
    1k Views
    Dan RathbunD
    @ben.doherty said: I am having lots of trouble with modules though, if I ask the ruby console for Voyeur::FaceMaker::instance_methods it gives me back a list of the methods as I'd expect, but if I say Voyeur::FaceMaker.makeAnalysisFaces it throws a #<NoMethodError.... any idea how to fix that? moved to it's OWN topic thread, so folks can find it easier: See: [info] Using Ruby Modules
  • Defining Length, Width and Thickness

    10
    0 Votes
    10 Posts
    804 Views
    D
    To update the changes - right click - Redraw! To sort the attributes as You like just put the alphabets in front: [image: 721C_2010-08-13_210132.jpg]
  • Webconsole NOT in #@$%&amp; Plugins folder

    7
    0 Votes
    7 Posts
    649 Views
    Dan RathbunD
    @archtobe said: I use a free image editor called: Paint.Net << Thanks! I used Windows Paint; crude but it does the trick. OH man... Paint.NET puts the MS-Paint to shame. MultiLayers, opens and saves in many more formats. Version 1 was a college programming project, by a group of guys. They did such a good job, (everyone loved it,) that they updated it, released, etc. etc. and it's up around ver 3 now.
  • Dynamic Component Length Parameters ???

    8
    0 Votes
    8 Posts
    769 Views
    D
    I also started to play with dynamic components as a way to put some info. But extracting all this information is a big pain - SketchUp's Generate report is a big mess - only inches and a lot of useless data!

Advertisement