How to get anchor point of SymbolItem - adobe-illustrator

I can't figure out how to retrieve registration point that I see in properties panel transform section in script.
I use this script documentation http://ai.aenhancers.com/jsobjref/SymbolItem/

As far as I can tell they are just coordinates of the symbol's center. You can get them this way:
var symbol = app.activeDocument.selection[0];
var X = symbol.position[0] + symbol.width/2;
var Y = -symbol.position[1] + symbol.height/2;
alert("X: " + X + "\n" + "Y: " + Y);

Related

Create Google Script that saves sheet as pdf to specified folder in google drive

So thanks to other members I was able to piece together a script that does what I need except for 1 small hiccup. Rather than saving the single sheet as a pdf in the designated folder, it saves the entire workbook. I've tried multiple variations to get it to save just the sheet I want (named JSA) but it either gives me an error message or continues to download the whole spreadsheet. I'm sure it's something simple I'm missing, but I'm not as versed with Script as I am with writing Macros, so I'm stuck. The first part of the code, downloading it as a PDF works like a charm, it's the last section where I want it to save the PDF to a specified folder that's the issue. Any assistance would be appreciated.
function downloadPdf() {
var ss = SpreadsheetApp.getActive(),
id = ss.getId(),
sht = ss.getActiveSheet(),
shtId = sht.getSheetId(),
url =
'https://docs.google.com/spreadsheets/d/' +
id +
'/export' +
'?format=pdf&gid=' +
shtId
+ '&size=letter' // paper size legal / letter / A4
+ '&portrait=false' // orientation, false for landscape
+ '&scale=2' // 1= Normal 100% / 2= Fit to width / 3= Fit to height / 4= Fit to Page
+ '&fitw=true' // fit to width, false for actual size
+ '&top_margin=0.25' // All four margins must be set!
+ '&bottom_margin=0.25' // All four margins must be set!
+ '&left_margin=0.25' // All four margins must be set!
+ '&right_margin=0.25' // All four margins must be set!
+ '&sheetnames=false&printtitle=false' // hide optional headers and footers
+ '&pagenum=false&gridlines=false' // hide page numbers and gridlines
+ '&fzr=false' // do not repeat row headers (frozen rows) on each page
+ '&horizontal_alignment=CENTER' //LEFT/CENTER/RIGHT
+ '&vertical_alignment=TOP'; //TOP/MIDDLE/
var val = SpreadsheetApp.getActive().getRange('H2').getValues();//custom pdf name here
var val2= Utilities.formatDate(SpreadsheetApp.getActive().getRange("N2").getValue(), ss.getSpreadsheetTimeZone(), "MM/dd/YY");
var val3= " - "
val += val3 += val2 += '.pdf';
//can't download with a different filename directly from server
//download and remove content-disposition header and serve as a dataURI
//Use anchor tag's download attribute to provide a custom filename
var res = UrlFetchApp.fetch(url, {
headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() },
});
SpreadsheetApp.getUi().showModelessDialog(
HtmlService.createHtmlOutput(
'<a target ="_blank" download="' +
val +
'" href = "data:application/pdf;base64,' +
Utilities.base64Encode(res.getContent()) +
'">Click here</a> to download, if download did not start automatically' +
'<script> \
var a = document.querySelector("a"); \
a.addEventListener("click",()=>{setTimeout(google.script.host.close,10)}); \
a.click(); \
</script>'
).setHeight(50),
'Downloading PDF..'
);
const folderName = `Test`;
const fileNamePrefix = val += val3 += val2 += '.pdf';
var JSA = SpreadsheetApp.getActiveSpreadsheet();
var s = JSA.getSheetByName("JSA");
DriveApp.getFoldersByName(folderName)
.next()
.createFile(SpreadsheetApp.getActiveSpreadsheet()
.getBlob()
.getAs(`application/pdf`)
.setName(`${fileNamePrefix}`));
}
I believe your goal is as follows.
You want to create a PDF file, which is downloaded using the first part of your script, in the specific folder on Google Drive.
In this case, how about the following modification? I thought that res might be able to be used.
From:
var JSA = SpreadsheetApp.getActiveSpreadsheet();
var s = JSA.getSheetByName("JSA");
DriveApp.getFoldersByName(folderName)
.next()
.createFile(SpreadsheetApp.getActiveSpreadsheet()
.getBlob()
.getAs(`application/pdf`)
.setName(`${fileNamePrefix}`));
To:
DriveApp.getFoldersByName(folderName)
.next()
.createFile(res.getBlob().setName(`${fileNamePrefix}`));
In this modification, it supposes that sht = ss.getActiveSheet(), is JSA sheet. If the active sheet is not JSA sheet, please modify as follows.
To:
const url2 =
'https://docs.google.com/spreadsheets/d/' +
id +
'/export' +
'?format=pdf&gid=' +
ss.getSheetByName("JSA").getSheetId()
+ '&size=letter' // paper size legal / letter / A4
+ '&portrait=false' // orientation, false for landscape
+ '&scale=2' // 1= Normal 100% / 2= Fit to width / 3= Fit to height / 4= Fit to Page
+ '&fitw=true' // fit to width, false for actual size
+ '&top_margin=0.25' // All four margins must be set!
+ '&bottom_margin=0.25' // All four margins must be set!
+ '&left_margin=0.25' // All four margins must be set!
+ '&right_margin=0.25' // All four margins must be set!
+ '&sheetnames=false&printtitle=false' // hide optional headers and footers
+ '&pagenum=false&gridlines=false' // hide page numbers and gridlines
+ '&fzr=false' // do not repeat row headers (frozen rows) on each page
+ '&horizontal_alignment=CENTER' //LEFT/CENTER/RIGHT
+ '&vertical_alignment=TOP'; //TOP/MIDDLE/
const res2 = UrlFetchApp.fetch(url2, {
headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() },
});
DriveApp.getFoldersByName(folderName)
.next()
.createFile(res2.getBlob().setName(`${fileNamePrefix}`));
Reference:
fetch(url, params)

How to fix the issue of output file not appearing, after having launched a run configuration?

I work on CVRP in combinatorial optimization, where the goal is to compare several models on several instances, using the OPL language. For this to e done, I first wrote and tested the said models; then I wrote an main flow control supposed to run each instance for a 2 hours duration.
My problem is that after 2 hours, and this for each model, the output file appears for some instances, containing the desired information; but for other instances, the output files do not appear, as if these instances do not exist. This problem persists even when you launch one or more of these instances in isolation.
below is the main flow control code, where BPF designates the name of the .mod file, which is simply modified in the code, when one wishes to switch to another model.
{string} datFiles=...;
main {
var source = new IloOplModelSource("BPF.mod");
var cplex = new IloCplex();
var def = new IloOplModelDefinition(source);
cplex.tilim=2*60*60;
cplex.threads=1;
for(var datFile in thisOplModel.datFiles)
{
var opl = new IloOplModel(def,cplex);
var data2= new IloOplDataSource(datFile);
opl.addDataSource(data2);
opl.generate();
var o=new IloOplOutputFile("BPF "+datFile+".txt");
if (cplex.solve()) {
if(cplex.getCplexStatus()==11){
o.writeln("instance : " + datFile
+" / opt = "
+ " / UB = " + cplex.getObjValue()
+ " / LB = " + cplex.getBestObjValue()
+" / time = " + " - "
+" / Gap = "+cplex.getMIPRelativeGap()*100+"%");
}
else {
o.writeln("instance : " + datFile
+ " / opt = " + cplex.getObjValue()
+ " / UB = " + cplex.getBestObjValue()+"*"
+" / time = " + cplex.getSolvedTime()
+ " / Gap : -");
}
o.close();
}
opl.end();
}
}

Google Apps script created file is not PDF

