Copy link to clipboard
Copied
Hi experts,
I have a requirement to add a Text to layer and make it uneditable to user.
I have successfully tried to Lock, hide, diable edit layers as well as textFrame inside the layer via Scripting. However in Illustrator UI, when user opens the document, user has the option to make the layer or Frame editable which is locked by scripting..
So, looking for an option to lock, hide the layer via Scripting and also have no option for user to unlock or make visible from UI.
Here is the code I used:
// Finds the tags associated with the selected art item,
// show names and values in a separate document
if ( app.documents.length > 0 )
{
doc = app.activeDocument;
if ( doc.selection.length > 0 )
{
for ( i = 0; i < doc.selection.length; i++ )
{
selectedArt = selection[0];
tagList = selectedArt.tags;
if (tagList.length == 0)
{
var tempTag = tagList.add();
tempTag.name = "OneWord";
tempTag.value = "anything you want";
}
}
// Create a document and add a line of text per tag
var reportDocument = app.documents.add();
top_offset = 400;
for ( i = 0; i < tagList.length; i++ )
{
tagText = tagList.value;
newItem = reportDocument.textFrames.add();
newItem.contents = "Tag: (" + tagList.name +
" , " + tagText + ")";
newItem.position = Array(100, top_offset);
newItem.enableAccess = false;
newItem.editable = false;
newItem.locked = true;
newItem.hidden = true;
newItem.layer.visible = false;
newItem.layer.opacity = 0;
newItem.layer.preview = false;
newItem.layer.locked = true;
newItem.layer.enable=false;
newItem.layer.requirePermissionPassword = true;
newItem.layer.permissionPassword = "Vinnudear";
newItem.textRange.size = 24;
top_offset = top_offset - 20;
// newItem.layer.parent.save();
//newItem.layer.parent.saveNoUI("c:\\temp\\LockTest.ai");
//newItem.layer.parent.requirePermissionPassword = true;
//newItem.layer.parent.permissionPassword = "teamcenter";
newItem.note = "USER:VINAY";
alert(newItem.note);
}
}
}
Regards,
Vinay
Message was edited by: Vinay Seera
Copy link to clipboard
Copied
Hi vinays28491172,
you can lock a layer and/or a page/path item and
you can hide a layer and/or a page/path item.
IMO you can't use a password for layers and/or path items.
The methods you have shown in you last post are only PdfSaveOptions
PDFSaveOptions.requirePermissionPassword = true;
PDFSaveOptions.permissionPassword = "Vinnudear";
Sorry.
Copy link to clipboard
Copied
Yes I locked it via scripting but User has the ability to unlock in UI.. So, the lock from scripting has no value.
I am looking for a way to lock from script which I am successful and also want a way that users cannot see that layer so that user cannot unlock in UI.
Regards,
Vinay
Copy link to clipboard
Copied
As I said before: you can lock and hide. But that's all. IMO no other possibilities.
What is the reason for your requirement?
Copy link to clipboard
Copied
Requirement is to set a hidden property(Name-Value pair) on an Illustrator/In Design/Photoshop document that cannot be viewed or edited by any User.
Regards,
Vinay
Copy link to clipboard
Copied
please, give an example
Copy link to clipboard
Copied
I am integrating Adobe tools(Illustrator/In Design/Photoshop) to an External application and I want to differentiate a
1. Document Created from Adobe Application via UI and
2. Document created via Script from external application.
o Steps Involved:
§ Create a document via script from external application.
§ Add a later and set a hidden property( “My Property” = ” External”).
§ User opens the document.
§ Should NOT see “My Property” on the document.
In order to differentiate, I want to add a hidden property to option 2 which users cannot see( hence cannot delete) and I can look for that property via Extension and identify the document.
Regards,
Vinay
Copy link to clipboard
Copied
… and this should works in Illuustrator and InDesign and Photoshop???
No way I think.
One try
A workaround for Illustrator could be:
Add the layer and give this a user defined color (near the original layer color).
This is not bulletproof. But you can read this color later and if the color is not yours - the layer was changed (or not created by your script)
Copy link to clipboard
Copied
The workaround you are suggesting about setting color to a layer, does this mean that if a User makes any change to the layer, the color automatically changes to something else?
Example I add a text frame to a layer and set color Green. If User updates Text Frame with some text, will the Layer color changes from Green to something else?
Regards,
Vinay
Copy link to clipboard
Copied
No. That is not possible with scripting.
And I do not know what do you really want.
Do you need a secure detail for something was added by script? Or do you want to prevent something for changes by user?
Remember: "As I said before: you can lock and hide. But that's all. IMO no other possibilities."
Copy link to clipboard
Copied
Sorry for the confusion and thanks for your patience..
Yes I do want prevent a layer for changes by User via UI.
I understood your answer about locking and hiding but as I said when you hide( set visible = false) via scripting, user is able to click on Layers window and select the hidden layer and make it visible.
As in the example below, even though I set all layers are invisible via Script , I can still see the layers and unhide.
Copy link to clipboard
Copied
You can't prevent a layer for changes by User via UI.
Do you perhaps want to check the document after openening by other users? Use check summ or colors or or or
There is nothing more to say, sorry.
Copy link to clipboard
Copied
Np. Thanks for trying..
Copy link to clipboard
Copied
You could take advantage of storing values in the xmp metadata:
var main = function() {
var doc, xmp,
uri = "http://www.mycompany.com",
pfx = "my",
value = "a new value from script",
ns, child = <my:prop xmlns:my="http://www.mycompany.com">{value}</my:prop>;
if ( !app.documents.length) return;
doc = app.activeDocument;
if ( !File ( doc.fullName ).exists ) {
alert("The document needs to be saved first" );
return;
}
xmp = getXMP ( doc );
ns = new Namespace (pfx, uri);
addNS ( xmp, ns);
if ( xmp.descendants("my:prop").length() ) {
xmp.descendants("my:prop")[0] = value;
}
else {
xmp.descendants("rdf:Description")[0].appendChild ( child );
}
doc.XMPString = xmp.toXMLString();
doc.save();
return xmp;
}
var addNS = function( xmp, ns) {
var nss = xmp.descendants("rdf:Description")[0].namespaceDeclarations(),
n = nss.length, ns, uri = ns.uri;
while (n-- ) {
if ( uri == nss[0].uri ) return;
}
xmp.descendants("rdf:Description")[0].addNamespace (ns);
}
var getXMP = function ( doc ) {
return XML ( doc.XMPString );
}
main();
For sure visible but not easily modified by end user. A possible issue might be a rewriting of the AI file by a third party sofware.
HTH
Loic Aigon
Copy link to clipboard
Copied
I was going to say xmp and some encryption encoding to hide that value.
Also, if the opening and saving of files can be all done via script - even if it's just a button in ScriptUI which does a save dialog + your custom logic, a script can write the annotation page item on close and read it in on open. Using CEP extensions it would be possible to more or less make this process automatic by having some script functions to check and write your notes into documents using whichever events correspond with the opening/closing/activation/deactivation.
Copy link to clipboard
Copied
Very good response. Thanks. It helped and I liked the solution a lot.