1

In previous CorelDraw user life, I had part of a 'workflow' where I needed to gather information on the height, width, and position of objects from a scaled diagram (think e.g., a technical drawing or log).

I used to do this in CorelDraw by simply exporting as a SVG, setting the units to millimetres and precision as 1:1: enter image description here

Fig 1: Example screenshot from CorelDraw export for SVG from a while ago...

Then I could take the XML of the SVG, chuck it through a python script to sort out all the other guff in there and up with a nice list of item/shape name, x, y, width, height relative the position that 0,0 mm is set on the document ruler.

As of yet, I can't find a way to replicate this in Illustrator. The SVG export remains always as px and so runs into problems between the DPI scaling (and more etc)

Am I missing somethignin Illustrator to be able to do this? A very simplified example below of example input, and desired ultimate output (doesnt matter if there's a messy output in between, just needs to be tangible/real world dimension numbers!). Of course scaling by DPI value is possible, but is going to change from user to user as far as I understand, and is an extra step and oppurtunity for error.

e.g., some shapes, with names

Fig 2: E.g., some shapes with name

Example ultimate output in DOCUMENT UNITS (millimetres):

Name X Y Height Width

A1 23 00 15 4

S02 23 15 5 4

... etc etc

Also see this post...

3
  • No such option in illustrator. The DPI value is fixed 72 pixels per inch, always no exceptions no user editable field for this (there is no way to set dpi in illustrator, because dpi of a vector document makes no sense. But then pixel as a unit makes no sense either)
    – joojaa
    Jul 16 at 15:39
  • As I feared! Seems like something that really should be a possibility as this information must exist to be able to display co-ordinates as info etc within Illustrator.
    – WestXylo
    Jul 16 at 15:48
  • It does its just that SVG consortium did explicitly a thing Adobe said they will not implement and hasnt implemented anything since then. So the exporter is what it is. Just wirte a jsx script and extract the info form within illustrator directly. But again the DPI of a illustrator svg is always 72 dpi its not something anybody can change.
    – joojaa
    Jul 16 at 17:32

1 Answer 1

0

There is no solution to this question as posed no real solution for SVG export. Adobe uses a internal unit of postscript points and that's what it dumps into the SVG file as pixels. This isn't wrong as far as the SVG standard was concerned at the time the exporter was made.

Your options are:

  1. Translate the pixels to other units in your script. The conversion factor is always fixed at 72 pixels = 1 inch

    (note that many applications can have other values and SVG consortium defines it as 96 But adobe always thinks its 72 no matter what)

  2. Run the script in illustrator, you still need to convert though as all units are same *

  3. Write your own exporter, here is an example of me doing one

  4. Export to PDF and parse the info from there. (no this isnt terribly hard), this is generally superior for fabrication as there can not be a conversion error in the format itself.

    Maybe a better format would be STEP.

  5. Don't use illustrator.

PS: Not having this kind of fixed frame would essentially break all existing Illustrator files on every hard drive in the world, every piece of plugin code, every piece of internal code and every script ever made. It is very unlikely that adobe will ever change this very suddenly. Though the move out of JSX might be a point where they could realistically do it.

* Here is a script that will put the coordinates on selected points in the document selectec units this should be sufficient for you to get the thing you want done done. Theres no reason why i couldn't do directly what you ask, but im not a a script on demand service (I just happened to have this script). You can rip the unit conversion from this script and use the script here for file dumping:

// jooPutCoordsAtPoint.jsx
//
// 

#target illustrator

var unit = app.activeDocument.rulerUnits

// get all selected points in document, filter out duplicates
var filteredPts = mergePoints( getSelectedPoints (activeDocument.selection),0.1);

addTextAtPoints(filteredPts, unit);

function addTextAtPoints(pts, unit){
    for(var i = 0; i < pts.length; i++){
        var x = pts[i][0];
        var y = pts[i][1];
        var textF = app.activeDocument.textFrames.add();
        textF.left = x;
        textF.top = y + textF.height;
        textF.contents =  "["+ Math.round(toUnit(x, unit)*10)/10 +" ,  " + Math.round(toUnit(y, unit)*-10)/10  +"]";
    }
}

function getSelectedPoints(sel){
    var points=[]
    for(var i = 0; i < sel.length; i++){
        var pp = sel[i].pathPoints;
        for(var j = 0; j < pp.length; j++){
            var p = pp[j];
            if ( p.selected == PathPointSelection.ANCHORPOINT  ){
                points.push(p.anchor);
            }                          
        }
    }
    return points;
}

function mergePoints(pts, eps){
    pts.sort();
    var ret=[];
    while(pts.length){
        var pt = pts[0];
        ret.push(pt);
        pts.splice(0, 1);
        var i=0;
        while(pts.length>i && Math.abs(pt[0]-pts[i][0])<eps){
            if(Math.abs(pt[1]-pts[i][1])<eps){
                pts.splice(0, 1);
            } else {
            i++;
            }
        
        }
    }
    return ret;
}

function toUnit(point, unit){
    switch (unit) {
    case RulerUnits.Pixels:
        return round(point);

    case RulerUnits.Points:
        return point;

    case RulerUnits.Picas:
        return point * 0,08334;

    case RulerUnits.Millimeters:
        return point *  0.352806;

    case RulerUnits.Centimeters:
        return point * 0.0352806;

    case RulerUnits.Meters:
        return point * 0.000352806;
    
    case RulerUnits.Inches:
        return point * 0.01389;
    
    case RulerUnits.Feet:
        return point * 0.0011575;
    
    case RulerUnits.Yards:
        return point * 0.0003858333333; 
    
    }

}
1
  • Hi Joojaa, Thanks for your very detailed and updated response and for going the extra mile in providing plenty of examples and some code to try out. I certainley appreciate you're not a code on demand service (...which is why I didn't ask for that ;-) ) so honestly, thanks very much for putting the time and effort into this. Get in touch - I owe you a beer/coffee! Time to learn some javascript...
    – WestXylo
    Jul 17 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.