I'm trying to create a PDF file with this code:
var name = "test.pdf";
var url = 'https://docs.google.com/spreadsheets/d/' + newSpreadsheetID + '/export?exportFormat=pdf&format=pdf' +
'&size=A4' +
'&portrait=true' +
'&fitw=true' + // fit to width, false for actual size
'&sheetnames=false&printtitle=false&pagenumbers=false' +
'&gridlines=false' +
'&fzr=false' + // do not repeat frozen rows on each page
'&gid='+SheetID; //the sheet's Id
var pdf = UrlFetchApp.fetch(url);
var pdf = pdf.getBlob().setName(name);
DocsList.createFile(pdf);
This code creates a file but the file contains just plain text, can you guys help me to get it into PDF format?
First off, DocsList was deprecated (https://developers.google.com/apps-script/reference/docs-list/docs-list). So I think we should use DriveApp this time.
I ignored the parameters you used to format the pdf, the script can be simply as -
var sheet = DriveApp.getFileById(spreadsheetId);
DriveApp.createFile(sheet.getAs("application/pdf"));
Please let me know if you want more elaboration. :)
I made a few changes and got your call working. I don't know where the documentation for the export settings are, but some of them don't work such as "gridlines". Also below is a 2 line example of the same thing.
function makePDF(){
var newSpreadsheetID = SpreadsheetApp.getActive().getId()
var SheetID="Sheet1";
var name = "test.pdf";
var url = 'https://docs.google.com/spreadsheets/d/' + newSpreadsheetID + '/export?exportFormat=pdf&format=pdf'; +
'&size=A4' +
'&portrait=true' +
'&fitw=true' + // fit to width, false for actual size
'&sheetnames=false&printtitle=false&pagenumbers=false' +
'&gridlines=false' +
'&fzr=false'; + // do not repeat frozen rows on each page
'&gid='+SheetID; //the sheet's Id
var pdf = UrlFetchApp.fetch(url,{headers: {authentication:"Bearer " + ScriptApp.getOAuthToken()}, muteHttpExceptions:true}).getBlob();
pdf.setName(name);
DriveApp.createFile(pdf);
}
function simplePDFConvert(){
var ss = SpreadsheetApp.openById( spreadSheetId );
DriveApp.createFile(ss.getBlob());
}

How to add line break to labels on axis for IE9?

I'm using Dojo 1.9.1.
I'm using dojox.charting to draw some charts.
I am using a labelFunc to produce a date/time label for my X-axis. This is working fine in all browsers.
But I want to add a line break to my label so that the date sits above the time, e.g.:
10/01/2014
06:00
I can add a html break tag to the string returned and this works in Chrome and Firefox but not IE9 (to be expected).
Has anybody solved how to do this one that works across all browsers including IE9 (or specifically ones that don't "do" html labels).
Cheers
Ian
My label func:
_labelFull: function (index) {
// Returns a label in the form "dd/mm/yyyy hh:mm" for tooltip labelling
var dt,
d;
dt = new Date(Date.parse(myglobalStartDateTime));
dt.setHours(dt.getHours() + Number(index));
// Full date/time
d = ("0" + dt.getDate()).slice(-2) + '/' +
("0" + (dt.getMonth() + 1)).slice(-2) + '/' +
dt.getFullYear() + ' ' +
("0" + dt.getHours()).slice(-2) + ':' +
("0" + dt.getMinutes()).slice(-2) + 'UTC';
return d;
}

Recorded Skeleton Data

The following is code I have used to try to record skeleton frame data
using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
if (skeletonFrame == null)
return;
this.Recorder.Record(skeletonFrame);
}
if the code above is run, what information is recorded?
If I were to save this information to an external file, what would I see?
Would there be coordinate information and a specific timestamp associated with each coordinate information?
Are you looking at recording the X, Y, Z data of the skeleton into a text file? It is generally easier to record the information separately in readable format. If you are looking at doing the aforementioned then this may help:
//save the XYZ of the skeleton data, but also save the XZ of depth data
private void saveCoordinates(Skeleton skeleton, string textFile)
{
StreamWriter coordinatesStream = new StreamWriter(newPath + "\\" + textFile);
foreach (Joint joint in skeleton.Joints)
{
coordinatesStream.WriteLine(joint.JointType + ", " + joint.TrackingState + ", " + joint.Position.X + ", " + joint.Position.Y + ", " + joint.Position.Z);
}
coordinatesStream.Close();
}