Copy link to clipboard
Copied
Hello,
I'll try to describe my problems:
We have about 20 scripts that ran great and reliable in Illustrator CS6 on macOS.
Now the scripts still work under Illustrator CC 2020 (24.3), but no longer reliably.
What does not mean reliable: We use the same script 15x in a row in the same document and it works great 14x and then it only works half.
After restarting Illustrator it works fine again in the same document in the same place, until at some point it doesn't work anymore.
I can't provoke this not working cleanly nor link it to any boundary conditions.
Do you have any ideas?
Copy link to clipboard
Copied
do all 20 scripts work 14 out of 15 times?
post at least one of the scripts that fail.
The usual suspects are variable declarations inside loops.
Copy link to clipboard
Copied
Hi Carlos,
I followed your hint and do the varaibale declaration outside of the loop now.
But still get something error: Error 1200: an Illustrator error occurred: 1346458189 ('MRAP') Line : 150 ->
Copy link to clipboard
Copied
#target illustrator
#targetengine main
// based on
// Box4selectedPath.jsx
// for selected pathItems // CS3
// creates a green rectangle around all the selected paths (visibleBounds)
// regards pixxxelschubser
// http://forums.adobe.com/thread/1183584
// Script erkennt jetzt die Höhe/Breite des Objekts und macht dann dementsprechend nur eine passende Vermassung.
function bemassmich (){
var Sel = app.activeDocument.selection;
var StrtPOrigin = app.activeDocument.pageOrigin;
var StrtROrigin = app.activeDocument.rulerOrigin;
app.activeDocument.pageOrigin = Array(0,0);
app.activeDocument.rulerOrigin = Array(0,0);
var mm = 72/25.4;
var regColor = findOrCreateColor ("VMI", 100, 0, 100, 0)
var regColor = new SpotColor();
regColor.spot = app.activeDocument.spots['VMI'];
var vmLayer = findOrCreateLayer("VMI") ;
vmLayer.locked = false;
//Skalierungsfaktor berechnen
var abBounds = app.activeDocument.artboards[0].artboardRect;
var dokbreite = ((abBounds[2]-abBounds[0])/mm)-24;
//var dokhoehe = ((abBounds[1]-abBounds[3])/mm)-24;
var standardvklbreite = 260;
var skal = (dokbreite/standardvklbreite);
var vBdsI, vBounds, vBounds_Li, vBounds_Ob, vBounds_Re, vBounds_Un;
if (Sel.length >0 ) {
vBounds = Sel[0].geometricBounds;
vBounds_Li = vBounds[0];
vBounds_Ob = vBounds[1];
vBounds_Re = vBounds[2];
vBounds_Un = vBounds[3];
if (Sel.length >1 ) {
for (i=1; i<Sel.length ; i++) {
vBdsI = Sel[i].geometricBounds;
if( vBounds_Li > vBdsI[0] ) {vBounds_Li = vBdsI[0]};
if( vBounds_Ob < vBdsI[1] ) {vBounds_Ob = vBdsI[1]};
if( vBounds_Re < vBdsI[2] ) {vBounds_Re = vBdsI[2]};
if( vBounds_Un > vBdsI[3] ) {vBounds_Un = vBdsI[3]};
}
}
var breite = Math.round(((vBounds_Re-vBounds_Li)/mm));
var hoehe = Math.round(((vBounds_Ob-vBounds_Un)/mm));
var zhoehe = hoehe;
//origin
var pathSource=app.activeDocument.selection[0];
pathSource.remove();
if (zhoehe<1){
var vmGroup = vmLayer.groupItems.add();
vmGroup.name="Vermaßung Horizontal";
var line = vmGroup.pathItems.add();
line.setEntirePath(Array(Array(((vBounds_Li)),((vBounds_Ob)+0*mm)),Array(((vBounds_Re)),((vBounds_Ob)+0*mm))));
line.strokeColor = regColor;
line.strokeWidth= 0.3 * skal * mm;
line.filled = false;
line.stroked = true;
line.strokeOverprint = true;
var line = vmGroup.pathItems.add();
line.setEntirePath(Array(Array(((vBounds_Li)),((vBounds_Ob)+2.5*skal*mm)),Array(((vBounds_Li)),((vBounds_Ob)-2.5*skal*mm))));
line.strokeColor = regColor;
line.strokeWidth= 0.3 * skal * mm;
line.filled = false;
line.stroked = true;
line.strokeOverprint = true;
var line = vmGroup.pathItems.add();
line.setEntirePath(Array(Array(((vBounds_Re)),((vBounds_Ob)+2.5*skal*mm)),Array(((vBounds_Re)),((vBounds_Ob)+-2.5*skal*mm))));
line.strokeColor = regColor;
line.strokeWidth= 0.3 * skal * mm;
line.filled = false;
line.stroked = true;
line.strokeOverprint = true;
var massBreite = vmGroup.textFrames.add();
massBreite.contents=breite;
massBreite.top = vBounds_Ob+7*mm;
massBreite.left = vBounds_Li+((vBounds_Re-vBounds_Li)/2);
massBreite.textRange.characterAttributes.fillColor= regColor;
massBreite.textRange.characterAttributes.size = 12*skal;
massBreite.textRange.characterAttributes.overprintFill = true;
massBreite.textRange.characterAttributes.stroked = false;
massBreite.textRange.characterAttributes.textFont = app.textFonts.getByName("HelveticaNeueLTStd-BdCn");
massBreite.paragraphs[0].paragraphAttributes.justification = Justification.CENTER;
}
else{
var vm1Group = vmLayer.groupItems.add();
vm1Group.name="Vermaßung Vertikal";
var line = vm1Group.pathItems.add();
line.setEntirePath(Array(Array(((vBounds_Li)-0*mm),((vBounds_Ob))),Array(((vBounds_Li)-0*mm),((vBounds_Un)))));
line.strokeColor = regColor;
line.strokeWidth= 0.3 * skal * mm;
line.filled = false;
line.stroked = true;
line.strokeOverprint = true;
var line = vm1Group.pathItems.add();
line.setEntirePath(Array(Array(((vBounds_Li)-2.5*skal*mm),((vBounds_Ob))),Array(((vBounds_Li)+2.5*skal*mm),((vBounds_Ob)))));
line.strokeColor = regColor;
line.strokeWidth= 0.3 * skal * mm;
line.filled = false;
line.stroked = true;
line.strokeOverprint = true;
var line = vm1Group.pathItems.add();
line.setEntirePath(Array(Array(((vBounds_Li)-2.5*skal*mm),((vBounds_Un))),Array(((vBounds_Li)+2.5*skal*mm),((vBounds_Un)))));
line.strokeColor = regColor;
line.strokeWidth= 0.3 * skal * mm;
line.filled = false;
line.stroked = true;
line.strokeOverprint = true;
var massHoehe = vm1Group.textFrames.add();
massHoehe.contents=hoehe;
massHoehe.textRange.characterAttributes.fillColor= regColor;
massHoehe.textRange.characterAttributes.size = 12*skal;
massHoehe.textRange.characterAttributes.overprintFill = true;
massHoehe.textRange.characterAttributes.stroked = false;
massHoehe.textRange.characterAttributes.textFont = app.textFonts.getByName("HelveticaNeueLTStd-BdCn");
massHoehe.paragraphs[0].paragraphAttributes.justification = Justification.CENTER;
var blupp = (massHoehe.width);
var blapp = (massHoehe.height);
massHoehe.top = vBounds_Ob-((vBounds_Ob-vBounds_Un)/2)+blapp;
massHoehe.left = vBounds_Li-(blupp/2);
massHoehe.rotate (90, true, true, true, true, Transformation.BOTTOM);
}
app.activeDocument.selection = null;
} else {
alert ("Du hast kein Objekt ausgewählt!")
}
app.activeDocument.pageOrigin = StrtPOrigin;
app.activeDocument.rulerOrigin = StrtROrigin;
};
function findOrCreateColor(colorName, C, M, Y, K) {
try { var myColor = app.activeDocument.swatches.getByName(colorName) }
catch (err) {
// Define the new color value
newSpotColor = new CMYKColor();
newSpotColor.cyan = C;
newSpotColor.magenta = M;
newSpotColor.yellow = Y;
newSpotColor.black = K;
// Create the new spot
var newSpot = app.activeDocument.spots.add();
// Define the new SpotColor
newSpot.name = colorName;
newSpot.color = newSpotColor;
newSpot.colorType = ColorModel.SPOT;
}
finally {
return myColor;
}
} ;
function findOrCreateLayer(layerName) {
try { var myLayer = app.activeDocument.layers.getByName(layerName) }
catch (err) {
myLayer = app.activeDocument.layers.add();
myLayer.name = layerName;
}
finally {
return myLayer;
}
} ;
bemassmich();
Copy link to clipboard
Copied
http://forums.adobe.com/thread ah, the good old days...
Copy link to clipboard
Copied
how do we test your script? I selected multiple paths, single paths and not much happened, other than getting a single callout drawn, no errors though.
Copy link to clipboard
Copied
Draw a horizontal or vertical line.
Have the line marked, run the script, get a dimension.
We you the script a lot, to get dimension in our Illustrator-Docs.
It runs correct without any error until somehting (I don't know what) happend, the I get the error I discribed above and the script is not working until I restart Illustrator.
Copy link to clipboard
Copied
Hi, If you have scripting knowledge, use try & catch.
It's helping to you to find the error where is it happening.
Or else find a developer.
Copy link to clipboard
Copied
Haha.
The script mentioned was edited in several ways and no longer has anything to do with my original script.
Here is the original script in the former forums.adobe.com/thread:
How to make a rectangle around activeDocument.selection?
Copy link to clipboard
Copied
Hi pixxelschubser,
as written in the script:
// based on
// Box4selectedPath.jsx
This was the foundation on which I build a lot of scripts. Huge Thanks after alle this years.
Copy link to clipboard
Copied
I just want to bring my topic a little up.
Any ideas?
Copy link to clipboard
Copied
I've been able to avoid a lot of similar issues that i used to have by avoiding try/catch blocks actually.. From my perspective, it seems that things in the try block can mess with the application even if they don't cause a runtime error at that moment.. then some or all of the catch block will execute and then down the line the script will attempt to access some object that was corrupted during the try block. Some data will get dumped or lost resulting in an MRAP error when illustrator tries to read the properties of an object.
So what i've done is written some helper functions to replace the getByName() method which in my humble opinion, is a pile of hot garbage. There's no safeguards built into it at all. normal usage of built in methods should never cause runtime errors. ever. but that's what you get from getByName() if the name doesn't exist. So I take advantage of the fact that when working with illustrator documents, the numbers of layers/swatches/graphic styles or even just pageItems on a given layer are typically small enough that we can trade off some speed/efficiency for reliability and predictability.
So, to avoid using try/catch and getByName() all together, i've replaced getByName with something like this:
function findSpecificGraphicStyle(doc,name)
{
var result;
for(var x=0;x<doc.graphicStyles.length && !result;x++)
{
if(doc.graphicStyles[x].name === name)
{
result = doc.graphicStyles[x]
}
}
return result;
}
This is guaranteed to give me either a graphic style object or undefined. No runtime errors. No headaches. I have different functions for different stuff based on my day to day needs, but basically the formula is this:
function findSomething(parentObject,searchTerm,criteria)
{
var result;
for each item/layer in parentObject while result is undefined
if criteria == "match" && item/layer.name === searchTerm
result = item/layer
else if criteria == "imatch" && item/layer.name.toLowerCase() === searchTerm.toLowerCase()
result = item/layer
else if criteria == "any" && item.layer.name.toLowerCase().indexOf(searchTerm.toLowerCase())
result = item/layer
return result
}
I use something like this for every kind of object i might want to find and i just keep the functions in a centralized utilities container script that gets included with all of my other scripts.
I can't say for certain that this is in any way related to the MRAP errors you're getting, but i can say that when i stopped using try/catch to identify layers/objects/swatches... a lot of my issues went away. That certainly didn't happen in a vacuum and there's no way to control for all variables, but i think it's worth thinking about anyway.