Taking a screenshot of a page in InDesign Extension Builder - actionscript-3

For my current assignment I need to make an extension for Adobe InDesign using Adobe Creative Suit Extension Builder and Flash Builder. I guess this is more of a question for ones that know Extension Builder and InDesign API.
The point of this extension is to load some data and send some data to a server. I need to make a screenshot of a page, then send it in jpg to a server. But, there are no (or at least i couldnt find any) ways to create a bitmap(to cast it on a object seems impossible, because this Objects are just Objects, and not DisplayObjects).
I managed to silently export pages as jpegs, now I'm thinking about loading them and sending but that will require building an AIR app to handle it all, so this will be a bit bulky.
So to sum up the question, how to take a screencapture of all elements on a page in InDesign using CS Ext.Builder?

what is the problem with export to JPG ? You can choose to export the page or the objects themselves.
Here is a snippet I wrote in a recent project. Hope it helps.
public static function getFilePath():String {
var app:com.adobe.indesign.Application = InDesign.app;
var sel:* = app.selection, oldResolution:Number, oldColorSpace:JpegColorSpaceEnum, groupItems:Array = [], i:int = 0, n:int = sel.length;
if (!sel || !n )
{
Alert.show("Pas de selection !", "title", Alert.OK, Sprite(mx.core.Application.application));
return "";
}
for ( i = 0 ; i < n ; i ++ )
{
groupItems [ groupItems.length ] = sel[i];
}
sel = ( sel.length > 1 )? app.activeDocument.groups.add ( sel ) : sel[0] ;
var tempFolder:File = File.createTempDirectory();
AppModel.getInstance().jpgFolder = tempFolder;
var jpgFile:File = new File ();
jpgFile.nativePath = tempFolder.nativePath + "/temp.jpg";
oldResolution = app.jpegExportPreferences.exportResolution;
app.jpegExportPreferences.exportResolution = 72;
oldColorSpace = app.jpegExportPreferences.jpegColorSpace;
app.jpegExportPreferences.jpegColorSpace = JpegColorSpaceEnum.GRAY;
sel.exportFile ( ExportFormat.jpg, jpgFile );
app.jpegExportPreferences.jpegColorSpace = oldColorSpace;
app.jpegExportPreferences.exportResolution = oldResolution;
if ( sel is Group )
{
sel.ungroup();
app.select ( groupItems );
}
return jpgFile.nativePath;
}

Related

Is there a simple way to have a local webpage display a variable passed in the URL?

