Data out of range with Indesign scripting, because of small page size - adobe-indesign

I'm getting Data out of range with a Indesign jsx script.
My scripts stops at: Line 102 Source: pageWidth = width;
I think it's because of the margin is larger then the paper size. I tried to handle the scenario of the smallest paper size: A11, with a if else statement.
And I tried to remove the masterpage, with app masterpages remove and pop, but I don't know how to do that.
How can I give all the paper sizes a margin of "5mm", and the "A11" a margin of "0mm"? I'm using Indesign CS6 on Windows 7.
This is my JSON data:
var papersizes = [
{
"name": "4A0",
"length": 2378,
"width": 1682
},
{
"name": "2A0",
"length": 1682,
"width": 1189
},
{
"name": "A0",
"length": 1189,
"width": 841
},
{
"name": "A1",
"length": 841,
"width": 594
},
{
"name": "A2",
"length": 594,
"width": 420
},
{
"name": "A3",
"length": 420,
"width": 297
},
{
"name": "A4",
"length": 297,
"width": 210
},
{
"name": "A5",
"length": 210,
"width": 148
},
{
"name": "A6",
"length": 148,
"width": 105
},
{
"name": "A7",
"length": 105,
"width": 74
},
{
"name": "A8",
"length": 74,
"width": 52
},
{
"name": "A9",
"length": 52,
"width": 37
},
{
"name": "A10",
"length": 37,
"width": 26
},
{
"name": "A11",
"length": 26,
"width": 18
}
];
This is my code:
var bleed = "4mm";
var margin = "10mm";
for (index = 0; index < papersizes.length; ++index) {
papersize = papersizes[index];
name = papersize["name"];
length = papersize["length"];
width = papersize["width"];
var doc = app.documents.add();
with(doc.viewPreferences) {
horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
}
with(doc.documentPreferences) {
pageHeight = length;
//Here does my script stops
pageWidth = width;
pageOrientation = PageOrientation.PORTRAIT;
pagesPerDocument = 1;
documentBleedBottomOffset = bleed;
documentBleedTopOffset = bleed;
documentBleedInsideOrLeftOffset = bleed;
documentBleedOutsideOrRightOffset = bleed;
}
//Here I try to handle the paper size
if(name != "A11") {
with (doc.pages.item(0).marginPreferences){
bottom = margin;
//When document.documentPreferences.facingPages == true,
//"left" means inside; "right" means outside.
left = margin;
right = margin;
top = margin;
}
} else {
with (doc.pages.item(0).marginPreferences){
bottom = 0;
//When document.documentPreferences.facingPages == true,
//"left" means inside; "right" means outside.
left = 0;
right = 0;
top = 0;
}
}
//If the active document has not been saved (ever), save it.
if(app.activeDocument.saved == false){
//If you do not provide a file name, InDesign will display the Save dialog box.
app.activeDocument.save(new File("C:/IndesignOutput/DIN_"+name+"_"+length+"mm_"+width+"mm.indd"));
app.activeDocument.close();
}
}

You are correct, you can't change the document size because of the default marges. So yes: changing them should make it work. However, you must change them before attempting to set this small size, not afterwards.
But, alas, that's not the only thing. As it appears, it is not enough to change just the current page – resizing a document also resizes its master spreads, and so you need to change those as well.
My usual trick to set a number of items to use the same properties is this:
// doc.masterSpreads.item(0).pages.everyItem().marginPreferences.properties = { ... };
... but, quite surprising, everyItem does nothing here! So you have to manually loop over the pages in masterSpreads. Fortunately, you don't have to change the first page of the document, because by default it has this first master spread applied.
It still didn't work, and after a bit of trial-and-error I found there is another set of margins that you need to reset: the document's own defaults. (No idea why. Maybe in case you delete all master spreads, or something odd like that, and the margin values still need to 'live' somewhere.)
This works for me:
length = 26;
width = 18;
bleed = "4mm";
margin = "10mm";
var doc = app.documents.add();
with(doc.viewPreferences) {
horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
}
doc.marginPreferences.properties = { top:0, bottom:0, left:0, right: 0 };
for (i=0; i<doc.masterSpreads.item(0).pages.length; i++)
doc.masterSpreads.item(0).pages.item(i).marginPreferences.properties = {
bottom:0,
//When document.documentPreferences.facingPages == true,
//"left" means inside; "right" means outside.
left:0,
right:0,
top:0
};
with(doc.documentPreferences) {
pageOrientation = PageOrientation.PORTRAIT;
pagesPerDocument = 1;
documentBleedBottomOffset = bleed;
documentBleedTopOffset = bleed;
documentBleedInsideOrLeftOffset = bleed;
documentBleedOutsideOrRightOffset = bleed;
pageHeight = length;
pageWidth = width;
}
Checking the name, by the way, is just fine if you know in advance which name will cause the problem. But it may be better to find out below what sizes (either width or height) the problem occurs, and set the margins to 0 if either size is too low.

Related

How can i create thumbnails with image, with coord X-0, Y-0

Voyager creates a crop on from the center, and I need to crop the beginning of the image. How do I do this? Only the width and height of the crop are specified in the documentation.
"name": "cropped",
"crop": {
"width": "300",
"height": "250"
}
Right in there documentation about cropping it shows
"thumbnails": [
{
"type": "crop",
"name": "crop-500-500",
"width": 500, // Required
"height": 500, // Required
"x": 50, // Optional. Left offset
"y": 50, // Optional. Top offset
}
]

ESRI Js API 4.15 : FeatureLayer labels are not visible on all features

