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!
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Definition Observer

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 3 Posters 534 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.
    • K Offline
      kwalkerman
      last edited by

      Hello,

      I'm trying to use definition observers in a script instead of multiple entities observers because they seem to be a little more stable. There are a number of quirky things about it, but one that I haven't been able to work around is as follows:

      When I add a component instance to the model, the onComponentInstanceAdded method fires. However, if I delete the component instance and then undo, onComponentInstance added does NOT fire. I need to be notified both of new instances and of instances that are back from the dead.

      Any ideas?

      Thanks a bunch,

      Karen

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

        Use a combination of definitions observer and definition observer.
        Add a definition observers to each of the definitions.
        When a definition is added/deleted to/from definitions you know.
        You now know that definition - add an observer to that too.
        When any definition has instances added/removed you know as its observer tells you...

        TIG

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

          ...
          except that onInstanceRemoved doesn't fire
          and onInstanceAdded doesn't fire for a delete-undo event

          ... I think I'm going back to entities observers... seems more stable in SU8

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

            Yea - definition observer has been troublesome all along: http://www.thomthom.net/software/sketchup/observers/#DefinitionObserver

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

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

              Crib from my '#HolePunchTool.rb'...
              That uses definition and definitions [and several other] observers, and a global [$] array of things that is adjusted as we go...
              It seems to work OK for me, to keep track of Hole-Punching Instances etc and control copying, etc...
              Have a look - the observers code is near the end of the script...
              You might be able to adjust its ideas to your needs... πŸ€“

              TIG

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

                Thanks TIG.

                TT - I revisited your observers chart page after posting the initial message. Definitely very helpful. Thanks for maintaining it.

                --
                Karen

                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