sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Help me solve a mystery

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 7 Posters 525 Views 7 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sdmitchS Offline
      sdmitch
      last edited by

      Using Ruby Web Console, I created a method to generate a Herringbone pattern on a selected face.
      h_bone.jpg
      When finished and all was working as expected, I copied the code to a plugin file. But, unlike when executed from Ruby Web Console, the code produced errors, as listed below, when executed.

      =begin
      
      su8 errors
      
      h_bone
      Error; #<NoMethodError; undefined method `explode' for nil;NilClass>
      C;\Users\Public\SketchUp\Plugins\h_bone.rb;39
      C;\Users\Public\SketchUp\Plugins\h_bone.rb;36;in `upto'
      C;\Users\Public\SketchUp\Plugins\h_bone.rb;36;in `h_bone'
      C;\Users\Public\SketchUp\Plugins\h_bone.rb;35;in `upto'
      C;\Users\Public\SketchUp\Plugins\h_bone.rb;35;in `h_bone'
      (eval);15
      
      
      su2014 errors
      
      h_bone
      Error; #<TypeError; reference to deleted Entities>
      C;/Users/Public/SketchUp/Plugins/h_bone.rb;38;in `add_instance'
      C;/Users/Public/SketchUp/Plugins/h_bone.rb;38;in `block (2 levels) in h_bone'
      C;/Users/Public/SketchUp/Plugins/h_bone.rb;36;in `upto'
      C;/Users/Public/SketchUp/Plugins/h_bone.rb;36;in `block in h_bone'
      C;/Users/Public/SketchUp/Plugins/h_bone.rb;35;in `upto'
      C;/Users/Public/SketchUp/Plugins/h_bone.rb;35;in `h_bone'
      <main>;in `<main>'
      -e;1;in `eval'
      nil
      
      =end
      
      

      Thinking that some of the code cleanup I had done had something to do with it, I pasted the code between a def and end statement in a new file, loaded and executed that. But the results were the same. So the question is, why would the exact same code executed from Ruby Web Console succeed while executed from a loaded plugin fail?

      Nothing is worthless, it can always be used as a bad example.

      http://sdmitch.blogspot.com/

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        A new clue in the mystery. If the components exist before the plugin is executed, it runs without a problem. So it is something regarding the initial creation of the components in the plugin that apparently doesn't occur when the Ruby Web Console script is executed.

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • D Offline
          driven
          last edited by

          if you simply wrap it as a string [ in the .rb file with eval ] and load that, does it work?

          i.e

          eval %Q(# you original code here)
          

          also, if you post the code it's easier to test...

          john

          learn from the mistakes of others, you may not live long enough to make them all yourself...

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            I would not trust my old Ruby Web Console plugin. There were name-space issues if I remember correctly.

            One simple way to write and test code in SketchUp is to use your favorite editor. Then create a menu or tool button in SketchUp to load the file you are editing. The advantge of a menu is that you can create a shortcut to reload the file. It's a simple, fast, and effective workflow.

            Hi

            1 Reply Last reply Reply Quote 0
            • sdmitchS Offline
              sdmitch
              last edited by

              Apparently the only mystery is why creating components "on the fly" is only partially successful at best.

              Nothing is worthless, it can always be used as a bad example.

              http://sdmitch.blogspot.com/

              1 Reply Last reply Reply Quote 0
              • jolranJ Offline
                jolran
                last edited by

                I could think of 2 things related to those errors. You are referencing face.normal in the add instance method. BUT using pushpull on the face after referencing to a variable may delete the original face/faceID or reference what you may call it.

                Also maybe using load definitions from paths might bring more succes than add ?

                1 Reply Last reply Reply Quote 0
                • TIGT Online
                  TIG Moderator
                  last edited by

                  Jolran is correct.
                  When you use f.pushpull() the original face is lost.
                  So when you later try to use a reference to that face ' f' it is a 'deleted-entity' - raising an error...
                  But since your container's entities only has the one face with that normal you can re-find the face if needed - or just set a reference to the normal [say as n=f.normal] BEFORE doing the pushpull that deletes the face...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • sdmitchS Offline
                    sdmitch
                    last edited by

                    In this case, I don't attempt to reference the face later. Also, if the plugin doesn't have to create the components, it ran normally.

                    I tried creating a group for each "box" then group.to_component. This was a better but still unreliable.

                    I eventually ended up just adding the "boxes" to a single group rather than making components at all. This then created another problem which was resolved in the test plugin by doing nothing more than simply moving the .add_group statement. I can't imagine why that should make a difference.

                    The good news is that all the gremlins have been eliminated and all is right with the world.

                    Nothing is worthless, it can always be used as a bad example.

                    http://sdmitch.blogspot.com/

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      The old webconsole may have done some initializing of local varibales that your method does not have.

                      Such as:
                      model = Sketchup::active_model defns = model.definitions selset = model.selection

                      etc.

                      Look at the code for the webconsole.

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        @sdmitch said:

                        In this case, I don't attempt to reference the face later.

                        Yes you did.. you tried to create a transform using f.normal so that method would likely return nil or raise an exception.

                        Or the add_instance method would return nil making the ci reference nil.

                        Obviously you expect a valid instance or group when you use the explode method, but the reference (that you are calling explode upon,) is referencing nil.

                        Learn to write nil tests / valid test into your code to catch these errors, ie:
                        ci.explode if ci

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          dacastror
                          last edited by

                          Is this editor will have the same behavior?

                          Link Preview Image
                          SketchUp Ruby Code Editor • [as]

                          This code editor extension offers an easy-to-use and visually appealing way to write and modify Ruby scripts directly within SketchUp. These scripts can then be used to create geometry, add functionality or add data within the SketchUp 3D modeling environment. The SketchUp Ruby API provides an extensive set of functions to automatize SketchUp in many ways or create scripted, computational geometry.

                          favicon

                          [as] (www.alexschreyer.net)

                          the author said it was based on the Ruby Web Console

                          1 Reply Last reply Reply Quote 0
                          • 1 / 1
                          • First post
                            Last post
                          Buy SketchPlus
                          Buy SUbD
                          Buy WrapR
                          Buy eBook
                          Buy Modelur
                          Buy Vertex Tools
                          Buy SketchCuisine
                          Buy FormFonts

                          Advertisement