sketchucation logo sketchucation
    • Login
    1. Home
    2. MSP_Greg
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    M
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 46
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Arrange component names

      siim11s,

      The previous code I posted didn't allow for name collisions. Below code should allow for it. Also added a few comments...

      
      # reInc checks for match of three digits at beginning of string,
      # loads digits into $1, rest of name into $2
      reInc = /^(\d{3})(.+)/
      
      if (reInc.match(inp[0]))
        # sort reverse so name colisions won't occur
        cds.sort! { |a,b| b.name <=> a.name }
      
        # initialize loop variables
        iPre = $1.to_i
        iCD = 0
      
        cds.each { |cd|
          if (reInc.match(cd.name))
            iCD = $1.to_i + 1
            # since we're reverse sorted, break when we reach low numbers
            break if iCD <= iPre
            cd.name = "%03d#{$2}" %iCD
          end
        }
        new.definition.name = inp[0]
      end
      
      # for testing, use below to resort & output new names
      cds.sort! { |a,b| a.name <=> b.name }
      cds.each { |cd| puts cd.name }
      
      

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Arrange component names

      Try the following (based on SDMitch's code)

      
      mod = Sketchup.active_model
      ent = mod.active_entities
      sel = mod.selection
      cds = mod.definitions.reject{|cd|cd.group?||cd.image?}
      prefix=('%03d' % cds.length)
      new=sel.first;new_name=prefix+' - '+new.definition.name
      inp=UI.inputbox(["New Name;"],[new_name],"Rename #{new.definition.name}")
      reInc = /^(\d{3})(.+)/
      if (reInc.match(inp[0]))
        new.definition.name = inp[0]
        iPre = $1.to_i
        iCD = 0
        cds.each { |cd|
          if (reInc.match(cd))
            iCD = $1.to_i + 1
            cd.name = "%03d#{$2}" %iCD if iCD > iPre
          end
        }
      end
      
      

      As long as the cd name begins with three numbers...

      Note - no testing for prefixes greater than 999, and no testing for duplicate names after the increment.

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Material, Layer, Color, Alpha

      Dan,

      @dan rathbun said:

      Greg you have been "ignored" because you are a troll. You have a total of 23 posts here. I have near 5000! You are both incorrect and insignificant.

      As I stated, condescending.

      The fact that I choose to spend my free time away from computers doesn't really have any bearing on what I know or what I've said.

      I don't recall there being a relationship between quantity and quality regarding forum posts. Most forums always have a few people who feel their (often newfound) knowledge is so unique and authoritative that they post to almost every thread...

      Please enlighten me and post a link to anywhere on the Internet that says something similar to your statement 'there are no properties in Ruby.'

      Same thing goes for the statement 'Most methods return new objects.' By the way, you use the word 'new.' Since you've mixed it up before, are you referring to a new object like material.color, or a reference to a child object like Sketchup.active_model.entities?

      You've misused many programming terms that have relatively standard definitions, and, as I've stated previously, you conflate Ruby and the SU API. I'd suggest you do some reading and join some other programming forums/lists.

      BTW, my 'Design Patterns' book by the 'Gang of Four' is 2nd printing. I think it's currently at the 40th (or more) printing. Do you have a copy?

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Material, Layer, Color, Alpha

      Dan,

      Your first post started with 'Not so fast', then mentioned referenced objects, 'really ticked off people', and a few other interesting phrases like 'Ruby does exactly what you ask it to do (unless you ask incorrectly.)'

      Now you've taken a different tack.

      Your subsequent posts state –
      My quick reply is that Ruby does NOT have "properties".
      Why don't you see any change?
      Because this proves my point that there are no properties in Ruby.
      If this seems weird, then it's just the way Ruby is.

      Regarding properties, methods, etc, I suggest you Google “properties vs methods”, as the distinction you're making is pointless and in error. Also, 'by reference' and 'by value' can apply to properties or methods.

      You're mixing together the Ruby programming language and the SU API. Much of what you've said about Ruby is incorrect (or really applies only to the SU API), and your programming terminology is, at a minimum, odd. If you feel I'm mistaken, I'd suggest you read a few books on API / class design and OOP programming. You might also study other API's like the javascript DOM API, or the .NET API.

      As an example, you've mentioned 'instance.' 'Instance' is applicable to programmers and designers of classes and API's, as is the term class (or static.) Users of API's rarely would use the term, as they are restricted to whatever the API allows, and aren't concerned with its internal implementation.

      Regarding all of your 'ideas' about the color object (especially 'amMats["Audience"].color!.blue= 255'), they are strange. Plain and simple, color is a property of the material object, and AFAIK, no ruby properties use the “!” symbol, which is always used with methods that change an object. Big difference. The “!” symbol is used as a shortcut to self re-assignment, which is common in many languages, and can also be used in Ruby. IOW, the following are identical –

      someArray.sort!
      someArray = someArray.sort

      It can also used when 'method chaining', but many programmers would prefer separate statements.

      You've contributed a lot to this forum, but IMHO, many of your posts are argumentative, condescending and off topic. Please try to improve your signal to noise ratio...

      Finally, API's are messy. Once something is added to one, it needs to be supported essentially forever. There have been many times where I wish the SU API was laid out differently (more like the DOM or .NET API's), but we and the SU dev team are stuck with it. Additionally, the SU API is designed with an eye towards being used by people who are not hardcore programmers. That shouldn't prevent discussions about how it might change or be improved. Let's just try to have good, on topic discussions.

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Material, Layer, Color, Alpha

      @dan rathbun said:

      Not so fast.

      material.color does not return a property. It returns a reference to a separate Ruby object, which can be shared across multiple Sketchup::Drawingelement subclass instances.

      Hmmm. Sorry if I confused you. I don't believe I said that anything returned a property. Color is a property of the material object.

      @dan rathbun said:

      If changing the alpha upon a material object, changed every object that also referenced that color object, there would be some really ticked off people (both users and programmers alike.)

      Ticked off. I hate that.

      First of all, the color property returns a color object, but it is not a reference to it; it is a new color object loaded with the values of the material's 'internal' color object. As such, color objects behave more like values, hence, when setting a color property to a color object, a reference is not created, the color object's values are just copied. Nothing changes with the following code --

      ` amMats = Sketchup.active_model.materials
      oColor = amMats["Audience"].color
      oColor.blue = 255

      below also does nothing

      amMats["Audience"].color.blue = 255`

      Hence, your example...

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Material, Layer, Color, Alpha

      Note to self – don’t compose messages when reorganizing code object structures.

      Rephrasing my original post

      The following returns a correct value –

      Material.alpha

      The following DO NOT return the correct value –

      Material.color.alpha
      Material.color.to_a[3]

      Layer.color.alpha
      Layer.color.to_a[3]

      The following do not return correct value for the ‘A’ string

      Material.color.to_s
      Layer.color.to_s

      I think it would be helpful the three color properties that return alpha information worked with both material and layer, returning the opacity...

      Thanks,

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • Material, Layer, Color, Alpha

      First of all, I’d like to thank the Trimble team for the updates to the SU Ruby API.

      Regarding color, alpha, materials, and layers, I’ve found the following –

      1. The Color object has alpha properties (getter & setter.)

      2. Material object – the color property/object does not have a alpha property matching the material. The material object does have an alpha property.

      3. Layer object – the color property/object does not have a alpha property matching the layer. The layer object does not have an alpha property.

      It would be helpful if both the layer.color and material.color objects’ corresponding alpha properties matched the opacity of their parent objects.

      Thanks,

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Paste between instances and onLayerAdded issue

      Have you tried pasting with only one new layer?

      I just checked in my code, and as you probably know, onLayerAdded is called for each new layer. This may be causing issues because you may have more than one start_operation beginning but not yet commited as the multiple calls to onLayerAdded are made.

      I'd try puts statements inside onLayerAdded and also inside start_operation and see if that's the issue.

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • Safe place to store user-defined parameters, Pt 2, bug?

      To all,

      Well, back to the user data/options/preferences storage issue. I use an ini that is included with the plugin I author.

      The previous thread

      http://sketchucation.com/forums/viewtopic.php?f=180&t=52730

      was interesting, especially the info posted by thomthom about Unicode issues.

      I wasn’t that concerned with most of the discussion, since with Vista, 7 and probably 8, windows will create a file in the VirtualStore if one writes to the ini file. This works in both SU7 & SU8. If someone is still using XP, I assume they’re probably using an admin user account.

      So I’m testing the code with SU2013. It does not save a file to the VirtualStore, and generates an error if you try to write to the file.

      Also interesting, in SU2013, the Ruby code

      File.writable?(sIniFile) returns true, but the following line

      File.open(sIniFile, "w") generates an error.

      More interesting is that SU8 and SU2013 appear to use the same version of msvcrt-ruby18.dll.

      Has anyone noticed this issue?

      Thanks,

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: SU 2013 not allowing SU 8 to run plugins!

      If you are using a Windows system, believe it or not, installing SU2013 changes the 'browser' that is used by SU8. On my systems with only SU8 or earlier, SU8 reports IE7 for the browser. Once SU2013 is installed, SU8 reports IE9 for the browser.

      I've had isssues with initializing WebDialogs using code inside the WebDialog.show method. I've found it is much better to perform those tasks usig a callback from the documents 'load' event.

      The error you've shown is a script error from the WebDialog's JavaScript, which is probably trying to set the value of something that doesn't exist yet...

      FWIW,

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Removal of unwanted internal polys (lines)?

      tomot,

      @tomot said:

      unused internal polys (lines)

      A key word might be 'internal.' See --

      Link Preview Image
      Deleting Unnecessary Edges

      Posted by Sandra Winstead, SketchUp Team Have you ever opened a SketchUp file that you didn’t create, or imported a model from another appli...

      favicon

      (sketchupapi.blogspot.com)

      HTH,

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Invalid Web Dialog

      CJ,

      @cjthompson said:

      if I submit more than once.

      Can you please clarify what exactly you mean by submit? Not sure if you mean HTML form submit or not...

      If you do, I have only used a button onclick event and a trap for escape.

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Ruby's global nightmare!

      jessejames,

      @jessejames said:

      Am i moving to quickly for ya?

      Having written code in Python, Ruby, C#, Java, JavaScript, various dialects of Basic, and C++, probably not. Also, having a CompSci prof in the late '70's always wax on about the elegance of Pascal conditioned me to the large distinction between 'elegant' when finished, vs easy to reach 'finished.'

      The Python features you’re referring to would be considered simple syntax conventions by most programmers, and, hence, trivial. I'll respond anyway.

      1. Namespaces – Lets say I'm working on a real project, and production code will be a minimal set of files. As the code is being created, it's often helpful to have the code being worked on by itself, in a separate IDE container. Once complete, it's moved into another container that has finished code. Often, that IDE container is a file. I don't want the namespace changing if I move code between them.

      2. End vs indent – I've written code where there may be a lot of end statements, one after the other. Also, indenting is commonplace today. Hence, it would seem that Python's removal of statements like 'end' would be helpful, even though almost all other languages use them. Conversely, when writing code, I often leave test/debug statements on the left margin as a marker that I can delete them when the code works. I can't do that in Python.

      I might suggest that you read a few books like 'Design Patterns' by the 'Gang of Four' to get an idea of what the real distinctions are in programming languages. Real distinctions affect whether a framework can be moved/ported to another language, as opposed to simple syntax conventions.

      I might also suggest that there's plenty of others forums for your concerns. This one is for Ruby used in SketchUp.

      BTW, I'm ignoring the flame, otherwise we might get into that layman concept...

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Transformations

      Jim,

      Can you post the file that you used for import shown?

      Thanks,

      greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Ruby's global nightmare!

      To all,

      I don't know why I looked at this thread, but the basic premise that began it is the idea that an OS object (a file) should have an effect on namespaces in a coding environment. That, at a minimum, is a matter of personal preference.

      I could argue that the idea is very foolish, as I want my code to define the namespace, not it's placement in a file, or the file's name.

      If we're going to argue about X language vs Y language, might as well address serious topics, not fluff, and somewhere other than a forum about using Ruby in SketchUp.

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Transformations

      TIG,

      @tig said:

      if would be nice to be able to get just the angle of rotation out of an existing transformation

      I think the below might help. I haven't tested it that much, and never with 'stretched' trans...

      suATan just returns the arctan of the two numbers (x,y), x=0 => +/- 90

      
      aT = e.transformation.to_a
        # aT[12], aT[13], aT[14]           x, y, z offsets from component origin
        # suATan(aT[0], aT[1])             xy plane angle
        # xy = (aT[8]**2 + aT[9]**2)**0.5
        # suATan(xy, aT[10]) - 90          rise angle, check this one 
      
      

      HTH,

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Instance @variable vs class @@variable

      Boy, a lot of topics in this thread. Here's an old programmer's brief thoughts...

      Why use Classes - Use classes when 'things' have data/properties. I have code that exports faces from SU to a text file. One format requires all the coordinates be listed together (with an ID) in the text file. My code loops thru the faces and creates an object from each face, with layer, material, etc and coordinate info as instance variables. The loop code creates a few hashes for the coordinates; the face objects can reference that after it's created. If I didn't use classes, I'd be screwing around with crazy arrays and all sorts of stuff. Years ago, that's how one had to code, B4 OOP.

      Class vs Instance - Using the above example, I use class variables for switches that affect all the objects, like what data to export. Also, the coordinate hashes are class variables.

      All of my web dialogs are classes, not because I create a lot of them, but because the class holds data. Both data for the dialog, and data that exists after a modal dialog is closed, like the choices a user picked.

      Keep in mind that classes are very generic and designed so that the user can't get at the internals. That's what setters/getters are for, so the designer, if needed, can validate changes made by an object's user.

      HTH,

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Ruby to WebDialog Communication

      Hello all!

      1. I've always used '/' for my directory delimiter in Windows, and it works fine.

      2. onLoad or DOMContentLoaded - I'm sure you know, but DOMContentLoaded is not implemented in IE at present. Also, I think Safari doesn't handle onLoad like Firefox or IE...

      3. Re 'backslashing' text, I think this issue is tied to strings that are passed between Ruby and javascript in a WebDialog. I'll try the '%' syntax sometime. Of course, my Ruby reference book is not where I am...

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Ruby to WebDialog Communication

      Martin,

      Looks good. Re the scrollbars issue, add

      <style type="text/css">
      body {width:100%;height:100%;background-color:rgb(240,240,240);margin:0px;padding:0px;overflow:auto;}
      body {font-family:Arial, Helvetica; font-size:16px;}
      </style>

      to the html head section (really, just add body {overflow:auto;}, and scrollbars will work automatically in IE. I think the color matches the default SU dialog background.

      Also,

      function retFalse() {return false}
      document.oncontextmenu=retFalse;

      added to one's script will disable 'right-click' menus.

      Lastly, I may have mentioned that I define the html as strings in my code, then use the 'set_html' WebDialog call. You have to backslash single & double quotes. This allows me to conditionally assemble it or change it. Also, one can do a 'sub' on the string and change the CSS font-size before the set_html call. My plug-in has a settings window that lets the user choose one of three font sizes for their dialogs. All my dialogs' dimensions/sizes are in terms of 'em' in CSS, so the CSS font-size is the only 'absolute' declaration.

      I've got C# code that parses html files and generates text files that can be cut and pasted into a Ruby script. If people would like, I could post that code...

      These items may not be Ruby <> JavaScript specific, but your article could be expanded to be a WebDialog FAQ, and save new 'scripters' some time.

      Forgive me for suggesting that you expand it. I've always hated editing other people's writing...

      Thanks,

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • RE: Module Wrapper for Your Ruby

      Speaking of classes, one can sort of hide them by declaring them private and adding a module method to return an instance.

      I haven't written any Ruby code for while, so forgive the naming; I code in too many languages. Brief example of private both in a module and a class...

      module Is_Visible
        # method to return an instance of Test
        def self.get_Test
          Test.new
        end 
      
        private
      
        class Test
          def show ; puts "Test.show" ; end
          def self.self_show ; puts "Test.self_show" ; end
      
          def pub_show ; pri_show ; end
      
          private
          def pri_show ; puts "Test.pri_show" ; end
          
        end
      end
      
      # Can't create object since private in module
      begin
        t1 = Test.new
        t1.show
      rescue
        puts "Can't create Test"
      end
      
      # Create object and call instance method
      Is_Visible.get_Test.show
      
      # Call class method
      Is_Visible.get_Test.class.self_show
      
      # Can't call pri_show since private in class
      begin
        Is_Visible.get_Test.pri_show
      rescue
        puts "Can't call pri_show"
      end
      
      # Can call via public method
      Is_Visible.get_Test.pub_show
      
      

      FWIW,

      Greg

      posted in Developers' Forum
      M
      MSP_Greg
    • 1
    • 2
    • 3
    • 2 / 3