Exporting code/copying code/ code management

I like to use multiple tabs to organise my code in processing, and was wandering if there was a simple way to grab all the code and paste it anywhere else, without having to check through all the tabs.

Also is there a feature which I can enable which would enable me to close/open large brackets of code, most software allows this but processing ide does not seem to;

Thanks guys

The easiest way to bring all the code from the different tabs together (if they are pure Processing code) is to export your sketch. Then you can visit the exported folder, search for the .java file generated. Keep in mind that Processing can also handle .java files in its tab system. These Java files are not merged in the exporting process as they are considered top classes.

For folding text in the editor, I don’t think it is possible at the moment. It is a nice feature request.

I would like to add that there is a tab manager tool, in case this could be of any use for your current work flow.

Kf

3 Likes

Yes these features would be greatly appreciated…

but the
/ File / Save As / [ctrl][shift][s]
is exactly doing that?


a nice lite editor is GEANY
Marking code parts ,

i use in Raspberry Pi for python ( and processing )
also for windows 7 ( about 100MB )

1 Like

I shall check out geany thanks, however the ctrl shift s, only save a copy of the project to a target location, it separates all tabs into there own entities.

2 Likes

well, they ARE, did you want to concat all .PDE and .JAVA files into one file?
i see no use of that unless for the purpose

  • to post it here at the forum as one CODE?
  • backup more easy? ( Processing / Tools / Archive Sketch works well )

but with smarter editor ( color marking, folding …)
no need to use multiple TAB / .PDE files.
but with one file you might loose the modular structure / re-usability
( of your classes and functions )
but as long you think in / use the project structure ( directory / pde files… )
both ways should be ok.

hit the nail on the head with the first bullet point

Exporting was mentioned already…

There are occasions where my Processing application crashes and I did not do a recent save.

I look into the %temp% folder and can find the last *.java file that Processing generated which is the same as an export (for working code). If I had a lot of tabs it is “a chore to restore”. :slight_smile:

These *.java and other files are also generated for every sketch and in the %temp% folder.

For example:

import processing.core.*; 
import processing.data.*; 
import processing.event.*; 
import processing.opengl.*; 

import java.util.HashMap; 
import java.util.ArrayList; 
import java.io.File; 
import java.io.BufferedReader; 
import java.io.PrintWriter; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.io.IOException; 

public class XY_Perlin_00 extends PApplet {

//Perlin noise used to generate a line
//Gives a nice "warbling" effect

float xoff1, xoff2, xoff3;

public void setup()
  {
  
  }

public void draw()
  {
  background(220);
  stroke(102, 0, 230);  
  strokeWeight(10);
  
  translate(-40, 0);
  rotate(-TAU/128);
  scale(.8f, 1);
  float p = .019f;

// I see patterns here and could replace with a for loop:
  circle(300, height - 300 +20, .019f);
  circle(500, height - 500 +20, .020f);
  circle(700, height - 700 +20, .021f); 

  lineX(100, 100, 800);
  lineY(100, 100, 800);  
  lineXY(100, 100, 800); 
  }

public void circle(int x, int y, float rand)
  {
  for (float th = -TAU/20 +TAU/2; th < 3*TAU/2 + TAU/20; th += TAU/500)
    {
    xoff1 = xoff1 + rand;
    random(10);
    float r = 40 + 10*noise(xoff1);
//    println(noise(xoff1));
    point( r*cos(th)+x, r*sin(th)+y);
    }
  }  
  
// These could be consolidated into one method and called from draw();  

public void lineX(int x1, int y1, int l)
  {
  for (float i = 0; i<l; i+=1)
    {
    xoff2 = xoff2 + .02f;
    point(i + x1, height - y1 + 10*noise(xoff2));
    }
  }  

public void lineY(int x1, int y1, int l)
  {
  for (float i = 0; i<l; i+=1)
    {
    xoff2 = xoff2 + .02f;
    point(x1 + 10*noise(xoff2), i + y1 + 10*noise(xoff2));
    }
  } 

public void lineXY(int x1, int y1, int l)
  {
  for (float i = 0; i<l; i+=1)
    {
    xoff3 = xoff3 + .02f;
    point(i + x1 + 10*noise(xoff3), height -i - y1 + 10*noise(xoff3));
    }
} 
  
  public void settings() {  size(800, 1000, P2D); }
  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "XY_Perlin_00" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}

If comment the “extras” that were added it will run as Processing sketch:

//import processing.core.*; 
//import processing.data.*; 
//import processing.event.*; 
//import processing.opengl.*; 

//import java.util.HashMap; 
//import java.util.ArrayList; 
//import java.io.File; 
//import java.io.BufferedReader; 
//import java.io.PrintWriter; 
//import java.io.InputStream; 
//import java.io.OutputStream; 
//import java.io.IOException; 

//public class XY_Perlin_00 extends PApplet {

//Perlin noise used to generate a line
//Gives a nice "warbling" effect

float xoff1, xoff2, xoff3;

public void setup()
  {
  
  }

public void draw()
  {
  background(220);
  stroke(102, 0, 230);  
  strokeWeight(10);
  
  translate(-40, 0);
  rotate(-TAU/128);
  scale(.8f, 1);
  float p = .019f;

// I see patterns here and could replace with a for loop:
  circle(300, height - 300 +20, .019f);
  circle(500, height - 500 +20, .020f);
  circle(700, height - 700 +20, .021f); 

  lineX(100, 100, 800);
  lineY(100, 100, 800);  
  lineXY(100, 100, 800); 
  }

public void circle(int x, int y, float rand)
  {
  for (float th = -TAU/20 +TAU/2; th < 3*TAU/2 + TAU/20; th += TAU/500)
    {
    xoff1 = xoff1 + rand;
    random(10);
    float r = 40 + 10*noise(xoff1);
//    println(noise(xoff1));
    point( r*cos(th)+x, r*sin(th)+y);
    }
  }  
  
// These could be consolidated into one method and called from draw();  

public void lineX(int x1, int y1, int l)
  {
  for (float i = 0; i<l; i+=1)
    {
    xoff2 = xoff2 + .02f;
    point(i + x1, height - y1 + 10*noise(xoff2));
    }
  }  

public void lineY(int x1, int y1, int l)
  {
  for (float i = 0; i<l; i+=1)
    {
    xoff2 = xoff2 + .02f;
    point(x1 + 10*noise(xoff2), i + y1 + 10*noise(xoff2));
    }
  } 

public void lineXY(int x1, int y1, int l)
  {
  for (float i = 0; i<l; i+=1)
    {
    xoff3 = xoff3 + .02f;
    point(i + x1 + 10*noise(xoff3), height -i - y1 + 10*noise(xoff3));
    }
} 
  
  public void settings() {  size(800, 1000, P2D); }
//  static public void main(String[] passedArgs) {
//    String[] appletArgs = new String[] { "XY_Perlin_00" };
//    if (passedArgs != null) {
//      PApplet.main(concat(appletArgs, passedArgs));
//    } else {
//      PApplet.main(appletArgs);
//    }
//  }
//}

If you intention is to post all your code (which distributed in different tabs) here in the forum, my recommendation is not to do that. You will lose structure and it will make the code hard to read, hence less appealing for anyone o help. I can see two purpose for you to post all your code here: you are looking for help or you are sharing your work. For the former, you should provide a MCVE instead of providing all the code.

In any case, a better alternative for your case would be to post your code in an online repo like github. Anybody will be able to check your code directly in github and then could clone it into their local machine to run it. This is the best option as this would keep the integrity of your code structure and this will guarantee to run in any PDE.

Kf

1 Like

Just mentioning that has been requested for over a decade, and is almost certainly not happening.

Concating your sketch files seems like a reasonable thing to want sometimes. It could be a simple script / droplet. What OS are you on?

Strange that a basic feature in almost all text-editors has been left out by choice, it however impedes code organisation, as it means I have to look elsewhere if my code is going to be lengthy . Geany seems to be the answer here though that does not resolve concatenation. I am currently using windows 10.

Thanks for all your replies, Geany appears to do everything I want a and try and make a script for concatenation there also appears to be a atom.io alternative, which is perfect as its currently my go to editor. Also there appears to be possibilities using visual studio.


visual studio

https://marketplace.visualstudio.com/items?itemName=Tobiah.language-pde

Seems there are plenty of alternatives.

2 Likes

here is a sketch that joins pde files and saves as txt file

// JOIN all pde in a folder

// user selects folder

//**************************************************************
// alter these values:
boolean CHECK_ONLY_FILES_CONTAINING = true; // we can search for a certain file type only e.g. ".pde"
String ALLOWED_ENDING    = ".pde";   // e.g. ".pde" when CHECK_ONLY_FILES_CONTAINING = true 
//**************************************************************