I'm trying to show labels on a point FeatureLayer, the label is not visible for just one Feature, But it become visible when the map change scale, is there any explanation?
Here is my code:
"renderer": {
"type": "class-breaks",
"field": "nums",
"classBreakInfos": [
{
"minValue": 0,
"maxValue": 9,
"label": " < 10",
"symbol": {
"type": "picture-marker",
"url": "./assets/picto/nums/vert.png",
"width": 30,
"height": 50
}
},
{
"minValue": 10,
"maxValue": 19,
"label": " 10 à 19",
"symbol": {
"type": "picture-marker",
"url": "./assets/picto/nums/orange.png",
"width": 30,
"height": 50
}
},
{
"minValue": 20,
"maxValue": 1000000,
"label": " > 19",
"symbol": {
"type": "picture-marker",
"url": "./assets/picto/nums/rouge.png",
"width": 30,
"height": 50
}
}
]
},
"labelingInfo": [
{
"labelExpressionInfo": {
"expression": "$feature.nums"
},
"labelPlacement": "center-center",
"symbol": {
"type": "text",
"color": "black",
"haloColor": "white",
"xoffset": -2,
"yoffset": 13,
"font": {
"size": 7,
"family": "sans-serif",
"weight": "bolder"
}
}
}
]
I joined a picture of the FeatureLayer labels problem:
Base on you definition, you are using the default deconflict strategy ("static"). Sometimes when overlaps occurs the overlapped label is not showed. Depends on the situation this strategy make sense or not.
You could try "none" option, to turn off deconfliction and you should not have that issue. It seems it might be what you are looking for.
labelClass.deconflictionStrategy = "none";
ArcGIS JS API - LabelClass deconflictionStrategy

Retrieving object from TreeMap

I've been working with few charts of amCharts 4, and everytime I struggled to subscribe to the event that returns the "selected/clicked" element. I don't know what I've been missing from the doc, but for example, I need to retrieve the selected item from "hit" event but i can't find anywhere (here is a simple i'd like to try this on https://codepen.io/team/amcharts/pen/erojQb)
var chart = am4core.create("chartdiv", am4charts.TreeMap);
chart.data = [{
"name": "First",
"value": 190
}, {
"name": "Second",
"value": 289
}, {
"name": "Third",
"value": 635
}, {
"name": "Fourth",
"value": 732
}, {
"name": "Fifth",
"value": 835
}];
/* Set color step */
chart.colors.step = 2;
/* Define data fields */
chart.dataFields.value = "value";
chart.dataFields.name = "name";
I tried this:
chart.seriesTemplates.template.columns.events.on('hit', function(ev) {
console.log('mlkmlz');
});
but not called, and this:
chart.seriesContainer.events.on('hit', function(ev) {
console.log(ev.target.dataItem)
});
but no dataItem attached
OK, so it's a bit more complicated than that. To attach events, you'll need to to actually create series for the specific level, then attach events on its column template:
var series = chart.seriesTemplates.create("0");
series.columns.template.events.on('hit', function(ev) {
console.log(ev.target.dataItem);
});

Amcharts Pie Prevent Caching

It seems that Amchart is caching the json and it is not drawing the graph nor legend.
First time I open the modal it displays fine, but if I close it and open again it displays all the data in labels (taken from the same JSON), but the chart is not being drawed. Is it a caching issue?
This is the way I am drawing it:
var modelPie = #Html.Raw(jsonPie);
var dataProvider = [];
dataProvider = modelPie.UsefulLifes;
var chartdivdounut = AmCharts.makeChart("chartdivdounut", {
"type": "pie",
"startDuration": 0,
"theme": "light",
"addClassNames": true,
"legend": {
"position": "right",
"marginRight": 0,
"autoMargins": false
},
"innerRadius": "30%",
"defs": {
"filter": [{
"id": "shadow",
"width": "200%",
"height": "200%",
"feOffset": {
"result": "offOut",
"in": "SourceAlpha",
"dx": 0,
"dy": 0
},
"feGaussianBlur": {
"result": "blurOut",
"in": "offOut",
"stdDeviation": 5
},
"feBlend": {
"in": "SourceGraphic",
"in2": "blurOut",
"mode": "normal"
}
}]
},
"dataProvider": dataProvider,
"valueField": "Value",
"titleField": "FieldName",
"showZeroSlices": false,
"labelsEnabled": false,
"export": {
"enabled": true
}
});
chartdivdounut.addListener("init", handleInit);
chartdivdounut.addListener("rollOverSlice", function (e) {
handleRollOver(e);
});
function handleInit() {
chartdivdounut.legend.addListener("rollOverItem", handleRollOver);
}
function handleRollOver(e) {
var wedge = e.dataItem.wedge.node;
wedge.parentNode.appendChild(wedge);
}
enter code here
I realized that the script section in the partial view was being executed just one time.
Seems to be something messed up. I re-wrote that part of the code and it started to work properly.

Make Amcharts slice take the whole pie chart

I'm trying to trying to remove a small gap when I have a pie chart with a 100% slice.
I've tried to give it a outlineThickness of 0 but there is still a very small gap.
Here is an example.
var chart = AmCharts.makeChart( "chartdiv", {
"type": "pie",
"theme": "light",
"dataProvider": [ {
"country": "Lithuania",
"litres": 10
}],
"outlineThickness": 0,
"outlineAlpha": 1,
"valueField": "litres",
"titleField": "country",
"balloon":{
"fixedPosition":true
},
"export": {
"enabled": true
}
} );
The only way to work around this in current version is to apply the same color to outline as the slice itself. You can use outlineColor for that:
https://jsfiddle.net/s083cdpk/1/
Please note that this should be applies only if there's only one slice, as the same color will be applied to all slices if there are more.
This options should be used:
"outlineThickness": 1,
"outlineAlpha": 1,
"outlineColor": undefined
Example

Resources