How do I traverse layerSets & artLayers in Extendscript? - extendscript

I'm familiar with CSS selectors and traversing in jQuery but can't work out how to do it in ExtendScript. I want to find the second to last folder in a layerSet and then go to the first LayerSet within it and select/focus it. I can't see how to go up and down PhotoShop's DOM (other than layerSets.length), nor how to specify a specific layerSets/artLayers without using names. Here's my lame attempt with made up stuff to demonstrate what I'm trying to do.
var topFolders = app.activeDocument.layerSets.length; //how many folders
var todayFolder = layerSetID(topFolders-1); //totally made up layerSetID()
app.activeDocument.activeLayer = todayFolder; //make folder active
I've been trawling photoshop_scriptref_js.pdf looking up things to do with name, index, select but can't find anything that I can understand fits my issue.

Related

Filter on folder and item type in ArcGIS Online

enter image description hereI want to change the extent of all webmaps in a given folder in ArcGIS Online. However, the standard query command (gis.content.search) does not have a property that allows searching only in a folder.
On the other hand, once I have a list of all items in a given folder, I am unable to only filter all webmaps out. This is the script I used (see also the image):
folderowner = 'my_username'
updatefolder = 'testfolder'
user = gis.user.get(username=my_username)
user
rightFolder = user.items(folder = updatefolder)
rightFolder
for item in rightFolder:
print(item.type)
for item in rightFolder:
if (item_type = "Web Map"):
print (item.title)
screenshot of script
I can print the Item types. But once I try to list only Web Maps, I get a Syntax error. I have tried many different notations.
I can pass the types in a print command, but I can't use the types as a way to filter. Where I am basically looking for is thus a way to get only web maps in a given folder.

Export (save as) jpg using layer name in Photoshop action

is it possible to copy the current active layer name in Photoshop and use it as the file name for a 'Save As' command in a Photoshop action?
Export Layers to Files isn't suitable because I only want to save a single jpg at a particular point in the action, but because the action is recursive I need a way of changing the filename so that the resulting jpg isn't overwritten with each recursion.
Many thanks!
It's possible to get the name of the activeLayer and save it within an variable:
var layerName = app.activeDocument.activeLayer.name;
var destFile = new File ("~/Desktop/" + layerName + ".jpg");
If you want to document.saveAs() you should set the asCopy parameter to true:
app.activeDocument.saveAs (destFile, docExportOptions, true, Extension.LOWERCASE);
This will prevent a name change of the file you're working with.
Instead of document.saveAs() you could use document.exportDocument() in case you want a really small JPEG output.
app.activeDocument.exportDocument (destFile, ExportType.SAVEFORWEB, docExportOptions);
Have you tried : "Export layers to files..." in Files, Script ? You don't tell us which method you are using right now.
This should export each layer with their name + a custom prefix of your choice.
Also, you may want to take a look at the Insert Menu Item that lets you record a set of actions and then does it automatically. If you need something more complex than the first option, this might be your solution.

exclude a certain path from all user searches

Unfortunately we have a special folder named "_archive" in our repository everywhere.
This folder has its purpose. But: When searching for content/documents we want to exclude it and every content beneath "_archive".
So, what i want is to exclude the path and its member from all user searches. Syntax is easy with fts:
your_query AND -PATH:"//cm:_archive//*"
to test:
https://www.docdroid.net/RmKj9gB/search-test.pdf.html
take the pdf, put it into your repo twice:
/some_random_path/search-test.pdf
/some_random_path/_archive/search-test.pdf
In node-browser everything works as expected:
TEXT:"HODOR" AND -PATH:"//cm:_archive//*"
= 1 result
TEXT:"HODOR"
= 2 results
So, my idea was to edit search.get.config.xml and add the exclusion to the list of properties:
<search>
<default-operator>AND</default-operator>
<default-query-template>%(cm:name cm:title cm:description ia:whatEvent
ia:descriptionEvent lnk:title lnk:description TEXT TAG) AND -PATH:"//cm:_archive//*"
</default-query-template>
</search>
But it does not work as intended! As soon as i am using 'text:' or 'name:' in the search field, the exclusion seems to be ignored.
What other option do i have? Basically just want to add the exclusion to the base query after the default query template is used.
Version is Alfresco Community 5.0.d
thanks!
I guess you're mistaken what query templates are meant for. Take a look at the Wiki.
So what you're basically doing is programmatically saying I've got a keyword and I want to match the keywords to the following metadata fields.
Default it will match cm:name cm:title cm:description etc. This can be changed to a custom field or in other cases to ALL.
So putting an extra AND or here of whatever won't work, cause this isn't the actual query which will be built. I can go on more about the query templates, but that won't do you any good.
In your case you'll need to modify the search.get webscript of Alfresco and the method called function getSearchResults(params) in search.lib.js (which get's imported).
Somewhere in at the end of the method it will do the following:
ftsQuery = '(' + ftsQuery + ') AND -TYPE:"cm:thumbnail" AND -TYPE:"cm:failedThumbnail" AND -TYPE:"cm:rating" AND -TYPE:"st:site"' + ' AND -ASPECT:"st:siteContainer" AND -ASPECT:"sys:hidden" AND -cm:creator:system AND -QNAME:comment\\-*';
Just add your path to query to it and that will do.

Allocating matrix / structure data instead of string name to variable

I have a script that opens a folder and does some processing on the data present. Say, there's a file "XYZ.tif".
Inside this tif file, there are two groups of datasets, which show up in the workspace as
data.ch1eXYZ
and
data.ch3eXYZ
If I want to continue with the 2nd set, I can use
A=data.ch3eXYZ
However, XYZ usually is much longer and varies per file, whereas data.ch3e is consistent.
Therefore I tried
A=strcat('data.ch3e','origfilename');
where origfilename of course is XYZ, which has (automatically) been extracted before.
However, that gives me a string A (since I practically typed
A='data.ch3eXYZ'
instead of the matrix that data.ch3eXYZ actually is.
I think it's just a problem with ()'s, []'s, or {}'s but Ican't seem to figure it out.
Thanks in advance!
If you know the string, dynamic field references should help you here and are far better than eval
Slightly modified example from the linked blog post:
fldnm = 'fred';
s.fred = 18;
y = s.(fldnm)
Returns:
y =
18
So for your case:
test = data.(['ch3e' origfilename]);
Should be sufficient
Edit: Link to the documentation

Relative path to physical path

<rant>
firstly, I've searched a lot and every single question / blog asks/tells about how to convert physical path to relative, never the other way around. If I've missed that question here, I am sorry.
<rant />
So, I have a directory structure very similar to this:
Root
|....Components
|....Classes
|....Utils
|....FileUtils
|....Assets //this is a folder
|....FileAccess.cs
So, in my FileAccess.cs I just want to read the content of a text file and display it on a page.
in my webpage.aspx.cs I am calling the getFileContent() which is in utils.
so the relative path from FileAccess.cs is Assets\spec.txt
So, how on earth can I access that with code?
this is what I am trying / tried:
//function getFileContent() content..
private const string QuestionnairePath = #"Assets\";
return Server.MapPath(QuestionnairePath + "spec.html");
it ALWAYS throws file not found exception and upon debugging it's not selecting the right folder.
I have even tried this:
private const string QuestionnairePath = #"~Utils\FileUtils\Assets\";
that doesn't work either.
This must be very easy. Just can't figure it out, for the life of me. I hate being a newbie sometimes.
Help please,
Thanks.
ps: Ideally, I would just want to use relative path: Assets\ - wonder if that is possible.

Resources