Skip to main content
Miyano_
Inspiring
July 3, 2018
Answered

Select objects inside many artboards

  • July 3, 2018
  • 3 replies
  • 2008 views

Hi everybody !

After having searched on ALL topics existing in the world for days, I could not find an answer to my question. That is why, I need your help

I want to export specifics artboards ( not all ) in the same DXF file . In order to do that, it's necessary to select layers, pageItems and sublayers which are on each artboard that I want export. I know and already tried the function " selectObjectsOnActiveArtboard() ", it's perfect if you want to export one artboard but does no work for multiple artboards . I would like to know if there is anything that would work for multiple artboards.

Thank you very much for your answer and help !

Have a nice day,

Miyano

This topic has been closed for replies.
Correct answer Miyano_

Hi William !

After having researched the entire Internet for an other solution, I just found a solution to the problem I encountered. I am getting arround the problem but I get the result I wanted.

I am making a loop that let visible every layer one by one. I then select the artboards that I want to export with docRef.selectObjectsOnActiveArtboard(); and place my selection with .move into a new layer. Finally, I just have to export the new created layers that contain everything I wanted.

Thanks a lot for your helpful comments !

Have a nice day !!!

Miyano

3 replies

Miyano_
Miyano_AuthorCorrect answer
Inspiring
July 12, 2018

Hi William !

After having researched the entire Internet for an other solution, I just found a solution to the problem I encountered. I am getting arround the problem but I get the result I wanted.

I am making a loop that let visible every layer one by one. I then select the artboards that I want to export with docRef.selectObjectsOnActiveArtboard(); and place my selection with .move into a new layer. Finally, I just have to export the new created layers that contain everything I wanted.

Thanks a lot for your helpful comments !

Have a nice day !!!

Miyano

Miyano_
Miyano_Author
Inspiring
July 4, 2018

Hi Carlos, William,

Thank you very much for your answer !

My first function makes invisible all layers :

function invisible()

{

        for(m=0;m<layers.length;m++){         

                layers.visible = false; // CALQUE LVL0

    }

}

My second function selects the layers that I want:

(sorry if my program is messy, Im new to Javascript and I tried with the little knowledge I have)

function selectlayer(layername)