//
//states 
final int stateWaitForFolder = 0;  // consts  
final int stateDone          = 1;
final int stateBreak         = 2;  
int state = stateWaitForFolder;  // current

String folderGlobal = "";  

boolean firstTime=true; 

// result 
String[] temp2 = {}; 

void setup() {
  size (1100, 700); 
  background(111);
  selectFolder("Select a folder to join pdes (Cancel to abort).", 
    "folderSelected");
}

void draw() {
  // 
  switch (state) {

  case stateWaitForFolder:
    // waiting until folder has been selected
    background(111);
    text("Please choose a folder. Hit Cancel to abort.", 
      33, 33);    

    // THE WAIT IS OVER 
    if (!folderGlobal.equals("")) {
      searchFolder( folderGlobal); 
      println("");
    } // if 
    break;

  case stateDone:
    background(111);
    text("DONE: " + folderGlobal, 
      33, 33);
    showButtons();
    if (firstTime) {
      firstTime=false;
    }
    break;

  case stateBreak:
    background(111);
    text("Window was closed or the user hit cancel.", 33, 33); 
    showButtons(); 
    break; 

  default:
    // error
    println ("error 91"); 
    exit();
    break;
    //
  }  // switch
}  // func 

// -----------------------------------------------------------------------------

void searchFolder(String folderLocal) {
  //  
  // println (folderLocal);

  String[] strList;

  // https://docs.oracle.com/javase/7/docs/api/java/io/File.html 

  File f = dataFile(folderLocal); 
  strList = f.list();
  if (strList!=null) {
    println ("files in total: " + strList.length);
    int i = 0;
    for (File f1 : f.listFiles()) {
      if (f1.isFile()) {
        // is a file 
        if ( checkFileName(f1.getName()) ) {
          // is pde 
          String[] temp1 = loadStrings(f1.getAbsolutePath());
          temp2 = (String[]) concat ( temp2, temp1 ) ;
        }
      }
    } // for

    println("");
    saveStrings("r"+timeStamp()+".txt", temp2); 
    state = stateDone; // next state
  }//if
}//func

boolean checkFileName(String fileName) {
  // depending on CHECK_ONLY_FILES_CONTAINING it returns true or it returns whether the file name contains a file ending ALLOWED_ENDING
  if (CHECK_ONLY_FILES_CONTAINING)
    return fileName.contains(ALLOWED_ENDING); 
  else 
  return true;
}//func 

// -----------------------------------------------------------------
// file handling 

void folderSelected(File selection) {
  // the 'callback' function.
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
    state=stateBreak;
  } else {
    println("User selected " + selection.getAbsolutePath());
    folderGlobal = selection.getAbsolutePath();
  } // else
}//func 

// ----------------------------------------------------------------
// Input 

void mousePressed() {
  if (state==stateDone||state==stateBreak) {
    if (dist(mouseX, mouseY, 133, 133) < 66) {
      // reset / restart
      folderGlobal=""; 
      selectFolder("Select a folder to rename files (Cancel to abort):", 
        "folderSelected");
      state=stateWaitForFolder;
    }//if
    else if (dist(mouseX, mouseY, 233, 133) < 66) {
      exit();
    }//else if
  }//if
}//func 

//-------------------------------------------------------------------
//Tools

void showButtons() {
  // set mode for text and rect 
  textAlign(CENTER, CENTER);
  rectMode(CENTER);

  // rects 
  noFill();  
  rect(133-5, 133+3, 84, 23);
  rect(233-1, 133+3, 84, 23);

  // text 
  fill(255); 
  text ( "Next folder", 133, 133);
  text ( "Quit", 233, 133);

  // reset 
  textAlign(LEFT);
  rectMode(CORNER); // The default mode is rectMode(CORNER)
}//func 

//-------------------------------------------------------------------

String timeStamp() {
  return     todaysDate () 
    + "_" 
    + timeNow () ;
}

String todaysDate () {

  int d = day();    // Values from 1 - 31
  int m = month();  // Values from 1 - 12
  int y = year();   // 2003, 2004, 2005, etc.

  String Result = 
    nf(y, 2)+
    nf(m, 2)+
    nf(d, 2); 
  return( Result );
}

String timeNow () {

  int h = hour();    // Values from 1 - 23
  int m = minute();  // Values from 1 - 60
  int s = second();   // 1-60

  String Result = nf(h, 2) + "" + 
    nf(m, 2) + "" + 
    nf(s, 2); 
  return( Result );
}
//
1 Like

