4 Replies Latest reply on Oct 8, 2016 5:09 AM by Loic.Aigon

    Import .DXF Change Stroke and Save as .ai


      Hello everyone. I'll start by saying that I'm new to Illustrator. I am using Illustrator CS6.


      I've been having to repeat this process daily so I'm looking to automate the process.


      Import .DXF

      Group Items

      Change stroke color to 255,0,0

      Change stroke weight to .001 pt

      Save As .ai


      If possible, it would be nice to set default layout size and printer settings but if not I can set that up as a preset elsewhere.


      So far I've only been able to get this group and copy script to work:

      var doc = app.activeDocument; 
      // Duplicates and groups all items in the current selection,
      if ( app.documents.length > 0 )
        docSelection = app.activeDocument.selection;
        if ( docSelection.length > 0 )
        newGroup = app.activeDocument.groupItems.add();
        for ( i = 0; i < docSelection.length; i++ )
        newItem = docSelection[i].duplicate();
        newItem.moveToBeginning( newGroup );
        //apply stroke color and width here?


      As well as this stroke changing script:

      //here you can change the stroke percentual
      var myA = prompt("Choose your %","80","Change width stroke");
      var myPercentile = myA/100;
          // choose all page elements
          for (var i=0;i<app.activeDocument.pageItems.length;i++){
              var myLayer = app.activeDocument.pageItems[i];
              //if element is compound make a new loop for pathItems
                  for(var u=0;u<myLayer.pathItems.length;u++){
                      //take actual stroke size
                      var myPath = myLayer.pathItems[u];
                      var myMeasure = myPath.strokeWidth;
                      //transform the stroke width into % choose at start
                      myPath.strokeWidth = myMeasure*myPercentile;
                      var myMeasure = myLayer.strokeWidth;
                      myLayer.strokeWidth = myMeasure*myPercentile;


      I looked though this reference but cannot find how to change the stroke weight:

      http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/pdf/illustrator/scripting/cs6/Illus trator-Scripting-Reference-Jav…


      If anyone could point me in the correct direction, I'd really appreciate it.

        • 1. Re: Import .DXF Change Stroke and Save as .ai
          Loic.Aigon Adobe Community Professional
          var main = function () {
            //use filter so users can only pick dxf files
            var macFilter = function ( f ) { return /\.dxf/i.test ( f.name ); },
            winFilter = "DFX Files:*.dxf;";
            var filter = $.os[0]=="W"? winFiltre : macFilter,
            //Get DXF files
            var DXFFiles = File.openDialog("Please select DXF File(s)…", filter, true), aDXFFile;
            if ( !DXFFiles) return;
            //Get percentage
            var p = prompt ( "How many reduction should we apply ?", "100" );
            if (!p ) return;
            //Control percentage value
            if ( isNaN( p ) || Number (p)==0  || Number (p)> 100 ) {
            alert("That's not a valid number !!!");
            //Choose output folder
            var fo = DXFFiles[0].parent.selectDlg("Choose OUTPUT folder");
            if ( !fo ) return;
            p = Number(p);
            var uip = app.userInteractionLevel;
            app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
            //Loop through dxf files
            var n = DXFFiles.length, group, artboard;
            try {
            while ( n-- ) {
            //Open file
            aDXFFile = DXFFiles[n];
            doc = app.open ( aDXFFile );
            //group items and resize
            group = groupAllItems ( doc );
            group.resize ( p, p);
            //fit artboard to group
            artboard = doc.artboards [ doc.artboards.getActiveArtboardIndex() ];
            artboard.artboardRect = group.geometricBounds;
            //Save document
            doc.saveAs ( File ( fo+"/"+doc.name.replace (".dxf", ".ai" ) ) );
            catch(err) {
            app.userInteractionLevel = uip;
          var groupAllItems = function ( doc )  {
            var pathItems = doc.pathItems, n = pathItems.length;
            var newGroup = doc.groupItems.add();
            var newRGBColor = new RGBColor();
            newRGBColor.red = 255;
            newRGBColor.green = 0;
            newRGBColor.blue = 0;
            var pathItem;
            while ( n-- ) {
            pathItem =pathItems[n];
            pathItem.strokeColor = newRGBColor;
            pathItem.strokeWidth = .001;
            pathItems[n].move ( newGroup, ElementPlacement.PLACEATEND );
            return newGroup;







          1 person found this helpful
          • 2. Re: Import .DXF Change Stroke and Save as .ai
            w47327872 Level 1

            Wow, thank you Logic.


            I ran the script and it successfully opens a DXF and resaves the file as .ai, although once I open the new .ai file- the lines are not grouped and the stroke color did not change. I think you put enough info in here for me to play around with it and get it to work though. Thank you so much!

            • 3. Re: Import .DXF Change Stroke and Save as .ai
              w47327872 Level 1



              I've played around with this a bit more but still couldn't figure out what the issue is. I can never get all items to group. About half of the items group and the stroke weight and color successfully change, but never all of them. I suspect the issue is with:

              group = groupAllItems(doc);

              more specifically:

              var pathItems = doc.pathItems,
                      n = pathItems.length;


              Is there a reason why pathItems is not successfully selecting all items?

              • 4. Re: Import .DXF Change Stroke and Save as .ai
                Loic.Aigon Adobe Community Professional


                the script "fails" because it's predicate is to look Orly after pathItems class instances. So any other object live preexisting groupItems, textframes and so on won't ne collected. So the script needs to extend the type of Target objects. Notting hard here but won't have Time to deal with until next weekend.

                and it's loic not logic