{

i=layername;

              

layers.visible = true; // CALQUE LVL0

layers.locked = false; // CALQUE LVL0

             

              

        for(a=0;a<layers.pageItems.length;a++){

        layers.pageItems.locked = false; // ITEM LVL1

        layers.pageItems.hidden = false; // ITEM LVL1

       //layers.pageItems.selected = true; // ITEM LVL1

         }

                var subLayers=layers.layers;

                 for(j=0;j<subLayers.length;j++){

                 subLayers.locked = false; // CALQUE LVL1

                 subLayers.visible = true; // CALQUE LVL1

                                                          

                                                            

                               for(b=0;b<subLayers.pageItems.length;b++){ //here we are looping through each pageItem of myLayer. 

                                                                          

                                subLayers.pageItems.locked = false; // ITEM LVL2

                                subLayers.pageItems.hidden = false; // ITEM LVL2

                                //subLayers.pageItems.selected = true; // ITEM LVL2

                                 }

                                           var subSubLayers=subLayers.layers;

 

                                           for(k=0;k<subSubLayers.length;k++){

                                           subSubLayers.locked = false; // CALQUE LVL 2

                                           subSubLayers.visible = true; // CALQUE LVL 2

                                                            for(c=0;c< subSubLayers.pageItems.length;c++){ //here we are looping through each pageItem of myLayer. 

                                                                          

                                                            subSubLayers.pageItems.locked = false; // ITEM LVL 3

                                                            subSubLayers.pageItems.hidden = false; // ITEM LVL 3

                                                            //subSubLayers.pageItems.selected = true; // ITEM LVL 3

                                                             }

                                                                   

                                                                         var subSubSubLayers=subSubLayers.layers;

 

                                                                         for(f=0;f<subSubSubLayers.length;f++){

                                                                         subSubSubLayers.locked = false; // CALQUE LVL 3

                                                                         subSubSubLayers.visible = true; // CALQUE LVL 3

                                                                                   for(d=0;d< subSubSubLayers.pageItems.length;d++){ //here we are looping through each pageItem of myLayer.                                                                                                                                                                                                                                                     subSubSubLayers.pageItems.locked = false; // ITEM LVL 4                                                                                                                     subSubSubLayers.pageItems.hidden = false; // ITEM LVL 4                                                                                                                     //subSubSubLayers.pageItems.selected = true; // ITEM LVL 4

                                                                                                                                                                              

}

}

}

}

At this step, I have the layers I want visible BUT the problem is that I also have unwanted objects which are in visible layers from undesired artboards.

Thats why this program selects the artboards that I want:

// Obtain title of the artboards

var artboardtitle = [];

for(i = 0; i < docRef.artboards.length; i++) {

artboardtitle = docRef.artboards.name;

}

// Collect artboards with PNO in the name

var PNOsearch = [];

for(j=0; j<artboardtitle.length; j++){

if(artboardtitle.indexOf('PNO') > -1) {

PNOsearch.push(artboardtitle);

    }

  }

//Select artboard PNO

function setActiveArtboardBy(name) {

    var artboard = docRef.artboards.getByName(name);

    for (i = 0; i < docRef.artboards.length; i++) {

        if (docRef.artboards == artboard) {

            docRef.artboards.setActiveArtboardIndex(i);

            break;

        }

    }

}

But after that Im blocked. I thought about two solutions:

The first one is to select objects inside different artboards and export them in DXF. The second one is to select one by one artboards that I dont want and hide the object of this artboard.

The downside is that I do not know how to set up these solutions  

Thanks and Have a nice day !!!

Miyano

Disposition_Dev
Legend
July 5, 2018

There is no logic anywhere in your code that exports or saves the file, so I can only guess as to your desired settings. but thats ok, we can fix those up after the fact.

The moral of the story is, if you have the correct artwork visible on one artboard, it doesn't matter what is visible on any other artboards because you can specify which artboard you want to export.

Please see this example converted from the javascript scripting reference:

function saveFileToPDF(destFileName,myRange)

{

    var doc = app.activeDocument;

    var dest = "~/Desktop/" + destFileName;

    var saveName = new File(dest);

    var saveOpts = new PDFSaveOptions();

   

    //this property accepts a string representing the number of the artboard you want to export

    //this number is not zero based like other collections in javascript

    //for the first artboard in the document, you'll use "1".

    saveOpts.artboardRange = myRange;

    saveOpts.preserveEditability = true;

    doc.saveAs(saveName, saveOpts);

}

Miyano_
Miyano_Author
Inspiring
July 5, 2018

Hi William,

Sorry, I didnt share the part of export file because I thought that the problem come from of the selection.

Ok thanks, I am relieved if the problem comes from the export. That means I already have the layers that I want visible.

I didnt encounter difficulties to export artboards that I want with layers that I want in PDF using saveFileToPDF from the manual.

My problem is to do the same thing in DXF. If I am not wrong, to export in DXF format I may use the exportFile function. I have been looking the features of that function and I didnt find any means to export content related to artboards.

[I think there are all the options in this website : http://jongware.mit.edu/iljscs6html/iljscs6/pc_ExportOptionsAutoCAD.html]

I feel like to export in DXF, its only depends on the selection. Is that correct ?   

Here is my current export to DXF program :

function getOptions() { 

  var exportOptions = new ExportOptionsAutoCAD(); 

      exportOptions.exportFileFormat = AutoCADExportFileFormat.DXF;//DWG  DXF 

      exportOptions.exportOption = AutoCADExportOption.PreserveAppearance; 

      exportOptions.version = AutoCADCompatibility.AutoCADRelease14; 

      exportOptions.exportSelectedArtOnly = true; //export selected objects true 

      exportOptions.convertTextToOutlines = false; 

      exportOptions.generateThumbnails = true; 

      exportOptions.unit = AutoCADUnit.Millimeters; 

return exportOptions; 

function exportFileToDXF() {

    var filename = "Test2"

    var destFolder = Folder.selectDialog( 'Select folder for DXF files.', '~' ); 

    var options = getOptions();

    var type = ExportType.AUTOCAD;

    var saveName = new File(destFolder + "/" + filename+".dxf");

   

    docRef.exportFile(saveName, type, options);

}

I am totally lost, the more I am looking for it, the more I am feeling that it is impossible

Thank you very much for your answer,

Miyano

CarlosCanto
Community Expert
Community Expert
July 3, 2018

Hi Miyano, there may not be a single command to do what you need but it's likely there are workarounds. Please provide more details preferably with screen shots or better yet a sample file.

Miyano_
Miyano_Author
Inspiring
July 3, 2018

Hi Carlos !

In this example, I want to export artboard 1 and artboard 2 into a DXF file. But I only want the objects in the layers 2 and 6 (not the objects of layer 1).

I have made a program that makes all layers invisible and after that makes wanted layers visible. I also made a program that pinpoints the artboards that I would like to export in the area thanks to their names.

[ I can share the program I made if you want but it is long and tedious   ]

The problem is that I am unable to combine both programs thus I am unable to select specific objects (that are on specific layers) of wanted artboards

Dont hesitate to tell me if you do not understand,

Thank you very much for your answer!!!

Miyano

Miyano_
Miyano_Author
Inspiring
July 3, 2018