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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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) ULP: Create reliable temp filename for scripts
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Autodesk EAGLE to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 19 replies
  • Subscribers 182 subscribers
  • Views 2323 views
  • Users 0 members are here
  • ulp
  • mac
Related

ULP: Create reliable temp filename for scripts

Former Member
Former Member over 12 years ago

Hello,

as far as I understand, the only way to manipulate the data structure of either an eagle schematic, board or library through an ULP is to collect the necessary commands in a text file and execute it using exit ("script <filename>"). This method works as long as there is a suitable filename available that is writeable. On a unix system, this would be somewhere in /tmp, on windows, this would be some other location. I have failed so far to find a way to create a temporary filename that works across all supported operating systems. I suggest to add a function to create a temporary path for exactly that purpose and to document it together with the whole approach of collecting commands to manipulate the data structure in a script and execute that script after the ULP is finished. This would have the other advantage that the script could get deleted after execution because it is intended for a single execution anyway.

 

What do you think about this? Does anyone has a realiable solution to create a temporary filename? I think the currently most used approach is to place the script into the same directory as the currently edited schematic or library. This works because the user usually has the rights to write to the directory of the currently edited file. But I think this is a hack because the file remains after execution and does not belong there. Another interesting idea would be to have a magic filename, for example ":memory" so the commands get stored somewhere in memory, exeuted and never become an object in the users filesystem.

  • Sign in to reply
  • Cancel
Parents
  • dukepro
    0 dukepro over 12 years ago

    On 06/20/2013 09:06 AM, Axel Jäger wrote:

    Hello,

    as far as I understand, the only way to manipulate the data structure of

    either an eagle schematic, board or library through an ULP is to collect

    the necessary commands in a text file and execute it using exit ("script

    <filename>").

     

    Axel,

     

    Rather than collecting commands into a file, collect them into a string

    then pass the string as the single argument to exit().

     

        string cmd = "";

     

        cmd += "display all;\n";    // display all layers

        cmd += "group all;\n";      // Group all objects

        cmd += "lock (CS> 0 0);\n"; // Unlock everything.

        cmd += "display last;\n";   // restore the original display

        ... add more useful commands to cmd

        exit(cmd);

     

    No files are used here.

     

    HTH,

        - Chuck

     

     

    Attachments:
    2234.att1.html.zip
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to dukepro

    Chuck: THIS is the solution, many thanks.

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

    Axel Jäger wrote:

    Chuck: THIS is the solution, many thanks.

     

    --

     

    Chuck's solution is used often but is slow when you perform many cmd +=

    Concatenating strings in a ULP is slow.

     

    When that becomes and issue you can have your ULP create your script file in

    the directory of the current  editor file you have open. You  know you can

    write to that place.

    You create the file using  open ("text file",wtD) so that that file is

    deleted when Eagle is closed. Hence the file is temporary.

     

    I think that covers your needs

     

    Warren

     

     

    --

    Viewed / responded via the newsgroup at

    news.cadsoft.de

     

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • k.portman
    0 k.portman over 12 years ago in reply to autodeskguest

    Chuck's solution is used often but is slow when you perform many cmd +=

    Concatenating strings in a ULP is slow.

     

    Well, don't use string concatenation. Collect all the commands in a

    string array and only as last step do the concatenation with strjoin().

    Another benefit is you can use sprintf() and generate complex command

    strings much easier. See the code below.

     

    Kim

     

    ====================================

    int ns;          //define counter

    string scr[];     //define cmd array

     

    //insert simple command/s

    scr[ns++] = "set undo_log off; set confirm yes;";

     

    //insert complex commands

    sprintf(scr[ns++], "edit %s.brd;", name);

    sprintf(scr[ns++], "text '%s' %s%sR%f (%fmm %fmm);", t[i].value, spin,

    mirr, t[i].angle, u2mm(t[i].x), u2mm(t[i].y));

     

    //concatenate array->string

    string cmd = strjoin(scr,' ');

     

    //exit and execute the script

    exit(cmd);

    ====================================

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • dukepro
    0 dukepro over 12 years ago in reply to k.portman

    Kim,

     

    I like that even better.  I am aware of the inefficiencies of doing

    multiple string concatenations.  Underneath the covers, I assume that

    each concatination does a strlen() on both strings to determine the

    memory required, then copies both strings to the newly allocated space.

    So the cost goes up with the number and length of the strings exponentially.

     

    strjoin(), however, looks like it can scan all the strings once to

    determine memory requirements, then copying each string into the

    allocated space.  So the cost is at worst 2n - more of a linear increase

    in cost.  Much more CPU friendly than successive concatenations.

     

    Thanks for pointing out a better method.  I'll put it to good use.

     

        - Chuck

     

    On 06/21/2013 08:52 AM, KimP wrote:

    Chuck's solution is used often but is slow when you perform many cmd +=

    Concatenating strings in a ULP is slow.

     

    Well, don't use string concatenation. Collect all the commands in a

    string array and only as last step do the concatenation with

    strjoin(). Another benefit is you can use sprintf() and generate

    complex command strings much easier. See the code below.

     

    Kim

     

    ====================================

    int ns;        //define counter

    string scr[];    //define cmd array

     

    //insert simple command/s

    scr[ns++] = "set undo_log off; set confirm yes;";

     

    //insert complex commands

    sprintf(scr[ns++], "edit %s.brd;", name);

    sprintf(scr[ns++], "text '%s' %s%sR%f (%fmm %fmm);", t[i].value, spin,

    mirr, t[i].angle, u2mm(t[i].x), u2mm(t[i].y));

     

    //concatenate array->string

    string cmd = strjoin(scr,' ');

     

    //exit and execute the script

    exit(cmd);

    ====================================

     

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • dukepro
    0 dukepro over 12 years ago in reply to k.portman

    Kim,

     

    I like that even better.  I am aware of the inefficiencies of doing

    multiple string concatenations.  Underneath the covers, I assume that

    each concatination does a strlen() on both strings to determine the

    memory required, then copies both strings to the newly allocated space.

    So the cost goes up with the number and length of the strings exponentially.

     

    strjoin(), however, looks like it can scan all the strings once to

    determine memory requirements, then copying each string into the

    allocated space.  So the cost is at worst 2n - more of a linear increase

    in cost.  Much more CPU friendly than successive concatenations.

     

    Thanks for pointing out a better method.  I'll put it to good use.

     

        - Chuck

     

    On 06/21/2013 08:52 AM, KimP wrote:

    Chuck's solution is used often but is slow when you perform many cmd +=

    Concatenating strings in a ULP is slow.

     

    Well, don't use string concatenation. Collect all the commands in a

    string array and only as last step do the concatenation with

    strjoin(). Another benefit is you can use sprintf() and generate

    complex command strings much easier. See the code below.

     

    Kim

     

    ====================================

    int ns;        //define counter

    string scr[];    //define cmd array

     

    //insert simple command/s

    scr[ns++] = "set undo_log off; set confirm yes;";

     

    //insert complex commands

    sprintf(scr[ns++], "edit %s.brd;", name);

    sprintf(scr[ns++], "text '%s' %s%sR%f (%fmm %fmm);", t[i].value, spin,

    mirr, t[i].angle, u2mm(t[i].x), u2mm(t[i].y));

     

    //concatenate array->string

    string cmd = strjoin(scr,' ');

     

    //exit and execute the script

    exit(cmd);

    ====================================

     

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
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