I am experimenting with a Firefox extension that will load an arbitrary URL (only via HTTP or HTTPS) when certain conditions are met.
With certain conditions, I just want to display a message instead of requesting a URL from the internet.
I was thinking about simply hosting a local webpage that would display the message. The catch is that the message needs to include a variable.
Is there a simple way to craft a local web page so that it can display a variable passed to it in the URL? I would prefer to just use HTML and CSS, but adding a little inline javascript would be okay if absolutely needed.
As a simple example, when the extension calls something like:
folder/messageoutput.html?t=Text%20to%20display
I would like to see:
Message: Text to display
shown in the browser's viewport.
You can use the "search" property of the Location object to extract the variables from the end of your URL:
var a = window.location.search;
In your example, a will equal "?t=Text%20to%20display".
Next, you will want to strip the leading question mark from the beginning of the string. The if statement is just in case the browser doesn't include it in the search property:
var s = a.substr(0, 1);
if(s == "?"){s = substr(1);}
Just in case you get a URL with more than one variable, you may want to split the query string at ampersands to produce an array of name-value pair strings:
var R = s.split("&");
Next, split the name-value pair strings at the equal sign to separate the name from the value. Store the name as the key to an array, and the value as the array value corresponding to the key:
var L = R.length;
var NVP = new Array();
var temp = new Array();
for(var i = 0; i < L; i++){
temp = R[i].split("=");
NVP[temp[0]] = temp[1];
}
Almost done. Get the value with the name "t":
var t = NVP['t'];
Last, insert the variable text into the document. A simple example (that will need to be tweaked to match your document structure) is:
var containingDiv = document.getElementById("divToShowMessage");
var tn = document.createTextNode(t);
containingDiv.appendChild(tn);
getArg('t');
function getArg(param) {
var vars = {};
window.location.href.replace( location.hash, '' ).replace(
/[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
function( m, key, value ) { // callback
vars[key] = value !== undefined ? value : '';
}
);
if ( param ) {
return vars[param] ? vars[param] : null;
}
return vars;
}

How do i parse the KairosSDK JSON recognise response in Swift?

For those who don't know what the Kairos SDK is, it's basically a facial recognition api.
When you give it an image, it will tell you who if they can match you with someone in the database.
When i give it an image; the api sends me back this response:
[images: (
{
attributes = {
gender = {
confidence = "80%";
type = F;
};
};
candidates = (
{
"enrollment_timestamp" = 1436883322;
face3rd = "0.988351106643677";
},
{
"enrollment_timestamp" = 1436883214;
hi = "0.94137054681778";
},
{
"enrollment_timestamp" = 1436883132;
hi = "0.94137054681778";
}
);
time = "6.43676";
transaction = {
confidence = "0.988351106643677";
"distance_apart" = "0.046980559825897";
"gallery_name" = test1;
height = 482;
"matching_threshold" = "0.4";
"next_subject" = hi;
"next_subject_confidence" = "0.94137054681778";
"simularity_threshold" = "0.1";
status = success;
subject = face3rd;
topLeftX = 148;
topLeftY = 92;
width = 482;
};
}
)]
What i have done is put three images in the database and have called each of them respectively, face3rd, hi, hi (sorry for the two hi's)
I have been trying to parse the names and the number next to it for soo long, i can get around the 6 second response time.
The reason i have not been able to get the names is because, as you can see, i don't know what to tell Swift to look for. The image name changes depending on who i get back.
I don't know if i've explained my situation, bestly, but if you look at the response. The parts that say:
face3rd = "0.988351106643677";
hi = "0.94137054681778";
hi = "0.94137054681778";
I need the information on both sides of the equal sign.
Thank you for your help and apologise, if reading it was pedantic or you felt like their was a lot of repetion.
Thanks!
Yes, it is poorly formatted JSON that we are returning. We will fix it in an upcoming version of the API (no release date at this time..sorry).
If all you need is the closest match, you can just access the subject variable directly and ignore the candidates array.
Otherwise, you would need to parse the candidates array manually unfortunately. I'm not sure how to do that in Swift.

Why does MusicProperties->Year always return the current year?

I'm trying to get the music properties for each file in the music library by using the StorageFolder APIs.
After calling GetFilesAsync(CommonFileQuery::OrderByName) on my music library I'm iterating over the resulting IVectorView^ and calling StorageFile->Properties->GetMusicPropertiesAsync() for each file, which is inherently slow but I have to do it this way, since QueryOptions are not supported on Windows Phone for some reason.
Anyway, after completing that task every property is correct except for MusicProperties->Year, which is 2014 for every single one of well over 900 music files on my phone. Here's a short code snippet:
create_task(lib->GetFilesAsync(Search::CommonFileQuery::OrderByName))
.then([](IVectorView<StorageFile^>^ songFiles)
{
auto taskPtr = std::make_shared<std::vector<task<Song>>>(songFiles->Size);
for (size_t i = 0, len = songFiles->Size; i < len; ++i)
{
StorageFile^ song = songFiles->GetAt(i);
(*taskPtr)[i] = create_task(song->Properties->GetMusicPropertiesAsync()).then([]
(MusicProperties^ props)
{
Song s;
s.album = std::wstring(std::move(props->Album->Data()));
s.artist = std::wstring(std::move(props->Artist->Data()));
s.title = std::wstring(std::move(props->Title->Data()));
s.track = props->TrackNumber;
s.year = props->Year;
return s;
});
}
//further processing is done in a when_all function after the song tasks have completed
}
Song is just a plain struct to save my result temporarily and convert it to JSON later on, but that Year property is freaking me out. Has anybody else encountered that issue already and is there any other way to retrieve the proper release year from a music file?

Hiding initial value in Imported Database Model of Enterprise Architect

I am currently creating database model by doing reverse-engineering MS SQL Server 2008 into Sparx's Enterprise Architect version 10.
I have been able to import tables, and hide items that are not required (such operations and stereotypes). However, I did not find the option to hide for Column Initial values when importing tables or in diagram properties, which left me the option to edit each column one by one (time consuming).
Do I miss any configuration to hide the Initial value? If such configuration does not exist, what is the best method to hide/remove the Initial value without configuration?
Finally got the solution by creating EA script. Feels free to use and enhance it :)
!INC Local Scripts.EAConstants-JScript
function OnProjectBrowserScript()
{
// Show the script output window
Repository.EnsureOutputVisible( "Script" );
var treeSelectedType = Repository.GetTreeSelectedItemType();
switch ( treeSelectedType )
{
case otElement: // if select table
{
removeInitial(Repository.GetContextObject());
break;
}
case otPackage: // if select package containing table
{
var selectedObject as EA.Element;
selectedObject = Repository.GetContextObject();
for ( var i = 0 ; i < selectedObject.Elements.Count ; i++ )
{
removeInitial(selectedObject.Elements.GetAt( i ));
}
break;
}
default:
{
// Error message
Session.Prompt( "This script does not support items of this type.", promptOK );
}
}
}
function removeInitial(selectedObject)
{
for (var i = 0 ; i < selectedObject.Attributes.Count; i++)
{
var attrib as EA.Attribute;
attrib = selectedObject.Attributes.GetAt(i);
attrib.Default = "";
attrib.Update();
}
Session.Output("finished updating " + selectedObject.Name);
}
OnProjectBrowserScript();

Dynamic variables in ActionScript 3.0

so.... eval() out of the question, any idea to do this? I also don't know how to use "this" expression or set() in actionscript 3 ( i seem couldn't find any complete reference on it ), just say through php file a multiple variable (test1, test2, test3,...) sent by "echo", how the flash aplication recieved it? I'm trying not to use xml on mysql to php to flash aplication. Simply how to change a string to a variable ?
example
(in as3-actions frame panel)
function datagridfill(event:MouseEvent):void{
var varfill:URLVariables = new URLVariables();
varfill.tell = "do it";
var filler:URLRequest = new URLRequest();
filler.url = "http://127.0.0.1/flashdbas3/sendin.php";
filler.data = varfill;
var filling:URLLoader = new URLLoader();
filling.dataFormat = URLLoaderDataFormat.VARIABLES;
filling.load(filler);
filling.addEventListener(Event.COMPLETE, datain);
function datain(evt:Event){
var arraygrid:Array = new Array();
testing.text = evt.target.Name2 // worked
// just say i = 1
i=1;
arraygrid.push({Name:this["evt.target.Name"+i],
Test:this.["evt.target.Test"+i]}); // error
//or
arraygrid.push({Name:this["Name"+i],
Test:this.["Test"+i]}); // error too
// eval() noexistent, set() didn't worked on actions frame panel
//?????
}
};
I hope it's very clear.
You could use this[varName] if I understand your question right.
So if varName is a variable containing a string which should be a variables name, you could set and read that variable like this:
this[varName] = "someValue";
trace(this[varName]);
Update:
In your example, you could try: evt.target["Test"+i] instead of Test:this.["evt.target.Test"+i]
If you have a set of strings that you'd like to associate with values, the standard AS3 approach is to use an object as a hash table:
var o = {}
o["test1"] = 7
o["test2"] = "fish"
print(o["test1"])