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

    Dynamic Component Redraw

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 8 Posters 4.2k Views 8 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
      JonD
      last edited by

      Is there an observer to catch the 'event' when a user applies a change to a dynamic component that causes it to redraw? I need to beable to force a redraw of another dynamic component if a change happens to another. I thought I saw something on a dynamic component observer, but I cannot find any documentation on it...

      Thanks,
      Jon

      1 Reply Last reply Reply Quote 0
      • B Offline
        bsnantes
        last edited by

        I have the same need. Did you find any solutions ?

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

          Nothing yet...

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            well supposedly the refresh method will force a redraw. Did you try that method? It might need to be implemented inside of a tool class. Did you look into that method?

            Chris

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

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

              @chris fullmer said:

              well supposedly the refresh method will force a redraw. Did you try that method? It might need to be implemented inside of a tool class. Did you look into that method?

              Chris

              He need the refresh method and an event callback...

              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 think it should be possible. The operation of DC's are not documented, but this blog post might contain some useful examples.

                Link Preview Image
                Dynamic Components that react to scene (aka page) changes

                Have you ever wanted to have a Dynamic Component that reacts to Scene changes? Well, this blogpost tells you how to write one (th...

                favicon

                (sketchupapi.blogspot.com)

                Hi

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

                  Hey guys,

                  There is no observer for DC redraw. I did think of a trick you could try, however.

                  The "functions" that can be called as part of a DC formula are defined in a class called DCFunctionsV1. Any protected methods inside that class are discovered by the DC plugin by reflection and can be called inside a DC spreadsheet formula. Since every formula is run each time a DC is redrawn, you can call your own ruby code this way.

                  For example, let's make a new DC spreadsheet function that shows a messagebox:

                  1. Save this script as customDCFunctions.rb into your plugins directory.
                  # Adds custom DC spreadsheet functions.
                  class DCFunctionsV1
                    
                    protected
                    
                    # Shows a messagebox from DC formula.
                    # Example Formula; =messagebox("something")
                    def messagebox(param_array)
                      val = param_array[0]
                      UI.messagebox(val.to_s)
                      return val
                    end
                  
                    # Returns first thing, alphabetically, in list of params.
                    # Example Formula; =firstAlpha("bob", "cal", "amy", "dan")
                    def firstalpha(param_array)
                      return param_array.sort.first
                    end
                  
                  end
                  
                  1. Restart SU, and create a new DC. Add a custom attribute called "onredraw" (or whatever you want) with the following formula:
                  =messagebox("Hello")
                  

                  Whenever that DC is redrawn (manipulate it with the scale tool, for example), you'll see your messagebox. You could just as easily call some more complex code. People who have your script installed will get the behavior you want. People without it won't, of course, so you'd need to be careful about that.

                  Hope that gets you started. 😄

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

                    Many thanks Scott, Thom and Chris. I will give this a try when I get back to the workstation.

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

                      @ScottLininger 
                       
                      Hi!
                      You code is interesting. (customDCFunctions.rb)
                      I try it but I got a error message when I open SU

                      @unknownuser said:

                      Error Loading File CustomDCFunctions.rb
                      Error: #<SyntaxError: C:/Users/Design6/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Plugins/CustomDCFunctions.rb:11: void value expression
                      C:/Users/Design6/AppData/Roaming/SketchUp/SketchUp 2017/SketchUp/Plugins/CustomDCFunctions.rb:17: void value expression>

                      Do you have a clue, why?

                      Thank you

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

                        Scott Lininger left Trimble/SketchUp several years ago to start his own company. (He is unlikely to see or reply to your question. Ie, this topic thread is at least 7 years old!)

                        There are more recent threads on making custom DC functions (but you should not publish any custom changes.)

                        See this thread:
                        http://sketchucation.com/forums/viewtopic.php?f=180&t=67235

                        I'm not here much anymore.

                        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