Skip to main content
Inspiring
May 31, 2015
Question

visibility variable get lost on undo/redo.

  • May 31, 2015
  • 2 replies
  • 990 views

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..

This topic has been closed for replies.

2 replies

_VGAuthor
Inspiring
June 3, 2015

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

Thanks for any help.

Silly-V
Legend
June 3, 2015

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?

_VGAuthor
Inspiring
June 8, 2015

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

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,

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..

Silly-V
Legend
May 31, 2015

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

_VGAuthor
Inspiring
June 1, 2015

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.

Silly-V
Legend
June 1, 2015

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?