How to hide layer by id? - adobe

I am writing generator plugin and I get document structure using method generator.getDocumentInfo(). It returns document object containing layer objects in tree structure. document object has property document.id and each layer has property layer.id.
Goal: I want to hide layer - I know only document id and layer id.
Problem: The only method to hide layer in generator plugin I found is evaluateJSXString() method. This is fine but I don't know how to access document by id and layer by id. According http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/photoshop/pdfs/photoshop-cc-javascript-ref.pdf document has no id property and layer also has no id property. All I found is that app.documents is an array of documents (but index is not id) and app.document[i].layers is an array of layers but it contains only top level layers and each top level layer contains child layers.
The only option I see is to write JSX script which will first traverse app.documents array to find doc with for example matching file name and then it will search for a layer in document.layers tree structure..
Is there any other options?
How generator provides document and layer IDs when using generator.getDocumentInfo()? Is some generatpr-internal notation?

I see this is an old question had the same question. I was able to come up with a solution using generator's method evaluateJSXString. You can execute extendscript with evaluateJSXString with in your generator plugin. There is no looping involved here. Just by layerID.
Note: layerID is a variable that holds the layer ID and it is concatenated to the string to be evaluated.
To show the layer:
var changeVisibilityString = " var ref = new ActionReference(); \
ref.putIdentifier(charIDToTypeID('Lyr '), " + layerID + " ); \
var desc = new ActionDescriptor(); \
desc.putReference(charIDToTypeID('null'), ref); \
desc.putBoolean(charIDToTypeID('MkVs'), false); \
executeAction( charIDToTypeID('Shw '), desc);"
generator.evaluateJSXString(changeVisibilityString);
To hide the layer:
var changeVisibilityString = " var ref = new ActionReference(); \
ref.putIdentifier(charIDToTypeID('Lyr '), " + layerID + " ); \
var desc = new ActionDescriptor(); \
desc.putReference(charIDToTypeID('null'), ref); \
desc.putBoolean(charIDToTypeID('MkVs'), false); \
executeAction( charIDToTypeID('Hd '), desc);"
generator.evaluateJSXString(changeVisibilityString);

Related

How to add any symbols after prefix_?

is there any solution? e.g. I have data in Map with key favorites_ prefix and values _suffix (for example: favorites_jeans, favorites_suit,...,). I want to by dint of loop get that values and set in List, because of it I must give keys of map, right?
I want to know how can I get values of myMap["favorites_*"] (* - after the favorites_ any symbols).
List<String> favoritesStrings = ['favorite_name','favorite_jeans',];
Map<String,dynamic> myMap = {
favoritesStrings[0]:'0',
favoritesStrings[1]:'1',
'someKey':'2',
'anotherKey':'3',
};
favoritesStrings.forEach((favorite)=>print(myMap[favorite]));//prints 0 1
As per what I understood, you want to fetch value from map using "favorites_" + a dynamic value from list as key.
You just have to use String templates and use $ to insert suffix variable to build key dynamically:
List<String> suffixList = ["jeans", "suit", "shirt"];
for(String suffix in suffixList) {
var item = myMap["favorites_$suffix"];
// Do something with item
}
Hope it helps

Google Appmaker createItem failing with could not select element

I have a temporary table where I let the user copy the record that needs to be edited. Once the edit is complete, I copy it back.
I am getting an error when I am trying to copy the original record to temporary table for editing. Here's the code I am using
console.log('copyOriginalToTemp ' + tempRecord.ID + ' options ' + JSON.stringify(options));
var myCreateDatasource = app.datasources.RadiosTemp.modes.create;
console.log('# of items in myCreateDatasource ' + myCreateDatasource.items.length);
var draft = myCreateDatasource.item;
draft.BatchId = options.BatchId ;
draft.County = tempRecord.County ;
... // lot of assignments
console.log('About to create item ');
myCreateDatasource.createItem(function(createdRecord) {
console.log('Creating the Item ' + createdRecord._key);
app.datasources.RadiosTemp.query.filters.BatchId._equals = options.BatchId;
.....
});
Error message tells me that newly created item cannot be selected but I have no idea why?. If I change the datasource to Manual Save, I get the same error with no key since it is in Manual save mode.

