sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Ruby Plugin - Inserted Component Wrong Scale

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 4 Posters 439 Views 4 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.
    • placidfuryP Offline
      placidfury
      last edited by

      Okay... I've learned a ton about SketchUp and Ruby recently, but this problem has me totally stumped. I'm white-flaggin' it.

      So, here's the situation:
      I have some code in my plugin running which inserts a component from a SKP file after the user has clicked two points (p1 and p2). After setting the z coordinate to the same on each point, the length is measured between those two points on a horizontal plane. I have my SKP component stored as exactly 1' long on the Y axis (it needs to grow/shrink to length along the Y). The component is inserted where it needs to go, then scaled along the Y axis (among other things). The length divided by 12 is therefore my new scale I want the component to have:

      
      newcomp_def = model.definitions.load("C;\test.skp")
      trans1 = Geom;;Transformation.new p1
      trans2 = Geom;;Transformation.scaling p1, 1, (length/12), 1
      instance = entities.add_instance newcomp_def, trans1
      instance.transform! trans2
      
      

      This works perfectly over and over... but as I go along drawing in the same file, at some point the component starts to end up the wrong length. It's as if the definition itself has gotten rescaled so that the scale is no longer 1.0 compared to the original. I have confirmed this by remarking out the line that rescales the component (essentially leaving it at original file scale, which should be 12" long), then drawing, and the "1.0" scale component is LONGER than 12". I have even tested by switching the SKP file that is loaded to another that is the same 12" length, and it works perfectly. Also, if I start a new drawing from template, it works perfectly as well. But when I go back into a drawing where the length is incorrect, it once again is the wrong length. This leads me to believe that somewhere SketchUp has the scale for the definition with this specific file wrong... but how do I fix it or purge it? I've tried everything I know to do and none of it has had any effect.

      Thanks in advance!

      Placid

      1 Reply Last reply Reply Quote 0
      • K Offline
        kaas
        last edited by

        Not sure if its the same problem but I also ran into problems when using very small units. My workaround was: draw the original element much larger (say 1000 units) and when inserting, divide its size by its bounds (in your case would be its depth). That way, you would end up with a 1 unit element again which you can scale to your liking.

        See more here: http://www.sketchup.com/intl/en/developer/docs/ourdoc/boundingbox

        1 Reply Last reply Reply Quote 0
        • placidfuryP Offline
          placidfury
          last edited by

          It's quite bizarre. Odd thing is, if I draw one of the components at a 1:1 scale first (12" long), then continue to insert more, it seems to hold the proper scale for the other instances. If the first one I draw is not at a 1:1 scale, then the subsequent instances are scaled off of the new scale of the first one (ie, if the first one drawn is say 24" long, then 24" becomes 1.0... so then when I draw a 12" instance afterward, it's at 1.0 scale, which then is drawn as 24" even though the points I picked are 12" apart. I don't entirely understand this... it's reloading the component from file every time, but I guess it still links them together...

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

            @placidfury said:

            it's reloading the component from file every time

            Why do you reload it every time? Maybe that is why the definition is reset. You should load the component into the DefinitionList just once.

            Hi

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

              To load a component only once...

              newcomp_def = model.definitions.load("C;\\test.skp") unless newcomp_def = model.definitions["test"]
              

              Also note how I have correctly escaped the \ in the SKP path !
              Also recommend that you use length/12.0 - i.e. a float rather than an integer.
              I also assume that you are trapping for length==0 earlier on, otherwise the scaling transformation will choke...

              TIG

              1 Reply Last reply Reply Quote 0
              • placidfuryP Offline
                placidfury
                last edited by

                TIG, you rock. Thanks for the help (including all the other countless posts of yours I've read on other threads that have taught me so much so far). I think that got it after having it load once (with the exception of one situation where I need it to load separately each time - I have a 'container' component that other sub-components get inserted into, and if it's not reloaded, then the previous sub-component instances are in the new container instance as well, which I don't want). I also changed the path \, and float, and yes 0 length is getting trapped.
                I still have so much to learn...

                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