9 Replies Latest reply on Jun 8, 2015 4:06 AM by _VG

    visibility variable get lost on undo/redo.

    _VG

      Hello All,

       

      I've scenario where I've to distinct the page items and apply some sort of unique Ids to them. So for that, I added the visibilityVariable to the page items. Code is as follows,


      var idoc = app.activeDocument; 

      var ipath = app.selection[0];

      var idocvar = idoc.variables.add();

      idocvar.kind = VariableKind.VISIBILITY; 

      idocvar.name = "0001"

      ipath.visibilityVariable = idocvar;

       

      Everything work fines untill I used undo/redo. The visibility variable got lost on undo/redo.

       

      Following are the steps that I do,
      - Create a pageItem, let's say a rectangle, and select it.

      - Now run the script.

      - You can see in the Variables palette that variable is assigned to the object.

      - Now move the page item (2-3 times) from one position to another.

      - Now Undo/Redo by usnig cntrl-z and cntl-shift-z. Object get lost and there will be no variable attached to the pageItem.

       

      Am I missing something here? Do we have another way to distinct the pageItems apart from visiblityVariable which will work in undo/redo case?
      Thanks for any help..

        • 1. Re: visibility variable get lost on undo/redo.
          Silly-V Adobe Community Professional

          Why not use the name or note, or even tag?

          • 2. Re: visibility variable get lost on undo/redo.
            _VG Level 1

            name can be identical for two page items. I think note or tag gets copied when we duplicate the page item. so it fails the unique ID approach.

            • 3. Re: visibility variable get lost on undo/redo.
              Silly-V Adobe Community Professional

              My Illustrator flipped-out when trying to name a variable "0001"  Perhaps because it does not like when variable names start as a number.

              Other than that, when you do Undo, do you make sure that you don't Undo too many times and you accidentally undo your own script which assigns and creates the variable?

              • 4. Re: visibility variable get lost on undo/redo.
                _VG Level 1

                That is what I need.. I want to revert the changes on undo what I've done through scripting.. But unfortunately undo/redo doesn't work properly with visibility variable. And when we undo/redo as mentioned in my above steps I saw that on windows, It only unbind the variable but on mac Ai get crashed..

                • 5. Re: visibility variable get lost on undo/redo.
                  Silly-V Adobe Community Professional

                  Yes, that has been also my experience, my Mac crashes, so I never undo when using variables. Hopefully there can be other ways to accomplish your desired goal.

                  • 6. Re: visibility variable get lost on undo/redo.
                    _VG Level 1

                    I am also hoping the same thing.. But till now no luck. I don't find any way to use unique id without visibility variable. May be some one else can shed some light on this..


                    Is there any way we could create an undo point or something like reverse the whole scripting thing in just one undo..

                    • 7. Re: visibility variable get lost on undo/redo.
                      _VG Level 1

                      Is it a some kind of bug?
                      Is there any way we could manage undo/redo through scripting.

                       

                      Thanks for any help.

                      • 8. Re: visibility variable get lost on undo/redo.
                        Silly-V Adobe Community Professional

                        There's too many things that I am not sure about. In my experience "0001" is not a good name for variables, so that'll make it crash. Otherwise, on windows I did what you did in 1st post, which is assign the variable with a script, then move the item up and down and then undo the moving, and my visibility variable is still there. So, I can't recreate the problem on my Windows machine, the visibility variable does not disappear or get unbound when doing Undo and Redo in the UI manually.

                        You can use the Undo command from a script, but what does that have to do with your initial problem of having the Undo & Redo erase your visibility variable?

                        • 9. Re: visibility variable get lost on undo/redo.
                          _VG Level 1

                          Sorry for the late reply,

                          In my experience "0001" is not a good name for variables

                          I tried it with different names also like "ID1", "pageItemID" etc.. Issue still persist.

                           

                          I can't recreate the problem on my Windows machine

                           

                          Can you please try this with 2-3 pageItems? I mean add the variable to each item using script (make sure to change the variable name) and move them after assigning variable to each item and then redo/undo. Please see the following images,

                           

                          #1- After assigning variable to pageItem

                          variableAssigned.JPG

                          As you can see the rectangle is assigned with ID-0001. Now when I move this item here and there and undo, the variable get unbinded.

                           

                          #2- Unbind variable image after undo/redo,

                          variableUnbind.JPG

                          I hope It clears thing here..

                           

                           

                          You can use the Undo command from a script, but what does that have to do with your initial problem of having the Undo & Redo erase your visibility variable?

                           

                          Actually I was asking, may be there is any way through which we can create any undo point, so that when we undo using cntrl-z it will undo till that point only.
                          Like there is an option in photoshop scripting to create a suspend history check point so that whatever we do in scripting or a portion of script can be accumulated in one undo point. I hope it make sense..

                           

                          Thank you for all your time and help..