Archive for the ‘Eagle PCB’ Category

Eagle PCB ULP Tutorial: Using NotePad++ to Write ULP and highlight Code

Thursday, October 31st, 2013

Research Link

From the ReadMe.txt file

Notepad++ has a User Defined Language facility that is documented in its help files and at the NpWiki++: http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=User_Defined_Languages

The file "Notepad++ UserDefineLang for Cadsoft ULP v0.1.xml" contains a beta release of a Notepad++ user defined language corresponding to ULP for Cadsoft Eagle v5.  
This language defintion may not always correctly display ULP keywords, for example, owing to white space or your variable names. 

To use this langauge definition in Notepad++ click View | User-Defined Dialog | Import and select the XML file.  Now when editing a file with extension .ULP the Eagle 
ULP keywords should be formatted according to the styles in the User-Defined dialog.

In order to have Notepad++ automatically open the ULP file and position the cursor on the line of an error in a ULP, you need Eagle V5.5 or later.  
Set the Eagle Options | User Interface | External Text Editor field to (include the quotation marks and edit the Notepad++.exe location to suit your installation):
"C:\Program Files\Notepad++\Notepad++.exe" -n%L "%F" 

Please refer to "Help | Editor Windows | Text Editor" in the Eagle help files for more information.  

Implementation Notes

  • I am not sure but I think that Windows 7 prevents writes to the NotePad++ files that save the setup.  I ended up taking ownership of the directory that holds the NotePad++ installation.
  • When I tried to use I could not get the text to highlight in color.  The italics and bold fonting worked but not the color.  Fix this by going into the "style configurator" of NotePad++ and unchecking "Enable global foreground color"

 

Running ULP from within NotePad++

Next I want to be able to execute the ULP from within NotePad++.  To do this I need to be able to 

  • run eagle and the ULP from the windows command line.  Example: eagle -C "run bom_ew bla; quit" qm07_blm.sch  … this particular line also terminates eagle which I probably will not use.
  • See the output of the script from within NotePad++

 

Execution from within NotePad++:  You can run eagle from a dead start using Windows 7 command line.  See Running Eagle ULP from windows command line and terminating eagle when done .  

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

Monday, October 28th, 2013

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

Wednesday, October 23rd, 2013

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");   


 

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

Tuesday, October 22nd, 2013

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. 

ULP tutorial that writes all the Reference Designators Values and an example Attribute to a text file

Friday, October 18th, 2013

For my BOM ULP I want to use attribute fields that you can see here.  To do this I need to know how to read an attribute.  The code snippet below does that.  The test attribute name is FUDGE and the test value is VANILLA.   To read attributes you need to know what they are called as you will see below.


dlgMessageBox("Do you want to count the parts?","Yes","No","Maybe");                       //opens a dialog box: no matter what you answer it will count the parts.   It is a joke.


//—— 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);
    }
    

//—— This is the loop that gets the parts and writes to file —–//

int cnt=0;

output(ULP_Path + "ListOfParts.txt", "wt")
{  
if (schematic) schematic(S)                                                                //This nested set of loops cycle through all the parts and increment the count each pass through
  {
    S.parts(P)
      {
        P.instances(E)                                                             
          { 
            printf(E.name + "     " + E.value + "     " + P.attribute[“FUDGE”] + "\n");
            cnt++;
          }
      }
  }
 } 
  

string result;
sprintf(result, "The parts count is %d", cnt);
dlgMessageBox(result, "+Yes", "No","Maybe");                                               // display the parts count in a dlgMessageBox
  
exit(0); 

Eagle PCB ULP User Language Program Tutorial that writes all the reference designators to a file

Thursday, October 17th, 2013

Now it is time to build on the previous examples.  This example does the following:

  • Get the path of the User Language Program (ULP)
  • It loops through all the parts
  • As it loops it appends the part name to a file

dlgMessageBox("Do you want to count the parts?","Yes","No","Maybe");                       //opens a dialog box: no matter what you answer it will count the parts.  


//—— 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);
    }

    

//—— This is the loop that gets the parts and writes to file —–//

string FileLine;
int cnt=0;

output(ULP_Path + "ListOfParts.txt", "at")
{  
if (schematic) schematic(S)                                                                //This nested set of loops cycle through all the parts and increment the count each pass through
  {
    S.parts(P)
      {
        P.instances(E)                                                             
          {
            printf(FileLine += E.name +"\n");
            cnt++;
          }
      }
  }
 } 
  

string result;
sprintf(result, "The parts count is %d", cnt);
dlgMessageBox(result, "+Yes", "No","Maybe");                                               // display the parts count in a dlgMessageBox
  
exit(0); 


The result will look like this: ListOfParts.txt

Simple Eagle PCB ULP User Language Program Tutorial to show the path of the ULP

Thursday, October 17th, 2013

If you want to alter anything on the schematic with a User Language Program you will need to output to a command line script file.   The most common thing to do is write it to the same directory that the ULP is in.  To do that you are going to need to know the path of the ULP.  Below is a program that gives you the path of the ULP.


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

  if (pos >= 0) 
    { 
      ULP_Path = strsub(argv[0], 0, pos + 1);
    }
    
dlgMessageBox(ULP_Path,"aroo","aree");                       //opens a dialog box with the path in the notification area

exit(0);


 

Notes for Writing an Eagle PCB Change of Value User Language Program

Thursday, October 17th, 2013

Script functions required

  • Need the script syntax to change a part value.  The command line to issue to change a part value is: value refdes value.  And example would be to change R5's value to 100 you would issue the command:  value r5 100
  • Need to add attribute fields to all parts.  Example: Attribute r5 Fudge  adds the fudge attribute. Pops up a window prompting for value of this attribute.  ATTRIBUTE r4  fudge 'vanilla'  is the correct syntax to include the value.
  • Need to run a script on libraries to turn on all value fields.  The command line to issue is: value on  while the device is up in the librarie editor.

​  

Requirements for Ideal Bill of Materials

  • Need to turn on the value field for all parts.  This will hold the basic resistance, capacitance, inductance values or integrated circuit part number.

BOM Fields

  • Item Number: Line item number
  • Quantity
  • Schematic Value: This is the simple short value shown in the schematic. Short values avoid clutter on the schematic
  • Vendor Part Number: Attribute field:  This will hold the catalog part number.  Example Mouser part number 
  • Manufacturers Part Number:  Attribute field: Example: Hittite part number
  • Internal Part Number: Attribute field:  Example: The company part number that covers all 0.1 uF capacitors
  • Description:  Attribute field: Description with specifications:  Example: CAP CER 4.7UF 35V 10% X5R 1210
  • Reference Designators: Grouped by value.  
  • Package: Need this to ease confirmation of correct purchase: Example: 0603

The relevant object is the schematic object

SCHEMATIC
     GRID
     LAYER
     LIBRARY
     SHEET
         CIRCLE
         RECTANGLE
         FRAME
         TEXT
         WIRE
         POLYGON
             WIRE
         PART
             INSTANCE
                 ATTRIBUTE
         BUS
            SEGMENT
                 LABEL
                     TEXT
                     WIRE
                 WIRE
          NET
              SEGMENT
                  JUNCTION
                  PINREF
                  TEXT
                  WIRE

A simple Eagle PCB ULP User Language Program Tutorial to Count the Number of Parts on a Board

Wednesday, October 16th, 2013

This program demonstrates how you access the Schematic object with an Eagle PCB User Language Program – ULP.


dlgMessageBox("Do you want to count the parts?","Yes","No","Maybe");                       //opens a dialog box: no matter what you answer it will count the parts.  

int cnt=0;
if (schematic) schematic(S)                                                                //This nested set of loops cycle through all the parts and increment the count each pass through
  {
    S.parts(P)
      {
        P.instances(E)                                                             
          {
            cnt++;
          }
      }
  }

string result;
sprintf(result, "The parts count is %d", cnt);
dlgMessageBox(result, "+Yes", "No","Maybe");                                               // display the parts count in a dlgMessageBox
  
exit(0); 

A simple Eagle PCB ULP User Language Program to Open a dialog message box dlMessageBox

Wednesday, October 16th, 2013

This is how you open a file dialog box:


dlgMessageBox("Fudge-","aroo","aree");                       //opens a dialog box
exit(0);


Cut and paste it into a file that you name:  dlgMessageBox.ulp