Eagle PCB ULP Tutorial: User Language Program that lists the library .lbr files in project directory

I want to be able to write a script to mass change all the libraries that a project depends on in order to make better B.O.M.  Bill Of Materials.  The following script lists the libraries in the project directory.  It writes the names of the libraries with full path to a text file named: ListOfLibraries.txt


//—— Get the Project Path ——//

string Project_Path;
string get_project_path() {
      if (board)     board(B)     return(filedir(B.name));
      if (schematic) schematic(S) return(filedir(S.name));
      if (library)   library(L)   return(filedir(L.name));
}

Project_Path = get_project_path();
dlgMessageBox(Project_Path, "+Yes", "No","Maybe");

string F[];
int i;
int n = fileglob(F, Project_Path + "*.lbr");                                                     //– Get file names with .lbr extension in project directory 
output(Project_Path + "
ListOfLibraries.txt", "wt"){ for(i=0;i<n;i++){ printf(F[i] + "\n");}  }   //– Write all the .lbr file names to text file


string ResultOfLibCount;
sprintf(ResultOfLibCount, "The number of libraries is %d", n);
dlgMessageBox(ResultOfLibCount, "+Yes", "No","Maybe"); 


fileglob stuffs an array with the files that satisfy the condition specified by the string supplied.  

Eagle PCB ULP Tutorial: User Language Program that lists the directory path of the Project File

When you need to know the path of the project you are running the ULP within the following code snippet is useful.


string get_project_path() {
  if (board)     board(B)     return(filedir(B.name));
  if (schematic) schematic(B) return(filedir(S.name));
  if (library)   library(B)   return(filedir(L.name));
}


string Directory;
Directory = get_project_path();
dlgMessageBox(Directory, "+Yes", "No","Maybe");   


Zuchini Onion Garlic Ginger Soup

Research Links

Ingredients

  • Olive Oil
  • 1 white onion, sliced
  • 8 to 9 large cloves garlic, sliced thinly 
  • 4 medium zucchini, about 1 1/2 pounds
  • 4 cups chicken or vegetable broth 
  • 1/2 teaspoon fresh ginger
  • Salt and pepper to taste

Put sliced garlic and onions and sautee in olive oil on medium-low heat for about 10 minutes, or until the onion is soft and translucent.

When the onions are soft, add the zucchini and cook until soft. Add the broth and bring to a simmer. Simmer at a 
low heat for about 45 minutes.

Let cool slightly, then blend with an immersion blender until creamy, or transfer to a standing blender to puree. 
Be very careful if you use the latter; only fill the blender half full with each batch, and hold the lid down tightly 
with a towel.

Taste and season with ginger, salt and pepper. Like most soups, this is significantly better after a night in the 
refrigerator to let the flavors meld.

Comments

  • This one is a real winner.  The ginger counterpoints against a very gentle sweetness from the zuchini 
  • In the original recipe they call for powdered ginger.  I think that would be a huge mistake.  The fresh ginger makes this recipe.

Tutorial: Eagle PCB ULP to write Script that Changes all the Devices in a library to have Value = ON

You select a device in an opened library for edit by using this syntax:  edit deviceset

Value is set to an active editable value with the syntax:  value on

Thus on a meta level this script is going to do the following things for each part in the library:

  • write the open device command to script file using syntax:  edit deviceset
  • write the turn the device value to script file using syntax: value on
  • repeat until all the parts in the library have been cycled through

This script will build upon the script that lists the devicesets in a library.


//—— Get the ULP Path ——//

string ULP_Path;
char bkslash = '/';
int pos = strrchr(argv[0], bkslash);

  if (pos >= 0) 
    { 
      ULP_Path = strsub(argv[0], 0, pos + 1);
    }

output(ULP_Path + "TurnValueOnAllParts.scr", "wt"){library(L) { L.devicesets(D) { printf("edit " +  D.name + ".dev" + "\n"); 
                                                                                  printf("value on \n");
                               
                               }}}


Note that the script cycles through devicesets and not devices.