• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Change plugin variables within Undo

Scheduled Pinned Locked Moved Developers' Forum
4 Posts 3 Posters 320 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.
  • M Offline
    maricanis
    last edited by 6 Aug 2013, 12:25

    Hi,

    In my plugin I define undoable operation with start_operation and commit_operation around my code.
    Operation does next:

    • check some flag value
    • based on flag changes materials of multiple surfaces in the model
    • sets new value to the flag

    If I use undo, after performing operation - materials are changed back correctly, but my internal flag variable is not, so next time I try to run operation staring flag value is wrong.

    Question:
    Is there some way to define which function Sketchup should call when Edit->Undo is clicked?

    I've looked Transaction observers, but it seems like they will trigger for every step of my operation (for each surface's material change), which is not the thing I need.

    I've tried to find similar question on the forum, and also browsed through API documentation, but haven't found solution.

    Thanks in advance,
    Marija

    1 Reply Last reply Reply Quote 0
    • T Offline
      tt_su
      last edited by 6 Aug 2013, 23:19

      Do you have a reproducible snippet of code?

      By flag, I assume you mean attribute or variable?

      1 Reply Last reply Reply Quote 0
      • M Offline
        maricanis
        last edited by 7 Aug 2013, 07:42

        Hi,

        Here is example of code.
        I have global variable @@dl_materials_changed which enables toggling on-off of faces materials in the model.
        Each time user press UI button this function onToggleMaterial is called.

        So with this code Undo correctly switches materials back, but @@dl_materials_changed flag is not changed, so next time I press button in UI it doesn't have correct value.

        def onToggleMaterial()
            Sketchup.active_model.start_operation("toggle materials")
            showFCMaterials()
            Sketchup.active_model.commit_operation()
        end
        
        def showFCMaterials()
            #load all faces in @faces varialbe
            @faces = getFaces(Sketchup.active_model.entities)  
        
            #Set materials if flag is true
            if @@dl_materials_changed
                @faces.each {|face|
                    material_name = face.get_attribute("faceData","material_name","")
                    if material_name != ""
                         face.material = materials[material_name]
                    else
                         face.material = nil
                    end
                }
                @@dl_materials_changed = false
            else
                 @faces.each_value {|face|
                    face.material = nil
                }
                @@dl_materials_changed = true
            end
        end
        
        1 Reply Last reply Reply Quote 0
        • D Offline
          danielbowring
          last edited by 7 Aug 2013, 08:11

          you could store the value/flag on the model instead, then it would also change with the undo steps

          
          model = Sketchup.active_model
          model.set_attribute('maricanis', 'dl_materials_changed', true)
          #...
          model.get_attribute('maricanis', 'dl_materials_changed', false)
          
          
          1 Reply Last reply Reply Quote 0
          • 1 / 1
          1 / 1
          • First post
            1/4
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement