sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Resizing a DC via Ruby?

    Scheduled Pinned Locked Moved Dynamic Components
    sketchup
    6 Posts 3 Posters 2.2k Views 3 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.
    • J Offline
      Jim
      last edited by

      If a DC has a formula for its Z length, is there a way to set its size via Ruby?

      LenZ: =largest(8, round(current("LenZ")/8)*8)

      Hi

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        I imagine that Scott posted a sample command one could send to a DC to force it to refresh... don't have the link though....

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

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

          I can simply use a Transformation to scale the DC to any size I need, and then do a redraw. But if it has internal components, everything gets whacked-out.

          This is sort of related to this discussion:

          http://forums.sketchucation.com/viewtopic.php?f=289&t=28186

          Hi

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

            Here's an example of what I'm trying to do. I have a DC named PeggedPost. This is a component stored in an external file, and used in one or more master files. If the component is then edited, I want to be able to re-load and replace the definition in a master file.

            Normal Scaled Instances:
            peggedpost.png

            I am using this code at the moment:

            
            model = Sketchup.active_model
            entities = model.entities
            selection = model.selection
            ins = selection[0]
            ins.definition.save_as("/dev/null")
            new_post = model.definitions.load("c;/Documents and Settings/Jim/My Documents/PeggedPost.skp")
            ins.definition = new_post
            $dc_observers.get_latest_class.redraw_with_undo(ins)
            
            

            But this falls apart when an instance has been scaled. Note the component on the right - it was scaled, then the above code executed.

            Messed Up Instance.
            330.png

            Is this even the right approach, or is there a better way to do it?

            (TIG's xref plug-in does not handle this particular situation either.)

            (the snippet is stored in a model attribute and can be pulled into my latest version of webconsole automatically: http://bitbucket.org/jimfoltz/webconsole/downloads )


            PeggedPost.skp

            Hi

            1 Reply Last reply Reply Quote 0
            • scottliningerS Offline
              scottlininger
              last edited by

              Jim,

              Couple of things I had to do to get the behavior you want:

              1. Rebuild the DC so there is no naked geometry. I turned the "post" into a subcomponent that sets its LENZ to the parent LENZ. (Naked geometry in DCs is particularly dumb. When in doubt, make everything a subcomponent instead of faces and edges.)

              2. Add a couple lines of code that store the unscaled size onto the component instance before you redraw it. This gives the plugin the information it needs to scale correctly after the import.

                model = Sketchup.active_model
                entities = model.entities
                selection = model.selection
                ins = selection[0]
                new_post = model.definitions.load("c;/temp/PeggedPost_noNakedGeometry.skp")
                ins.definition = new_post
                lenx, leny, lenz = ins.unscaled_size
                ins.set_last_size(lenx, leny, lenz)
                $dc_observers.get_latest_class.redraw_with_undo(ins)
              

              Cheers, πŸ˜„

              • Scott Lininger
                SketchUp Software Engineer
                Have you visited the Ruby API Docs?
              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                @unknownuser said:

                1. Rebuild the DC so there is no naked geometry. I turned the "post" into a subcomponent that sets its LENZ to the parent LENZ. (Naked geometry in DCs is particularly dumb. When in doubt, make everything a subcomponent instead of faces and edges.)

                What about when you make cutout DC's? Then you need "naked" edges to make the cut.

                Thomas Thomassen β€” SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                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