element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Autodesk EAGLE
  • Products
  • More
Autodesk EAGLE
EAGLE User Support (English) Rename wires
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Autodesk EAGLE requires membership for participation - click to join
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 34 replies
  • Answers 2 answers
  • Subscribers 172 subscribers
  • Views 2863 views
  • Users 0 members are here
Related

Rename wires

Former Member
Former Member over 11 years ago

Hello,

 

In an Eagle-shematic (50 pages) I need to change quite a lot of wire names. Select every single and change the name would do the job, but is quite time consuming...

 

The wires can have diferent names, some examples:

W500/01

W500/02

W500/xx

...

W501/01

W501/02

...

W502/01

...

W600/01

W600/02

...

W601/01

...

W700/BN

W700/BU

...

W135/1.5RD

...

 

Now as writen before, a lot of wire names should be changed. For example all W500/xx will be renamed to W512/xx and so on. Can somebody tell me how I can do that a bit more eficient? I tried this one: Renaming parts in Eagle CAD by editing the XML directly

Works quite well for part names, but the wire names are not recognised by this tool. I would have to change the source code (I think I'd be able to do that) and then recompile that, but I have no Idea about C++ and how to compile...

 

So it would be great if somebody had another simple and working idea how to do that.

 

Thank you

 

My configuration:

Eagle 6.5.2 Hobbyist licence

Win 8.1

  • Sign in to reply
  • Cancel
Parents
  • AnalogNotes
    0 AnalogNotes over 11 years ago

    Well, I'm going to show my Unix bias here, but there are a *lot* of tools available to do things like this built in to Linux and OS X and available for Windows.  It depends how deep you want to go down the rabbit hole!

     

    My first reaction would be to use "sed" the stream editor.  (Do a search for "sed for windows".)  Sed is used at the command line, and takes some input, modifies it, and sends it to some output.  For example,

     

    sed 's/W500/W512' schematic.sch > newschematic.sch

     

    which would change occurrences of W500 to W512 and create a new file called newschematic.sch without changing the original schematic.sch.  To make sure things look good, you could use the "diff" command on the two files to see exactly what was changed.  Of course, you wouldn't want to have to change that command line and re-run it for every substitution you want to make, so it's better to create a sed script file with all the commands you want (somewhat analogous to that CSV file in the referenced article), and then run the command:

     

    sed -f script.file schematic.sch > newschematic.sch

     

    Sed is a great tool and can be used over and over again without having to modify and recompile.  Now, if you want to learn something a little more sophisticated, there is a simple, yet amazing text processing language called AWK.  AWK knows how to read in a text file line by line, split the line into words and do things to those words.  You can do more testing and manipulating than you can in sed.  AWK is very much like the C programming language, so you can do things like printf to create new output.  Then, if you want to really go down the rabbit hole and get into more powerful scripting languages, the big three in my book are PERL, Python and Ruby.  Each has strengths and weaknesses and each has devout followers and detractors.  Let me know if you're interested or do a search to learn more...

     

    BTW, if you don't want to download and install any of these unix tools, you might consider using Windows PowerShell too...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to AnalogNotes

    Thank you for your help.

     

    after some tests I found out that Win doesn't like the following command:

    sed 's/W500/W5000' 30c.sch 30d.sch

    But the following seems to work so far (thank you google):

    sed "s/W500/W5000/" 30c.sch 30d.sch


    Well, first everything seems to work fine, it reads and schows all data in the 30c file, but after everything has finished, the 30d.sch is still empty. Any idea what I am doing wrong? Sorry I have to admit that I'm not the shell-guy...

     

    As for the advice with the inconsistent board: Thank you for your advice, but there is no board, only the schematic. It is the shematic of my newly build camper. I know, eagle may not be the best solution for doing that, but works so far ok for me...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • AnalogNotes
    0 AnalogNotes over 11 years ago in reply to Former Member

    You need a greater than sign before the last file name.  The greater than sign is basically an arrow pointing to where the output should go...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to AnalogNotes

    small thing, big consequences...thank you very much, I missed that one. Now everything works perfectly. In combination with the script file it is very powerfull.

     

    For a more complex rename I'm now looking for a solution as well. Lets asume we have the following net names:

    W100/1.5RD

    W101/1.5RD

    W102/50RD

    W103/50BK

    W104/1.5OR

    W105/xxxx

    ...

    W150/1.5RD

    W151/1.5OR

     

    These names are in no order somewhere in the schematic. Is it possible to sort these so that the first W1xx is on page 1 and so on. Important; the numbers and letters after the slash should not be changed. So for example if W150/1.5RD is changed to W103 it should still have the /1.5RD at the end. The "old" W103 may then become W104/50BK, W104 is changed to W105/1.5OR and so on...Hope you understand what I'd like to do.

     

    Thank you very much for the great help.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • AnalogNotes
    0 AnalogNotes over 11 years ago in reply to Former Member

    My suggestions so far have been based on treating the schematic file as one big stream of text.  (That is what Unix was originally designed for, to process streams of text.). When we need to start thinking about the structures in a file, we need to use a different type of tool.

     

    There are two categories of solution that come to mind.  We can either try to use the tools that are built in to EAGLE, or we can use one of those scripting languages I mentioned.  It's a trade off between specific knowledge and general applicability.  Are you more interested in learning more about EAGLE or learning how to write scripts that can apply to other programming problems?

     

    Let's assume that you just want to get this problem solved, so we'll use available tools for this task and not reinvent anything.  EAGLE has a command prompt right there on the screen.  You can type commands instead of selecting them with a mouse.  Just for grins, when you have your schematic open, type "win fit" and press the enter key.  Just like a sed file, or an operating system batch file, you can put a series of these commands into an EAGLE script file and run it.  If you use a particular script a lot, you can assign it to a key or add it to a menu.  This is what makes EAGLE so appealing to an old Unix guy like me!

     

    More in a bit.  I can't stand using this iPad to type...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • AnalogNotes
    0 AnalogNotes over 11 years ago in reply to AnalogNotes

    Now interestingly enough, The EAGLE scripting language doesn't have any control structures.  That means there is no way to test things, or repeat things, other than to duplicate a line x number of times.  EAGLE scripts are just brute-force lists of commands to run.

     

    So, for whatever reason, the Cadsoft folks decided to leave the scripting alone and add a different programming language to create scripts.  This is called "User Language" and you create User Language Programs (ULPs).  The interesting thing about ULPs is that they don't get to change things while they run, they have to generate EAGLE scripts that you run after the ULP is complete.  In some ways, this is a very Unix-like thing to do.  And I'm part German, (born in Frankfurt actually), so I have the in-group privilege to say it's a very German thing too!  LOL

     

    SIDE NOTE: It would be amazingly cool if Cadsoft made all of the EAGLE commands available as library functions that could be called by other languages.  Personally, I'd love it if I could start up a Python program, import an EAGLE library and directly manipulate a schematic or board!  image

     

    So, anyway, User Language is very powerful, it knows about the structures in EAGLE files.  This saves *lots* of time!  You can write a ULP that works with the schematic, the board, a library, or parts of any of them.

     

    I'm not sure I know *exactly* what you're trying to do, but my first interpretation is that you want to renumber wires based upon which page of the schematic they are on.  So, in a ULP, we would start by using the schematic, then looping through each page of the schematic.  The code to do that would be:

     

    schematic(S){

      S.sheets(SH){

         // do something here

      }

    }


    The first line says we're going to work with the schematic and call it "S".  The next line says, take S, and go through each sheet in it one at a time and call it "SH" while we're using it.  I took a quick look at the EAGLE help, and I found that you can go through each wire of the sheet by adding:


    schematic(S){

      S.sheets(SH){

        SH.wires(W){

          // do something with each wire here

        }

      }

    }


    But the problem seems to be that the name of each wire is not listed in the data members of the UL_WIRE structure.  I'm guessing we'll have to loop through something different, like nets() maybe:

     

    schematic(S){

      S.sheets(SH){

        SH.nets(N){

          // do something with each net here

        }

      }

    }


    This illustrates the toughest part of writing a ULP, figuring out the parent-child relationships of all the structures.  Once you get the structure correct, then at the "do something" point, we output the command that does the actual rename.


    I apologize, but I must depart for the day, my son turned 19 today and we have a party to prepare for.  I hope I've given you some hints as to how you might proceed.  I'm not sure, but I think I'd probably look at looping through segments() and labels() next.  Everything is documented in EAGLE help.  If you want to directly access the file with your web browser the way I do, open the file eagle_en.htm in the bin directory of your EAGLE installation, or you can get to the help files on my web site at http://analognotes.com/eagle/helpfiles/


    If you learn from reading other people's code, go to the Cadsoft ULP download site and search for "renumber"...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to AnalogNotes

    Your suggestions so far (with sed) have been just great to change the names of roundabout 60% of the names I'd like to change (W3xx up toW9xx). To change the W1xx names are so to say a new problem.

     

    You assume right, at the moment I just need to get this problem solved in Eagle. Going deeper into scripting and programming would need time I don't really have right now...

     

    Win fit? Hmm, not sure how this special command would help me on that right now...for that I use Ctrl+F2...But while I'm writing about; is it just to tell me there are powerfull commands in Eagle? If so, I know that, but I have no Idea how to use them correctly to solve my problem. This is my first project in Eagle and I am learning by doing. That's also why I have to rename a lot. It startet small and back then the net names where not really an issue, but as things grew (up to 50 pages right now) I got more and more messed up on that...

    I think the rename command would be my best friend, but to solve my problem in a reasonable amount of time and manual work, that one should probably bring some other friends along with. As for using scripts in Eagle, I played a little bit around with the scr and ulp functions in Eagle, but I have not really a clue how to use them correctly to solve my problem. Said that, i'd really apreciate if you could give me some advice how to do that.

     

    By the way, if that script could also reorder the terminals who are aranged "chaotic" all over the shematic would be nice. I promess, this is the last "new" labelling issue I'll ask about ;-)

    The terminals are labelled 11X01, 11X02..., 12X01, 12X02..., 14X01...

    11X, 12X 14X should never change, the numbers after the X would be nice if they start on page one left  with 01 and then continue on. Mainly the same problem as with the W1xx but no numbers/letters at the end who schouldn't be changed.

     

    Thank you very much

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to AnalogNotes

    I think my last and your last posts just crossed each other. Anyway.

     

    I think you understood me a bit wrong. I don't want to rename based on the page number.

    Right now I have the following (just an example):

                               Now                       Should be

    W100/1.5RD  on page 27                  1. W1xx wire on page 01

    W101/1.5RD  on page 32                  2. W1xx wire on page 01

    W102/50RD  on page 01                   3. W1xx wire on page 01

    W103/50BK  on page 45                   1. W1xx wire on page 02

    W104/1.5OR  on page 26                 2. W1xx wire on page 02

    W105/xxxx  on page 14                    1. W1xx wire on page 03

    ...                                                     ...

    W149/1.5OR  on page 06                  5. W1xx wire on page 26

    W150/1.5OR  on page 01                  1. W1xx wire on page 27

     

    Now the old W100 (on page 27) will be renamed to, W150 (assumed it is the 150iest W1xx wire in the shematic). But the last part of the name should be kept as it was before. The last part of the name is the dimension and the color of the wire, so it should stick to that wire where it is right now. So new we would have:

    W100/1.5OR  on page 01 (because the wire on Page 01 is a 1.5OR)

    W150/1.5RD  on page 27 (because the wire on page 27 is a 1.5RD)


    I'll have a look at your sources...and try around a little bit. Happy birthday to your son and have a nice party.

    Btw. we could also write in german ;-) I've just chosen English because I tought the chances to find an Eagle crack would be bigger. Not sure if that would be apreciated if we go on in german. German would be easier, but at the end is also a foreign language for me. So its up to you...


    While writing I just got another idea: I use sed to change all W1xx to W999 (or something else). I would then get W9900, W99901, W99902... Then I would only need a solution how to rename all the W999xx in the script one after the other to W100, W101... Then I get W100xx, W101xx, after that just delete the xx part. Not sure if sed can do that, and if it can how. Probably to simple? I may run in trouble on that wires who start on one page and continue on diferent other pages...?


    Thank you

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • AnalogNotes
    0 AnalogNotes over 11 years ago in reply to Former Member

    Ursicin Caminada wrote:

    Win fit? Hmm, not sure how this special command would help me on that right now...for that I use Ctrl+F2...But while I'm writing about; is it just to tell me there are powerfull commands in Eagle?

     

    Yes, that is just to point out that there are many powerful commands and learning them is a good thing.  Every command can be started from the command line instead of just the mouse...

     

    I think you understood me a bit wrong. I don't want to rename based on the page number.

    Right now I have the following (just an example):

                               Now                       Should be

    W100/1.5RD  on page 27                  1. W1xx wire on page 01

    W101/1.5RD  on page 32                  2. W1xx wire on page 01

    W102/50RD  on page 01                   3. W1xx wire on page 01

    W103/50BK  on page 45                   1. W1xx wire on page 02

    W104/1.5OR  on page 26                 2. W1xx wire on page 02

    W105/xxxx  on page 14                    1. W1xx wire on page 03

    ...                                                     ...

    W149/1.5OR  on page 06                  5. W1xx wire on page 26

    W150/1.5OR  on page 01                  1. W1xx wire on page 27

     

    Yes, I must be misunderstanding, because it is looking to me like you rename all the wires starting on page one, then going to page two, then three...

     

    Now the old W100 (on page 27) will be renamed to, W150 (assumed it is the 150iest W1xx wire in the shematic). But the last part of the name should be kept as it was before. The last part of the name is the dimension and the color of the wire, so it should stick to that wire where it is right now. So new we would have:

    W100/1.5OR  on page 01 (because the wire on Page 01 is a 1.5OR)

    W150/1.5RD  on page 27 (because the wire on page 27 is a 1.5RD)

     

    To keep the last part of the name the same, you will have to use the string functions of EAGLE.  First, use the strchr() function to find the location of the "/" character, then use the strsub() function to extract the last part of the string, so etwas:

     

    string oldname = "W154/1.5OR";

    char c = '/';

    int position = strchr(oldname, c);

    string lastpart = strsub(oldname, position);

     

    Now, lastpart should be "/1.5OR".  You can test this by going to the EAGLE control panel, then File->New->ULP and copy this and save it:

     

    string oldname = "W154/1.5OR";

    char c = '/';

    int position = strchr(oldname, c);

    string lastpart = strsub(oldname, position);

    dlgMessageBox(lastpart);

     

    Now open your schematic and then click the ULP button and choose the file you just saved.  the dlgMessageBox command will open a dialog box that should say "/1.5OR" and have an OK button.

     

    To generate the full new name, use the "sprintf" command, so:

     

    int number = 100;

    string newname;

    sprintf( newname, "W%d", number);

     

    Now, newname is "W100".  Then, add the last part to the wire name with "+=", so:

     

    newname += lastpart;

     

    Test:

     

    int number = 100;

    string oldname = "W154/1.5OR";

    char c = '/';

    int position = strchr(oldname, c);

    string lastpart = strsub(oldname, position);

    string newname;

    sprintf(newname, "W%d", number);

    newname += lastpart;

    dlgMessageBox(newname);

     

    OK, lunch time.  I will post later about how to use this in a loop to process all wires...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • AnalogNotes
    0 AnalogNotes over 11 years ago in reply to AnalogNotes

    OK, let's look at how we would loop through everything.  In a previous message, I talked about how EAGLE can loop through every sheet of a schematic.  Let's make a test to see how that works.  Create a new ULP or you can use the one we created in the last message and delete everything in it.  Let's start with this code, so copy and paste this into the ULP:

     

    string sheetname;

    string message;

     

    schematic(S){

      S.sheets(SH){

        sprintf(sheetname, "Sheet: %d\n", SH.number);

        message += sheetname;

      }

    }

    dlgMessageBox(message);

     

    Save it and then run it by clicking the ULP button, or you can type "run" and the filename at the command line in the schematic.  (I called my ULP "rename.ulp", so I type "run rename.ulp" and press the enter key.)  You should get a dialog box with a line for every page of the schematic.  EAGLE dialog boxes are not very smart, so it may extend below the bottom of the screen.  Press the escape key or the space bar or click on the close button of the window.

     

    Now, let's make a list of all the nets on each page of the schematic.  Add in these lines after "message += sheetname;":

     

    SH.nets(N){

      message += N.name;

      message += " ";

    }

    message += "\n";

     

    The important things to know here are that we are going through all of the nets on the schematic page, and when we are using each one, it is called "N".  We add the name of the net to the message, then to make it readable, we are adding a space (" ").  After each page, we are adding a new line ("\n") to separate the pages.  So the whole thing should look like:

     

    string sheetname;

    string message;

     

    schematic(S){

      S.sheets(SH){

        sprintf(sheetname, "Sheet: %d\n", SH.number);

        message += sheetname;

        SH.nets(N){

          message += N.name;

          message += " ";

        }

        message += "\n";

      }

    }

    dlgMessageBox(message);

     

    Save that and run it.  Do you see all of the names of your wires?  If not, we are looking in the wrong place.  Let me know and we will try something else.  If you do see the names that you want to change, then we can proceed.

     

    Now it's time to add in the name changing code from my last message.  Let's remove the space and newline entries first, then we need to define some more variables:

     

    string oldname;

    string newname;

    string lastpart;

    char c = '/';

    int number = 100;

    int position;

     

    Put those lines below the sheetname and message variables.  Now the name changing lines:

     

    oldname = N.name;

    position = strchr(oldname, c);

    lastpart = strsub(oldname, position);

    sprintf(newname, "W%d", number);

    newname += lastpart;

    number += 1;

     

    Do you see how I got oldname from the name of the net this time?  The last line here is the magic bit that makes the wire number count up.  Now, let's put in the lines that show what we have done so far in the dialog box.  The whole thing should be:

     

    string sheetname;

    string message;

    string oldname;

    string newname;

    string lastpart;

    char c = '/';

    int number = 100;

    int position;

     

    schematic(S){

      S.sheets(SH){

        sprintf(sheetname, "Sheet: %d\n", SH.number);

        message += sheetname;

        SH.nets(N){

          oldname = N.name;

          position = strchr(oldname, c);

          lastpart = strsub(oldname, position);

          sprintf(newname, "W%d", number);

          newname += lastpart;

          number += 1;

          message += "Rename old: ";

          message += oldname;

          message += " to new: ";

          message += newname;

          message += "\n";

        }

      }

    }

    dlgMessageBox(message);

     

    Run that and see if that looks like what you are trying to accomplish.  In the next message, I'll show you how to generate the script that actually renames everything...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • AnalogNotes
    0 AnalogNotes over 11 years ago in reply to AnalogNotes

    OK, let's look at how we would loop through everything.  In a previous message, I talked about how EAGLE can loop through every sheet of a schematic.  Let's make a test to see how that works.  Create a new ULP or you can use the one we created in the last message and delete everything in it.  Let's start with this code, so copy and paste this into the ULP:

     

    string sheetname;

    string message;

     

    schematic(S){

      S.sheets(SH){

        sprintf(sheetname, "Sheet: %d\n", SH.number);

        message += sheetname;

      }

    }

    dlgMessageBox(message);

     

    Save it and then run it by clicking the ULP button, or you can type "run" and the filename at the command line in the schematic.  (I called my ULP "rename.ulp", so I type "run rename.ulp" and press the enter key.)  You should get a dialog box with a line for every page of the schematic.  EAGLE dialog boxes are not very smart, so it may extend below the bottom of the screen.  Press the escape key or the space bar or click on the close button of the window.

     

    Now, let's make a list of all the nets on each page of the schematic.  Add in these lines after "message += sheetname;":

     

    SH.nets(N){

      message += N.name;

      message += " ";

    }

    message += "\n";

     

    The important things to know here are that we are going through all of the nets on the schematic page, and when we are using each one, it is called "N".  We add the name of the net to the message, then to make it readable, we are adding a space (" ").  After each page, we are adding a new line ("\n") to separate the pages.  So the whole thing should look like:

     

    string sheetname;

    string message;

     

    schematic(S){

      S.sheets(SH){

        sprintf(sheetname, "Sheet: %d\n", SH.number);

        message += sheetname;

        SH.nets(N){

          message += N.name;

          message += " ";

        }

        message += "\n";

      }

    }

    dlgMessageBox(message);

     

    Save that and run it.  Do you see all of the names of your wires?  If not, we are looking in the wrong place.  Let me know and we will try something else.  If you do see the names that you want to change, then we can proceed.

     

    Now it's time to add in the name changing code from my last message.  Let's remove the space and newline entries first, then we need to define some more variables:

     

    string oldname;

    string newname;

    string lastpart;

    char c = '/';

    int number = 100;

    int position;

     

    Put those lines below the sheetname and message variables.  Now the name changing lines:

     

    oldname = N.name;

    position = strchr(oldname, c);

    lastpart = strsub(oldname, position);

    sprintf(newname, "W%d", number);

    newname += lastpart;

    number += 1;

     

    Do you see how I got oldname from the name of the net this time?  The last line here is the magic bit that makes the wire number count up.  Now, let's put in the lines that show what we have done so far in the dialog box.  The whole thing should be:

     

    string sheetname;

    string message;

    string oldname;

    string newname;

    string lastpart;

    char c = '/';

    int number = 100;

    int position;

     

    schematic(S){

      S.sheets(SH){

        sprintf(sheetname, "Sheet: %d\n", SH.number);

        message += sheetname;

        SH.nets(N){

          oldname = N.name;

          position = strchr(oldname, c);

          lastpart = strsub(oldname, position);

          sprintf(newname, "W%d", number);

          newname += lastpart;

          number += 1;

          message += "Rename old: ";

          message += oldname;

          message += " to new: ";

          message += newname;

          message += "\n";

        }

      }

    }

    dlgMessageBox(message);

     

    Run that and see if that looks like what you are trying to accomplish.  In the next message, I'll show you how to generate the script that actually renames everything...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • Former Member
    0 Former Member over 11 years ago in reply to AnalogNotes

    Wow, thank you for your huge work and patience.

     

    Unfortunately it doesn't look like a 5-minute-job to try out image I'll try to go through that step by step, but that has to wait till tomorrow evening. You know, there are such unimportant things like work, sleeping and so on who have to be done as well image

     

    I really apreciate your help and how you explain it step by step. Like that I have a small chance in understanding what I'm doing... Thank you very much.

     

    Good night

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Former Member

    Thanks a lot for your help. So far everything seems to work verry nice. Just one thing: With oldname = N.name; we look for all net names. If possible I'd like to change only a range of names, because for example W300/xx-W900/xx are already in the correct order and should not be changed anymore.

     

    The simplest would probably be to look for all wires starting with W1xx (W100 up to W199). I tried to use wildcards like * and ?? (I changed the N.name command to something like W1* or W1?? or W1##) but that doesn't seem to work...I think there is a trivial solution for that?

     

    Even beter would be if i could chose a range of numbers to change (only if it doesn't gets to complex!): For example from W100/xxxx up to W299/xxxx, or W100-W199 plus some unnamed wires (N$1 to N$150 for example)

     

    strxstr? Will that be ULP for beginners lesson 2? image

    ^[ \t]+|[ \t]+$...hmm that looks for me like: You have a roof, you spent time repairing it + you spend more time on repairing it and that costs you more $...am I right? image


    thanks and good night

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • AnalogNotes
    0 AnalogNotes over 11 years ago in reply to Former Member

    Ursicin Caminada wrote:

    The simplest would probably be to look for all wires starting with W1xx (W100 up to W199). I tried to use wildcards like * and ?? (I changed the N.name command to something like W1* or W1?? or W1##) but that doesn't seem to work...I think there is a trivial solution for that?

     

    One (simple) way is to add this as a test after oldname = N.name;:

     

    string startpart = "W1";

    int position = strstr(oldname, startpart);

    if (pos >= 0)

      // It starts with W1 and it should be renamed...

     

    Even beter would be if i could chose a range of numbers to change (only if it doesn't gets to complex!): For example from W100/xxxx up to W299/xxxx, or W100-W199 plus some unnamed wires (N$1 to N$150 for example)

     

    strxstr? Will that be ULP for beginners lesson 2?

     

    Yes, strxstr might be a good answer for this because you could write a regular expression that would match the W, then the number, then the slash, or the N$ and the number.

     

    ^[ \t]+|[ \t]+$...hmm that looks for me like: You have a roof, you spent time repairing it + you spend more time on repairing it and that costs you more $...am I right?

     

    LOL!  In a regular expression, "^" means the beginning of a line, and "$" means the end of a line.  (They even use "$" as a command in the vim editor to move the cursor to the end of the line.)  The square brackets [] are used for specifying a group, in this case a space and a "\t" which means a tab character.  A regular expression matches anything in the group, so it can be either a space or a tab.  The "+" means one or more of what is right before it.  ("?" is zero or one of the previous thing, and "*" is zero or more of the previous thing.  This is different from the ? and * wildcards.)  The "|" is used to mean the test "or".  So,

     

    ^[ \t]+ means one or more spaces or tabs at the beginning of a line

    |  or

    [ \t]+$ means one or more spaces at the end of the line

     

    Simple, yes?  image

     

    So, to match your wire name, the regular expression would be W\d+ which means a "W" followed by one or more digits.  If you wanted to get all W1xx and W2xx numbers, you could use W[12]\d+ which means one or more digits after either W1 or W2.  You can keep trying to modify the regular expression to test for the range of numbers you want to use, or you might want to just use oldname, get rid of the "W" and use strtol() to convert the digits to a number that you can test with some combination of =, < or >.  It would be easy to put a couple variables at the top of your script instead of trying to modify a regular expression every time:

     

    int minimum = 100;

    int maximum = 299;

     

    char c = '/';

    int position = strchr(oldname, c);

    string number = strsub(oldname, 1, position);

    int test = strtol(number);

    if ( (test >= minimum) && (test <= maximum) )

    // in range, do something

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to AnalogNotes

    Hi,

     

    I tried to put that new code to the old one. Not sure if it could work like that. That is what I tried:

     

    int minimum = 100;

    int maximum = 199;

     

    string sheetname;

    string message;

    string oldname;

    string newname;

    string lastpart;

    char c = '/';

    //int number = 100;

    //int position;

     

    schematic(S){

      S.sheets(SH){

           sprintf(sheetname, "Sheet: %d\n", SH.number);

           message += sheetname;

           SH.nets(N){

                oldname = N.name;

                     int position = strchr(oldname, c);

                     string number = strsub(oldname, 1, position);

                     int test = strtol(number);

                     if ( (test >= minimum) && (test <= maximum) )

                     // in range, do something

                     // position = strchr(oldname, c);

                     // lastpart = strsub(oldname, position);

                     // sprintf(newname, "W%d", number);

                     // newname += lastpart;

                     // number += 1;

                message += "Rename old: ";

                message += oldname;

                message += " to new: ";

                message += newname;

                message += "\n";

                }

           }

    }

    dlgMessageBox(message);

     

    Now the Message-Box shows me all nets like it did with the old code, but now only the nets matching the test criteria have the "Rename old:" at the beginning...and none of them have a new name after "to new:" somehow hard to explain...It looks like that:

     

    (...)

    Sheet: 4

    N$96 to new:

    N$97 to new:

    (...)

    Rename old: W190/50RD to new:

    Rename old: W191/50BK to new:

    (...)

     

    So I think something is wrong, but I have no Idea what.

     

    As for the regular expressions...thank you for your explanations, but I think I'll put that on hold until I have learned lesson 1 for beginners ;-)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • AnalogNotes
    0 AnalogNotes over 11 years ago in reply to Former Member

    Well, something I didn't tell you before...  "//" means that anything after this on a line is a comment.  A comment is something only for humans to read.  The computer (EAGLE) ignores everything in the comment.  There is another kind of comment too, a multi-line comment that starts with "/*" and ends with "*/".  For example:

     

    /*

    this is a comment and EAGLE will ignore everything in it

    */

     

    // this is also a comment, but it only lasts until the end of this one line.

     

    I'm going to try to use the Github Gist function for the ULP code.  I will do that in the next message...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • AnalogNotes
    0 AnalogNotes over 11 years ago in reply to AnalogNotes

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • AnalogNotes
    0 AnalogNotes over 11 years ago in reply to AnalogNotes

    Well, the gist looks very nice on the Element14 site, but it doesn't get through to NNTP.  image

     

    You can see what I posted at: https://gist.github.com/AnalogNotes/9377478

     

    At the top right of the code display is a button with "<>" on it.  That will let you view the "raw" code in a form that is very easy to copy and paste.  Let me know if that works for you...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to AnalogNotes

    Your code works perfectly, I'll check what is different and try to figure Out what didn't work with my code, unfortunately I'didnd have time to do that yet.

     

    As for the // I found out myself that they are used for comments...could have deleted these lines, but you know, because I don't really know what I am doing on a such script, I just start somewhere and try if it works or not. I then comment out one line, have a look what changed, comment out the next line, try again....
    Because of that I just comment out these lines, so if I need them again it is much faster to delete the // than to find and

    copy/paste the needed line.

    The commented out lines are basically your "old" script in what I copied the new part. I then commented these lines out because I tought they would basically do the same as the new ones...

     

    Gist GitHub: Because I use the Element14 Website instead of newsgroups, I didnt notice a problem with the code missing. What I noticed was that the code is not shown in the notification email, but this isn't a big problem for me. Copy and paste from the element14  website works peerfectly.
    Is there any concerns if I post the code directly on to the element14 website? Or why du you use GitHub?

     

    Thanks

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • AnalogNotes
    0 AnalogNotes over 11 years ago in reply to Former Member

    Ursicin Caminada wrote:

    Your code works perfectly, I'll check what is different and try to figure Out what didn't work with my code, unfortunately I'didnd have time to do that yet.

     

    As for the // I found out myself that they are used for comments...could have deleted these lines, but you know, because I don't really know what I am doing on a such script,

     

    I'm impressed, you are doing well!

     

    I just start somewhere and try if it works or not. I then comment out one line, have a look what changed, comment out the next line, try again....

     

    I think that's the best way to learn...

     

    Because of that I just comment out these lines, so if I need them again it is much faster to delete the // than to find and copy/paste the needed line.

     

    This is what "real" programmers do all the time.  image

     

    Gist GitHub: Because I use the Element14 Website instead of newsgroups, I didnt notice a problem with the code missing. What I noticed was that the code is not shown in the notification email, but this isn't a big problem for me. Copy and paste from the element14  website works peerfectly.
    Is there any concerns if I post the code directly on to the element14 website? Or why du you use GitHub?

     

    It was mostly an experiment.  When I paste code into a post on Element14, every line gets the same indentation, so I make a lot of changes in the editor here.  The Github Gist is nice because the indentation stays the way I created it, and the code is displayed with line numbers.  I could then explain things by line number.

     

    This forum is connected to the NNTP system and all of the posts are stored at the Eagle Central web site too.  Code doesn't transfer very well between them.  I think I will only post code directly here at Element14 in the future.

     

    I use Github and Bitbucket to store all of my programs and my EAGLE files.  That way I have a backup that is not on my own computer and they keep track of all of the changes I make to my files.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • AnalogNotes
    0 AnalogNotes over 11 years ago in reply to AnalogNotes

    OK, I did some testing on a schematic that I have here.  At first, I only had failures.  When I ran the script with the commands "name oldname newname", I got an error message "Unknown part".  I tried several different things, and finally sent a question to Cadsoft tech support.  Jorge pointed out that in the documentation for the name command, it says that "only parts, elements, pads, smds, pins and gates can be selected by their name using the old_name new_name syntax.  Nets, busses and signals have to be clicked first."  Oh no, that means we *have* to use a mouse click!

     

    Luckily, I had just learned something new that I could try.  You can read about it in another thread here on Element14: Re: How do I move/rotate values on a schematic?  I tested a couple commands using "name newname coordinates" by typing them on the command line in the schematic editor, and they worked!  So, then I just had to figure out where in the ULP to find the coordinates for the mouse click.  I looked in the help file, and found that nets have a segments() loop member and that segments have a wires() loop member and each wire has a start point (x1, y1).  Perfect!

     

    So here is the script:

     

    int minimum = 100;

    int maximum = 199;

    int newnumber = 100;

     

    string script = "grid inch;\n";

    string line;

    string oldname;

    string oldnumber;

    string newname;

    string lastpart;

    char c = '/';

    int position;

    int test;

     

    schematic(S){

      S.sheets(SH){

        sprintf(line, "edit .s%d;\n", SH.number);

        script += line;

        SH.nets(N){

          oldname = N.name;

          position = strchr(oldname, c);

          oldnumber = strsub(oldname, 1, position);

          test = strtol(oldnumber);

          if ( (test >= minimum) && (test <= maximum) ) {

            lastpart = strsub(oldname, position);

            sprintf(newname, "W%d", newnumber);

            newname += lastpart;

            N.segments(SEG)

              SEG.wires(W) {

                sprintf(line, " (%f %f);\n", u2inch(W.x1), u2inch(W.y1));

              }

            script += "name ";

            script += newname;

            script += line;

            newnumber += 1;

          }

        }

      }

      script += "edit .s1;\n";

      script += "grid last;\n";

      dlgMessageBox(script);

    }

    exit(script);

     

    I used the "grid inch" command to make sure I was working with the correct units to match the "u2inch" commands.  The "grid last" command near the bottom returns the grid setting to what it was before the script ran.  At the start of each schematic page loop, I add the command to the script to edit that page so that the mouse clicks match the parts on the correct page.  At the end, I put in the command "edit .s1" to return to the first page of the schematic.  The dlgMessageBox command shows you the script before it runs, and the very last line, "exit(script);" is what actually runs the script and makes the changes.  If you want to see what will run without making changes, comment out the exit line.  If you don't want the dialog box to show, you can comment out the dlgMessageBox line.

     

    Hopefully that works for you!  Let me know if you have any questions...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube