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

    Paste between instances and onLayerAdded issue

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 4 Posters 301 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.
    • jiminy-billy-bobJ Offline
      jiminy-billy-bob
      last edited by

      Hi guys

      I've come across an annoying issue with layersObservers.
      I have a layersObserver doing stuff when a new layer is added. The operations are wrapped in start_ and commit_operation, and I use a timer to avoid doing stuff right inside the observer (TT's advice), like this :

      <span class="syntaxdefault">module Test<br /><br />    class TEST_layersObserver </span><span class="syntaxkeyword"><</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">LayersObserver<br /><br />        def onLayerAdded</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">layers</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> layer</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">            timer </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start_timer</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> false</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault">                UI</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">stop_timer</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">timer</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">                Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start_operation</span><span class="syntaxkeyword">(</span><span class="syntaxstring">"Add layer"</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">                    </span><span class="syntaxcomment">#some code<br /></span><span class="syntaxdefault">                Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">commit_operation<br />            </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault">        end</span><span class="syntaxcomment">#def<br /></span><span class="syntaxdefault">        <br />    end</span><span class="syntaxcomment">#class<br /></span><span class="syntaxdefault">    <br />    Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">layers</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_observer</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">TEST_layersObserver</span><span class="syntaxkeyword">.new)<br /><br /></span><span class="syntaxdefault">end</span><span class="syntaxcomment">#module  &nbsp;</span><span class="syntaxdefault"></span>
      

      No issue when adding a new layer manually or via ruby, but when I try to copy some geometry from another instance of SU, being on a layer that is not already existing in the new file (The one where I want to paste), it fails.
      When pasting, SU tries to add the non-existing layer (sometimes I even see it flashing in the layers window), and goes right back to the previous tool. No layer added, no geometry added.
      It works fine without a timer, or without start/commit.

      You can try the snippet above, it fails. (If you have Layers Panel installed, disable it beforehand)

      This is really frustrating... 😒

      25% off Skatter for SketchUcation Premium Members

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

        Have you tried pasting with only one new layer?

        I just checked in my code, and as you probably know, onLayerAdded is called for each new layer. This may be causing issues because you may have more than one start_operation beginning but not yet commited as the multiple calls to onLayerAdded are made.

        I'd try puts statements inside onLayerAdded and also inside start_operation and see if that's the issue.

        Greg

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

          Layers can also be added when a user inserts a component from their library or the 3D-Warehouse.

          I'm not here much anymore.

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

            FYI... Test is a standard Ruby module, into which the SU Dev Team added a set of undocumented test methods.

            Suggest you nest YOUR "Test" module inside YOUR toplevel namespace.

            ie:

            module JBB
              module Test
            
                # code
            
              end
            end
            

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • jiminy-billy-bobJ Offline
              jiminy-billy-bob
              last edited by

              This happens with only one layer (Actually I haven't tested with multiple)

              And of course, I test this in my own namespace, I added "Test" only to post the snippet here.

              25% off Skatter for SketchUcation Premium Members

              1 Reply Last reply Reply Quote 0
              • jiminy-billy-bobJ Offline
                jiminy-billy-bob
                last edited by

                Nervermind, it works when I put the timer inside the start/commit_operation... 😒

                25% off Skatter for SketchUcation Premium Members

                1 Reply Last reply Reply Quote 0
                • tt_suT Offline
                  tt_su
                  last edited by

                  That operation should be transparent...

                  1 Reply Last reply Reply Quote 0
                  • jiminy-billy-bobJ Offline
                    jiminy-billy-bob
                    last edited by

                    It is in my code. I just simplified everything to paste this snippet.

                    25% off Skatter for SketchUcation Premium Members

                    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