new version

  • with a line of **************** between the single pde-files and
  • the main file (pde with setup and draw that has the same name as the folder) is listed first.
  • Starts notepad with the resulting file.

Chrisir

// JOIN all pde in a folder

// user selects folder

//**************************************************************
// alter these values:
boolean CHECK_ONLY_FILES_CONTAINING = true; // we can search for a certain file type only e.g. ".pde"
String ALLOWED_ENDING    = ".pde";   // e.g. ".pde" when CHECK_ONLY_FILES_CONTAINING = true 
//**************************************************************

//
//states 
final int stateWaitForFolder = 0;  // consts  
final int stateDone          = 1;
final int stateBreak         = 2;  
int state = stateWaitForFolder;  // current

String folderGlobal = "";  

final String stars = "********************************************************************************";

int linesInTotal=0; 

// result 
String[] resultingStringArray = {}; 

String FileWithFolderName=""; 

// ------------------------------------------------------------

void setup() {
  size (1100, 700); 
  background(111);
  selectFolder("Select a folder to join pdes (Cancel to abort).", 
    "folderSelected");
}

void draw() {
  // 
  switch (state) {

  case stateWaitForFolder:
    // waiting until folder has been selected
    background(111);
    text("Please choose a folder. Hit Cancel to abort.", 
      33, 33);    

    // THE WAIT IS OVER 
    if (!folderGlobal.equals("")) {
      searchFolder( folderGlobal); 
      println("");
    } // if 
    break;

  case stateDone:
    background(111);
    text("DONE: " + folderGlobal, 
      33, 33);
    showButtons();
    break;

  case stateBreak:
    background(111);
    text("Window was closed or the user hit cancel.", 33, 33); 
    showButtons(); 
    break; 

  default:
    // error
    println ("error 91"); 
    exit();
    break;
    //
  }  // switch
}  // func 

// -----------------------------------------------------------------------------

void searchFolder(String folderLocal) {
  //  
  // println (folderLocal);

  String[] strList;

  // https://docs.oracle.com/javase/7/docs/api/java/io/File.html 

  resultingStringArray = new String[0]; 
  resultingStringArray = (String[]) append ( resultingStringArray, "" ) ;
  resultingStringArray = (String[]) append ( resultingStringArray, "// "+stars ) ;
  resultingStringArray = (String[]) append ( resultingStringArray, "//         joined pde-file of folder " + folderLocal ) ;
  resultingStringArray = (String[]) append ( resultingStringArray, "// "+stars ) ;
  resultingStringArray = (String[]) append ( resultingStringArray, "" ) ;

  // first handle only the file which name is the name of the folder (in processing that's the main file)
  findFileWithFolderName(folderLocal);

  File f = dataFile(folderLocal); 
  strList = f.list();
  if (strList!=null) {
    println ("files in total: " + strList.length);
    int i = 0;
    for (File f1 : f.listFiles()) {
      if (f1.isFile()) {
        // is a file 
        if ( checkFileName(f1.getName()) && !FileWithFolderName.equals(f1.getName()) ) {
          // is pde 

          // write intro for that file / tab 
          resultingStringArray = (String[]) append ( resultingStringArray, "" ) ;
          resultingStringArray = (String[]) append ( resultingStringArray, "// "+stars ) ;
          resultingStringArray = (String[]) append ( resultingStringArray, "// tab: " + f1.getName() ) ;
          resultingStringArray = (String[]) append ( resultingStringArray, "" ) ;

          // write content
          String[] temp1 = loadStrings(f1.getAbsolutePath());
          linesInTotal += temp1.length; 
          resultingStringArray = (String[]) concat ( resultingStringArray, temp1 ) ;
        }
      }
    } // for

    resultingStringArray = (String[]) append ( resultingStringArray, "" ) ;
    resultingStringArray = (String[]) append ( resultingStringArray, "// End of joined file. "+stars ) ;
    resultingStringArray = (String[]) append ( resultingStringArray, "" ) ;
    //println("");
    println("Lines in total: "
      +linesInTotal);
    String fileNameTarget="result"+timeStamp()+".txt";
    saveStrings(fileNameTarget, 
      resultingStringArray);

    // open  
    openInNotepad(sketchPath("")+fileNameTarget); 

    state = stateDone; // next state
  }//if
}//func

