Copy link to clipboard
Copied
Can this be done in illustrator scripting??
http://coreldraw.com/forums/t/35280.aspx
creating a rectangle around selected object or objects and set margins...
Regards
Martin
Hallo martin_Cahill,
My English is not the best, because of that in German.
Grundsätzlich sind sich VBA und Javascript sehr ähnlich. Versuche die folgende Funktion mit den VBA-Äquivalenten zu vergleichen. Learning by doing
...function makeRect() {
if (selection.length == 0) {
alert("Kein Objekt …");
return;
}else{
if (selection.length > 1) {
alert("Zu viele Objekte …");
return;
}else{
var myDoc = app.activeDocument;
var Sel = myDoc.selection
var SelVB = Se
Copy link to clipboard
Copied
yes, it can be done
Copy link to clipboard
Copied
Great news.
I have this script that does what I want, it draws the rectangle around the obect with a distance margin of 0.05cm then groups the objects togeather.
can you help me to convert this script to work in illustrator?
this works in coral draw its VBA
Sub makeRect()
Dim s As Shape, sRect As Shape
Dim x As Double, y#, h#, w#
Dim dMarg#
Dim sr As New ShapeRange
dMarg = 0.05
ActiveDocument.Unit = cdrCentimeter
Set s = ActiveShape
If s Is Nothing Then Exit Sub
s.GetBoundingBox x, y, w, h
Set sRect = ActiveLayer.CreateRectangle2(x - dMarg, y - dMarg, w + (dMarg * 2), h + (dMarg * 2))
sRect.Outline.Width = 0.001
sRect.CreateSelection
sr.Add sRect
sr.Add s
sr.Group
End Sub
Copy link to clipboard
Copied
Hallo martin_Cahill,
My English is not the best, because of that in German.
Grundsätzlich sind sich VBA und Javascript sehr ähnlich. Versuche die folgende Funktion mit den VBA-Äquivalenten zu vergleichen. Learning by doing
function makeRect() {
if (selection.length == 0) {
alert("Kein Objekt …");
return;
}else{
if (selection.length > 1) {
alert("Zu viele Objekte …");
return;
}else{
var myDoc = app.activeDocument;
var Sel = myDoc.selection
var SelVB = Sel[0].visibleBounds;
var dMarg = 28.3464567;
var Links = SelVB[0];
var Oben = SelVB[1];
var SelBreite = (SelVB[2] - SelVB[0]);
var SelHoehe = (SelVB[1] - SelVB[3]);
var newCMYK = new CMYKColor();
newCMYK.cyan = 100;
newCMYK.magenta = 0;
newCMYK.yellow = 0;
newCMYK.black = 0;
var myGroup =myDoc.groupItems.add();
Sel[0].move(myGroup, ElementPlacement.PLACEATBEGINNING);
var MargBox = myDoc.pathItems.rectangle(Oben+dMarg, Links-dMarg, SelBreite+2*dMarg, SelHoehe+2*dMarg);
MargBox.stroked = true;
MargBox.strokeWidth = 10;
//MargBox.filled = false;
MargBox.fillColor = newCMYK;
MargBox.move(myGroup, ElementPlacement.PLACEATEND);
}
}
}
Hilft dir das weiter?
Viel Spass noch.
Copy link to clipboard
Copied
Hallo Vielen Dank für die Hilfe
I have copied the code into a text file and saved it as .jsx in the preset folder of illustrator
I run the script no errors but nothing happens??
Martin
Copy link to clipboard
Copied
Add this at as the very first line:
makeRect() ;
-- schubser defined a new function but forgot to call it
Copy link to clipboard
Copied
yes it works!
Only thing last thin I would like no fill colour atall?
I have comented MargBox.fillColor = newCMYK; but didnt work
Regards
Martin
Copy link to clipboard
Copied
Ive fixed it now!
Thanks everyone for the help great forum!
thanks pixxxel schubser great job!!
Martin
Copy link to clipboard
Copied
please get into the habit of marking your posts as "Answered" if you get satisfactory answers.
thanks
Copy link to clipboard
Copied
Hey Martin, I had the same requirement as you.
can you post that finalised scrip here for us then?
Thank you, in advance,
Fred
Copy link to clipboard
Copied
function makeRect() {
if (selection.length == 0) {
alert("Kein Objekt …");
return;
}else{
if (selection.length > 1) {
alert("Zu viele Objekte …");
return;
}else{
var myDoc = app.activeDocument;
var Sel = myDoc.selection
var SelVB = Sel[0].visibleBounds;
var dMarg = 28.3464567;
var Links = SelVB[0];
var Oben = SelVB[1];
var SelBreite = (SelVB[2] - SelVB[0]);
var SelHoehe = (SelVB[1] - SelVB[3]);
var newCMYK = new CMYKColor();
newCMYK.cyan = 100;
newCMYK.magenta = 0;
newCMYK.yellow = 0;
newCMYK.black = 0;
var myGroup =myDoc.groupItems.add();
Sel[0].move(myGroup, ElementPlacement.PLACEATBEGINNING);
var MargBox = myDoc.pathItems.rectangle(Oben+dMarg, Links-dMarg, SelBreite+2*dMarg, SelHoehe+2*dMarg);
MargBox.stroked = true;
MargBox.strokeWidth = 10;
//MargBox.filled = false;
MargBox.fillColor = newCMYK;
MargBox.move(myGroup, ElementPlacement.PLACEATEND);
}
}
}
makeRect();
Copy link to clipboard
Copied
Thank you for that almost instant reply!
Best,
Fred
Copy link to clipboard
Copied
Sorry to repost, but I wanted to make this with no fill and margin of 0.375 inches all around (so +0.75 inches top/bottom and +0.75 inches left/right). I tried to change the dMarg variable but I don't quite get the ratio. New to scripting. Any help will be appreciated.
Copy link to clipboard
Copied
I wanted to make this with no fill
Change these two lines
//MargBox.filled = false;
MargBox.fillColor = newCMYK;
to
MargBox.filled = false;
// MargBox.fillColor = newCMYK;
... and margin of 0.375 inches all around ...
Units are in points. So change dMarg to
var dMarg = 0.375 * 72;
Copy link to clipboard
Copied
it got me closer, but for some reason it's still off... it's adding 0.7917 instead of 0.75.
I looked up the unit conversion and the 0.375*72 part should be correct... but I don't know where the extra area is coming from... My attached photo is a 1 inch x 1 inch square.
Copy link to clipboard
Copied
nevermind... I figured it out... the initially selected object path can't have a stroke. Thank You!
Copy link to clipboard
Copied
Avec un contour, utilisez
var SelVB = Sel[0].geometricBounds;
var dMarg = 0.375 * 72;
Copy link to clipboard
Copied
Hi, this is a very useful script! Could I ask if it's possible to make the stroke colour a named spot colour instead?
This is what I have -
Copy link to clipboard
Copied
Hi!
MargBox.strokeColor = activeDocument.spots["toto"].color;
Copy link to clipboard
Copied
Excellent thanks for your help!
Copy link to clipboard
Copied
Sorry I thought it had worked. It seems to be just adding the colour as a normal colour and not a spot. Any ideas?
This is the code -
function makeRect() {
if (selection.length == 0) {
alert("Kein Objekt …");
return;
}else{
if (selection.length > 1) {
alert("Zu viele Objekte …");
return;
}else{
var myDoc = app.activeDocument;
var Sel = myDoc.selection
var SelVB = Sel[0].visibleBounds;
var dMarg = 5.5;
var Links = SelVB[0];
var Oben = SelVB[1];
var SelBreite = (SelVB[2] - SelVB[0]);
var SelHoehe = (SelVB[1] - SelVB[3]);
var newCMYK = new CMYKColor();
newCMYK.cyan = 0;
newCMYK.magenta = 0;
newCMYK.yellow = 0;
newCMYK.black = 69;
var myGroup =myDoc.groupItems.add();
Sel[0].move(myGroup, ElementPlacement.PLACEATBEGINNING);
var MargBox = myDoc.pathItems.rectangle(Oben+dMarg, Links-dMarg, SelBreite+2*dMarg, SelHoehe+2*dMarg);
MargBox.stroked = true;
MargBox.strokeWidth = 0.25;
MargBox.strokeColor = activeDocument.spots["PerfCutContour"].color;
MargBox.filled = false;
// MargBox.fillColor = newCMYK;
MargBox.move(myGroup, ElementPlacement.PLACEATEND);
}
}
}
makeRect();
Copy link to clipboard
Copied
Pour moi j'ai compris celà ?
Copy link to clipboard
Copied
Unfortunetely I'm not getting that. It's applying the correct spot colour but it's not a spot colour with a name. Without the name my plotter wont read the strokes as cut lines.
Thanks for helping.
Copy link to clipboard
Copied
Hi robbo78!
Pouvez vous en dire plus sur le fonctionnement de votre traceur?
Si le tracé doit porter ce nom, alors ajoutez,
MargBox.name = "PerfCutContour";
elleere
Copy link to clipboard
Copied
Hi, could I ask what you mean by "tracker"? Sorry I'm a bit of a newbie to scripting.
I will try adding that and see how it goes 🙂