How to separate multiple columns from a range in an array?

I have a range of data in a Google Sheet and I want to store that data into an array using the app script. At the moment I can bring in the data easily enough and put it into an array with this code:
var sheetData = sheet.getSheetByName('Fruit').getRange('A1:C2').getValues()
However, this puts each row into an array. For example, [[Apple,Red,Round],[Banana,Yellow,Long]].
How can I arrange the array by columns so it would look: [[Apple,Banana],[Red,Yellow],[Round,Long]].
Thanks.
It looks like you have to transpose the array. You can create a function
function transpose(data) {
return (data[0] || []).map (function (col , colIndex) {
return data.map (function (row) {
return row[colIndex];
});
});
}
and then pass the values obtained by .getValues() to that function..
var sheetData = transpose(sheet.getSheetByName('Fruit').getRange('A1:C2').getValues())
and check the log. See if that works for you?
Use the Google Sheets API, which allows you to specify the primary dimension of the response. To do so, first you must enable the API and the advanced service
To acquire values most efficiently, use the spreadsheets.values endpoints, either get or batchGet as appropriate. You are able to supply optional arguments to both calls, and one of which controls the orientation of the response:
const wb = SpreadsheetApp.getActive();
const valService = Sheets.Spreadsheets.Values;
const asColumn2D = { majorDimension: SpreadsheetApp.Dimension.COLUMNS };
const asRow2D = { majorDimension: SpreadsheetApp.Dimension.ROWS }; // this is the default
var sheet = wb.getSheetByName("some name");
var rgPrefix = "'" + sheet.getName() + "'!";
// spreadsheetId, range string, {optional arguments}
var single = valService.get(wb.getId(), rgPrefix + "A1:C30");
var singleAsCols = valService.get(wb.getId(), rgPrefix + "A1:C30", asColumn2D);
// spreadsheetId, {other arguments}
var batchAsCols = valService.batchGet(wb.getId(), {
ranges: [
rgPrefix + "A1:C30",
rgPrefix + "J8",
...
],
majorDimension: SpreadsheetApp.Dimension.COLUMNS
});
console.log({rowResp: single, colResp: singleAsCols, batchResponse: batchAsCols});
The reply will either be a ValueRange (using get) or an object wrapping several ValueRanges (if using batchGet). You can access the data (if any was present) at the ValueRange's values property. Note that trailing blanks are omitted.
You can find more information in the Sheets API documentation, and other relevant Stack Overflow questions such as this one.

Show Log of a file in jgit when committng it as a BLOB

Implemented the above logic to create a new commit (with no parents) that contains only my file. Commits are fast in the repository as compared to CommitCommand commit = git.commit();
But I am not able to get the Logs of a particular file , the number of times it has been updated/revised , and every time i go for Constants.HEAD , I am getting null.
Any help will be of great advantage.
Git git = jGitUtil.openRepo();
Repository repository = git.getRepository();
ObjectInserter repoInserter = repository.newObjectInserter();
ObjectId commitId = null;
try
{
byte[] fileBytes= FileUtils.readFileToByteArray(sourceFile);
// Add a blob to the repository
ObjectId blobId = repoInserter.insert(org.eclipse.jgit.lib.Constants.OBJ_BLOB, fileBytes);
// Create a tree that contains the blob as file "hello.txt"
TreeFormatter treeFormatter = new TreeFormatter();
treeFormatter.append(actualFileName, FileMode.REGULAR_FILE, blobId);
ObjectId treeId = treeFormatter.insertTo(repoInserter);
System.out.println("File comment : " + relativePath + PortalConstants.FILESEPARATOR + actualFileName + PortalConstants.EP_DELIMETER + userComments);
// Create a commit that contains this tree
CommitBuilder commit = new CommitBuilder();
PersonIdent ident = new PersonIdent(user.getFirstName(), user.getUserId());
commit.setCommitter(ident);
commit.setAuthor(ident);
commit.setMessage(relativePath + PortalConstants.FILESEPARATOR + actualFileName + PortalConstants.EP_DELIMETER + userComments);
commit.setTreeId(treeId);
commitId = repoInserter.insert(commit);
System.out.println(" commitId : " + commitId.getName());
repoInserter.flush();
System.out.println("Flush Done");
}catch(IOException ioe){
log.logError(StackTraceUtil.getStackTrace(ioe));
System.out.println(StackTraceUtil.getStackTrace(ioe));
}
finally
{
repoInserter.release();
}
return commitId.getName();
}
I would probably use Add File and Commit File porcelain commands instead of trying to implement it myself. Then retrieving the log should be possible via something like this:
Iterable<RevCommit> logs = new Git(repository).log()
.all()
.call();
for(RevCommit rev : logs) {
System.out.println("Commit: " + rev + " " + rev.getName() + " " + rev.getId().getName());
}
Where you can retrieve the additional information based on the commit-id.
I have now also added this as new snippet Show Log
Note that if you are creating a commit with no parents, you are saying that there is no history. Therefore you won't be able to see any other changes from that history because it doesn't exist.
You probably should use a commit with the parent of the current position of the branch so that you'll be able to get more information.

