sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Resize DC with ruby

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 5 Posters 502 Views 5 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.
    • G Offline
      GWD
      last edited by

      I'm trying to resize a DC with a ruby script. But the result is very strange.

      I use the .set_last_size function, and the DC size changes but not to the right size.

      DCresize.rbDC resize test.skp

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

        Where is the documentation on .set_last_size?

        What happens if you use using a typical scaling Transformation?

        Hi

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

          Dan covered the additional methods added by the DC Extension [including that one] here
          http://www.sketchucation.com/forums/viewtopic.php?p=293542&sid=5e9cba98370bfa85f9ab7093e95f2894#p293542

          TIG

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

            If you use .scaled_size and .unscaled_size these return arrays of the xyz size/scales as original or current.
            If you use these values in the .set_last_size() with a modifying * or / for x/y/z values you will see that halving the X doubles LenX and so on - so conversely to double the X use /2. To set the X-length to a new value in 'units' just do the cockeyed math to get the correct factor - e.g. x=10" and you want it to be 20" you find the ratio 10/20, and then apply it to the present scaling factor as a / (as 'manual trials' show... to make it *2 you'd actually use /2 ❓ )... [do the "/cm conversions to suit...] It just seems weird 😕

            TIG

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

              @unknownuser said:

              I'm trying to resize a DC with a ruby script. But the result is very strange.

              I use the .set_last_size function, and the DC size changes but not to the right size.

              The .set_last_size function is an internal method that needs to be called at the correct point in the redraw process depending on various factors, as driven by the DCObservers.

              A DynamicComponent is not actually a Ruby class in the instance object sense (although it was written as a Singleton class block, it really could have been written as a module, instead.)

              So a DC, is really just a Sketchup::ComponentInstance instance object, that has a specially named AttributeDictionary, ie: "dynamic_attributes" and the DC extension has Observers that "watch for" and react upon objects that have that specially named dictionary.

              I suggest you use the normal transform! method to scale or move a DC via Ruby, then if you must force a redraw, call the redraw as you did in your example.
              Also, if doing rotational transforms, be sure to do them in x, y, z order.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • M Offline
                Morgan74
                last edited by

                Hello,

                I wrote a small code to add a DC at a specific position and resize it.

                So when Sketchup add an instance of a DC its position is 0,0,0. You need to define a transformation to place it where you want.

                t1 = Geom;;Transformation.axes(...,...,...)
                newDC = Sketchup.active_model.entities.add_instance(Sketchup.active_model.definitions["MyDC"],t1)
                

                To set the length I used the set_attribute method of the DC definition

                len = 13
                len2 = 12
                newDC.definition.set_attribute "dynamic_attributes","_lenx_nominal",len.to_s
                newDC.definition.set_attribute "dynamic_attributes","_lenz_nominal",len2.to_s
                
                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