void findFileWithFolderName(String folderLocal) {

  // first handle only the file which name is the name of the folder (in processing that's the main file)

  String[] strList;

  File f = dataFile(folderLocal); 
  strList = f.list();
  if (strList!=null) {
    println ("files in total: " + strList.length);
    int i = 0;
    for (File f1 : f.listFiles()) {
      if (f1.isFile()) {
        // is a file 
        if ( checkFileName(f1.getName()) &&  f1.getName().equals(f.getName()+ALLOWED_ENDING) ) {
          // is pde 

          println("findFileWithFolderName says "
            + f1.getName());

          // write intro for that file / tab
          resultingStringArray = (String[]) append ( resultingStringArray, "" ) ;
          resultingStringArray = (String[]) append ( resultingStringArray, "// "+stars ) ;
          resultingStringArray = (String[]) append ( resultingStringArray, "// tab: " + f1.getName() +" main file (file name is folder name)") ;
          resultingStringArray = (String[]) append ( resultingStringArray, "" ) ;

          // write content
          String[] temp1 = loadStrings(f1.getAbsolutePath());
          linesInTotal = temp1.length; 
          resultingStringArray = (String[]) concat ( resultingStringArray, temp1 ) ;

          // store name of the FileWithFolderName globally and leave here
          FileWithFolderName = f1.getName(); 
          return;
        }
      }
    } // for
  }
}

boolean checkFileName(String fileName) {
  // depending on CHECK_ONLY_FILES_CONTAINING it returns true or it returns whether the file name contains a file ending ALLOWED_ENDING
  if (CHECK_ONLY_FILES_CONTAINING)
    return fileName.contains(ALLOWED_ENDING); 
  else 
  return true;
}//func 

// -----------------------------------------------------------------
// file handling 

void folderSelected(File selection) {
  // the 'callback' function.
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
    state=stateBreak;
  } else {
    println("User selected " + selection.getAbsolutePath());
    folderGlobal = selection.getAbsolutePath();
  } // else
}//func 

// ----------------------------------------------------------------
// Input 

void mousePressed() {
  if (state==stateDone||state==stateBreak) {
    if (dist(mouseX, mouseY, 133, 133) < 66) {
      // reset / restart
      folderGlobal=""; 
      FileWithFolderName=""; 
      linesInTotal=0; 
      resultingStringArray = null;
      selectFolder("Select a folder to rename files (Cancel to abort):", 
        "folderSelected");
      state=stateWaitForFolder;
    }//if
    else if (dist(mouseX, mouseY, 233, 133) < 66) {
      exit();
    }//else if
  }//if
}//func 

//-------------------------------------------------------------------
//Tools

void showButtons() {
  // set mode for text and rect 
  textAlign(CENTER, CENTER);
  rectMode(CENTER);

  // rects 
  noFill();  
  rect(133-5, 133+3, 84, 23);
  rect(233-1, 133+3, 84, 23);

  // text 
  fill(255); 
  text ( "Next folder", 133, 133);
  text ( "Quit", 233, 133);

  // reset 
  textAlign(LEFT);
  rectMode(CORNER); // The default mode is rectMode(CORNER)
}//func 

//-------------------------------------------------------------------

String timeStamp() {
  return     todaysDate () 
    + "_" 
    + timeNow () ;
}

String todaysDate () {

  int d = day();    // Values from 1 - 31
  int m = month();  // Values from 1 - 12
  int y = year();   // 2003, 2004, 2005, etc.

  String Result = 
    nf(y, 2)+
    nf(m, 2)+
    nf(d, 2); 
  return( Result );
}

String timeNow () {

  int h = hour();    // Values from 1 - 23
  int m = minute();  // Values from 1 - 60
  int s = second();   // 1-60

  String Result = nf(h, 2) + "" + 
    nf(m, 2) + "" + 
    nf(s, 2); 
  return( Result );
}

// ---------------------------------------------------------
// open in notepad

void openInNotepad(String currentFile) {
  // open in notepad

  if (currentFile.equals("")) {
    //return; // leave here (not necessary)
  }

  try
  {
    ProcessBuilder pb = new ProcessBuilder("notepad.exe", currentFile);
    Process p = pb.start();
  }
  catch ( Exception /* IOException, URISyntaxException */ e )
  {
    e.printStackTrace();
  }//catch
}
//
2 Likes

I have decided to stick with atom.io as it currently does everything that I need it to do. You can still have multiple tabs or sketch files in one project folder if so desired. However this was mainly to counter the issue of bracket folding.

for the language

for syntax management

just add your processing install folder to the “path” variables in your system config, and your good to go, press ctrl + alt + b to start the processing sketch. Its that easy.

1 Like