Lucene.NET & Facete Search Solution

Hey just started using Lucene.NET, any was wondering if anyone had a working example of Lucene.NET with a faceted search.
I know this below link http://www.devatwork.nl/articles/lucenenet/faceted-search-and-drill-down-lucenenet/
Which looked great, but all it does is tell me the number of results in the faceted search but not actually how I can retrieve the index and details of those results. i.e as in a normal search in Lucene.NET.
I.e from that link he has the following snippet
private static void FacetedSearch(string indexPath, string genre, string term){
var searcher = new IndexSearcher(indexPath);
// first get the BitArray result from the genre query
var genreQuery = new TermQuery(new Term("genre", genre));
var genreQueryFilter = new QueryFilter(genreQuery);
BitArray genreBitArray = genreQueryFilter.Bits(searcher.GetIndexReader());
Console.WriteLine("There are " + GetCardinality(genreBitArray) + " document with the genre " + genre);
// Next perform a regular search and get its BitArray result
Query searchQuery = MultiFieldQueryParser.Parse(term, new[] {"title", "description"}, new[] {BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD}, new StandardAnalyzer());
var searchQueryFilter = new QueryFilter(searchQuery);
BitArray searchBitArray = searchQueryFilter.Bits(searcher.GetIndexReader());
Console.WriteLine("There are " + GetCardinality(searchBitArray) + " document containing the term " + term);
// Now do the faceted search magic, combine the two bit arrays using a binary AND operation
BitArray combinedResults = searchBitArray.And(genreBitArray);
Console.WriteLine("There are " + GetCardinality(combinedResults) + " document containing the term " + term + " and which are in the genre " + genre);
}
Which will tell me i.e there is 2 records for the search term "Dublin" and which are in genre "Financial" which is perfect but the article seems to skip the part where it says how I can retrieve the indexes of those results and display on screen.
He does explain this in the link below for a normal search but not facete search..
i.e Normal Search
private static void Search(string indexPath, string term)
{
// create searcher
var searcher = new IndexSearcher(indexPath);
// create a query which searches through the title and description, the term can be in the title or the description
Query searchQuery = MultiFieldQueryParser.Parse(term, new[] {"title", "description"}, new[] {BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD}, new StandardAnalyzer());
// perform the search
Hits hits = searcher.Search(searchQuery);
// loop through all the hits and show their title
for (int hitIndex = 0; hitIndex &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt; hits.Length(); hitIndex++)
{
// get the corresponding document
Document hitDocument = hits.Doc(hitIndex);
// write its title to the console
Console.WriteLine(hitDocument.GetField("title").StringValue());
}
}
http://www.devatwork.nl/articles/lucenenet/search-basics-lucenenet/
Any help would be greatly appreciated
Edit :
Or should I do a search query and then do a Filter on the results ?
The BitArray represents hits. Each 1 has an index, that is equal to document id
So 1001001 means that documents with position 0, 3 and 6 in index match your search. You just have to retrieve them from lucene index.
var searcher = new IndexSearcher(indexPath);
// get document at position 0
var doc = searcher.Doc( 0 );

Resources