element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Achievement Levels
    • Benefits of Membership
    • Feedback and Support
    • Members Area
    • Personal Blogs
    • What's New on element14
  • Learn
    Learn
    • eBooks
    • Learning Center
    • Learning Groups
    • STEM Academy
    • Webinars, Training and Events
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Arduino Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Project Groups
    • Raspberry Pi Projects
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Or 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
Autodesk EAGLE
  • Products
  • More
Autodesk EAGLE
EAGLE User Support (English) Make ULP exit in the Board window with a desired tool selected?
  • 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 Not Answered
  • Replies 10 replies
  • Subscribers 148 subscribers
  • Views 376 views
  • Users 0 members are here
Related

Make ULP exit in the Board window with a desired tool selected?

hbridge99
hbridge99 over 8 years ago

Hi EagleCAD support,

 

 

1) In a ulp or script, where does the program end up after  running the exit() script?

 

2) Is there some logic to this I am missing?

 

3) Is there a way in a ulp/script to return to the board (or schematic) window with a specified tool selected.

 

4) Can you point me to the very latest scripting and user language guides?

 

5 Is there a reason these guides are not in the docs folder?

 

hbridge99

  • Sign in to reply
  • Cancel

Top Replies

  • autodeskguest
    autodeskguest over 8 years ago in reply to hbridge99 +1
    On 20/06/2015 10:03 a.m., Paul Badger wrote: The window still doesn't activate though. Is there a way to change the focus to the board? It's really weird - it sets the tools correctly but without activating…
  • hbridge99
    hbridge99 over 8 years ago in reply to autodeskguest +1
    OSX 10.9.5 I notice other people are complaining about OSX graphics issues in 10.9, 10.10. Thanks for the help. I'm signing off this issue. In the grand scheme of all the things that are awkward, missing…
  • clem57
    0 clem57 over 8 years ago
    1. If exit(0), you end up where you were when you entered RUN.
    2. ???
    3. There is a special case for the exit( string). In this case the string is a command to execute in context of where you entered the RUN command usually the editor.
    4. Cannot find latest, but this should help User Language Program (ULP) Guide
    5. Well, good question.
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • autodeskguest
    0 autodeskguest over 8 years ago

    Paul Badger wrote on Fri, 19 June 2015 10:03

    Hi EagleCAD support,

     

     

    1) In a ulp or script, where does the program end up after  running

    the

    exit() script?

     

    2) Is there some logic to this I am missing?

     

    3) Is there a way in a ulp/script to return to the board (or

    schematic)

    window with a specified tool selected.

     

    4) Can you point me to the very latest scripting and user language

    guides?

     

    5 Is there a reason these guides are not in the docs folder?

     

    hbridge99

     

    --

    To view any images and attachments in this post, visit:

    http://www.element14.com/community/message/153052

     

     

    1. The script will run to its end if no problems are encountered. So it

    will end up where you code it to. If you want to start a ulp in the borad

    editor and end up in the schematic editor, for example, you can do that.

     

    2. Maybe missing knowledge.

     

    3. Sure, generally leaving the semi colon off the end of a command will

    keep that command active. End your ulp with exit("move") and the move

    command will be active.

     

    4. These are extracted from the HELP on occasions by Richard H so you don't

    need then really. They contain only the info that is in the HELP. A new

    version is only needed when a new Eagle version has had a change to the

    User Language. Check the release notes to get an indication of how often

    that happens

     

    5. Up to Cadsoft to decide if more is desirable there. Personally I would

    never use it but it may bring comfort to those starting out and feel they

    would like a pdf version of the User Language section  in the HELP.

     

    The best thing to do is study the simple examples that come with Eagle.

     

    All the best

    Warren

     

    --

    Web access to CadSoft support forums at www.eaglecentral.ca.  Where the CadSoft EAGLE community meets.

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • hbridge99
    0 hbridge99 over 8 years ago

    I'm probably remiss for not posting the ulp code.

    I've tried several versions of exit with no joy.

     

    It occured to me while thinking through this that

    maybe the issue is my dialog, which has closed, but that "space" may be where the ULP ends up now.

    I'm trying to get the ULP to do the script, then exit to the board from where it was called, selecting the MOVE tool.

     

    //======================================================

    // AlignD v0.2 based on Align v 1.0.3 by Danny Danhave

    //

    // Eagle v6.0 or later is required. Only the board editor is supported.

    //

    // Aligns board components in group or listed at the command line

    // The direction of alignment is autodetected. The components are aligned

    // after the origins of the top or leftmost component

    //

    // This software is released under the BSD 4-clause license:

    //

    // Copyright (c) 2010-2011, Damhave Systems

    // All rights reserved.

     

    // Modified 2010-05-21 LJW - Correct group coordinate determination & quote output script name on exit

    // Modified 2013-06-13 gh (IPG Automotive GmbH) - Adaptations to Eagle 6.x

    // Modified 2013-06-13 gh (IPG Automotive GmbH) - Original Part order is now kept, independant from Part Name!

     

    // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

     

    //    *    Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

    //    *    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer

    //         in the documentation and/or other materials provided with the distribution.

    //    *    Neither the name of the Damhave Systems nor the names of its contributors may be used to endorse or promote products derived from

    //        this software without specific prior written permission.

    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,

    // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS

    // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE

    // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,

    // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY

    // OF SUCH DAMAGE.

    //======================================================

    #usage    "<B>Aligns board components in group or listed in the components field</B>"

    "<P>"

        "Align components along a line parallel to the x or y axis of the board.<br>"

        "The direction of alignment is autodetected by looking at the position of the components. The alignment direction can also be forced.<br>"

        "<b>Options:</b>"

        /* Previous flags for reference "<b>blockquote>run alignd [*]<br>"

        //" The presence of a  flag causes the ULP to run without the dialog with the last options set.<br />"

        "<br /><h3>Options:</h3>"

        "d: Distribute components evenly between the outermost components<br>"

        "e: use regular Expressions (regex) instead of wildcards<br>"

        "g: align to Grid<br>"

        "h: Force alignment on a horizontal line<br>"

        "i: Increment position for each component by the specified value<br>"

        "o: align to reference Object<br>"

        "s: Snap to grid<br>"

        "k: Keep original part order if parts are already in the correct order but not aligned<br>"

        "v: Force alignment on a Vertical line"

        "<I>The components in the selection group are used when no components are specified at the command line.<br>"

        "The align to the bottommost/leftmost component flag -c is default set if no -g or -o flags are specified</I></blockquote>" */

        "<P>"

        "<b>Force Horizontal</b><br />"

        "   Forces horizontal alignment.<br />"

        "<b>Force Vertical</b><br>"

        "   Forces vertical alignment.<br />"

        "<b>Snap to Grid</b><br>"

        "   Forces components to nearest gridpoint. May be used with all other options.<br />"

        "<b>Align to Grid</b><br>"

        "   Aligns components on a horizontal or vertical gridline but not to gridpoints.<br />"

        "<b>Align to Reference Object</b><br>"

        "   Aligns component to a Reference Object. The reference object need not be selected or in the group selection.<br />"

        "<b>Component List</b><br>"

        "   A list of components to align, separated by spaces. Components need not be selected. \"*\" is a wildcard.<br />"

        "<b>Use Regular Expressions</b><br>"

        "   Uses regular expressions in the component list fields instead of asterisk wildcard.<br />"

        "<b>Distribute</b><br>"

        "   Equally distributes components between the first and last selected component.<br />"

        "<b>Increment</b><br>"

        "   Increments each component the amount shown in the field.<br />"

         "<P>"

        "AlignD Copyright (c) 2014 Paul Badger<br />"

        "Align ULN on which AlignD is based: Copyright (c) 2010-2011 Damhave Systems<br />"

     

        "<Author>Paul Badger & Danny Damhave<br>ModernDevice.com<br />"

        "Damhave Systems www.damhave.com</Author><br>"

        "This ulp is released under the BSD 4-clause license. See source code for details."

     

    enum {false, true};

    enum {ALIGN_ALONG_YAXIS, ALIGN_ALONG_XAXIS};

    enum {GROUP, LIST};

    string outputFileName = "aligntempfile.scr";

    string partlist[];

    int alignment, xRefObject = INT_MAX, yRefObject = INT_MAX, xAligned = INT_MAX, yAligned = INT_MAX, xMin = INT_MAX, xMax = INT_MIN, yMax = INT_MIN, yMin = INT_MAX, noElements = 0, mode = GROUP, firstInList = 1,

        alignToComponentFlag = false, keepFlag=false, alignToGridFlag = false, alignToObjectFlag = false, alignOnVerticalLine = false, alignOnHorizontalLine = false, regexFlag = false, snapFlag = false, distributeFlag = false, incrementFlag = false;

    real distance, increment, xAvg = 0.0, yAvg = 0.0;

     

    int Result = 0;

    // this is a file where param values are stored - params would be better in static memory but

    // that is not available to ULPs at this time

    string ULPfilename = path_ulp[0] + '/' + "AlignD.ULP.txt";

     

    // Checkboxes variables for the dialog

    int horizontal = 0, vertical = 0, dlgIncrement  = 0, distribute = 0, snapGrid  = 0, alignToGrid = 0, align = 0, keepInOrder = 0;

    int dlgRegEx = 0, alignToObject = 0, alignComponents = 0, flagsSet = 0, numberOfComponents, IncrementAmtInMils = 0;

     

    int DBbools[];

    string ObjectString = "";

    string ComponentText = "Components sep. by spaces";

    string ComponentList[];  // two dim text array (list)

    string boolParams = "000000000000000000";

    //string compParams = "Components sep. by spaces";

    string incrmntParm = "000000";

    string str_DBbools= "000000000000";

    string inString;

    string CompHistory[];  //history for component box

     

     

    // Align ULP 1.0.3 by Danny Damhave Damhave Systems www.damhave.com

    // Dialog box implementation by Paul Badger 2014

     

    void initParamFile(){

    int size = filesize(ULPfilename);

    if (!size){output(ULPfilename,"wt")

          printf("00000000000000000000");

          }

    }

     

    void saveParams(){     

    DBbools[0] = horizontal;

    DBbools[1] = vertical;

    DBbools[2] = snapGrid;

    DBbools[3] = alignToGrid;

    DBbools[4] = keepInOrder;

    DBbools[5] = alignToObject;

    DBbools[6] = alignComponents;

    DBbools[7] = dlgRegEx;

    DBbools[8] = dlgIncrement;

    DBbools[9] = distribute;

    DBbools[10] = 0; //unused

    DBbools[11] = 0; //unused

     

    for (int i = 0; i < 12; i++){

          if  (DBbools[i]) str_DBbools[i] = '1';

          else str_DBbools[i] = '0';

    }

     

    output(ULPfilename,"wt"){

          printf("Bools:%s\n", str_DBbools);

          printf("ObStr:%s\n", ObjectString);

          printf("CmpSt:%s\n", ComponentText);

          printf("IncMs:%d\n", IncrementAmtInMils);

        }

     

    }

     

    void help(void) {

      dlgDialog("HELP AlignD") {

        dlgLabel(usage);

        dlgHBoxLayout {

          dlgStretch(0);

          dlgPushButton("+OK") dlgAccept();

          dlgStretch(0);

        }

      };

    }

     

    void getParams(){

    int i = 0;

    string Sarray[];

    int nStrings = fileread(inString, ULPfilename);

    nStrings = strsplit(Sarray, inString, '\n');

     

    ObjectString = strsub(Sarray[1], 6, strlen(Sarray[1]));

    ComponentText = strsub(Sarray[2], 6, strlen(Sarray[2]));

    IncrementAmtInMils = strtol(strsub(Sarray[3], 6, strlen(Sarray[3])));

     

     

    //Parse out Boolean checkbox info

     

    horizontal =        Sarray[0][i++ + 6] - '0';

    vertical =          Sarray[0][i++ + 6] - '0';

    snapGrid =          Sarray[0][i++ + 6] - '0';

    alignToGrid =       Sarray[0][i++ + 6] - '0';

    keepInOrder =       Sarray[0][i++ + 6] - '0';

    alignToObject =     Sarray[0][i++ + 6] - '0';

    alignComponents =   Sarray[0][i++ + 6] - '0';

    dlgRegEx =          Sarray[0][i++ + 6] - '0';

    dlgIncrement =      Sarray[0][i++ + 6] - '0';

    distribute =        Sarray[0][i++ + 6] - '0';

    DBbools[9] =        Sarray[0][i++ + 6] - '0';

    DBbools[10] =       Sarray[0][i++ + 6] - '0';

    DBbools[11] =       Sarray[0][i++ + 6] - '0'; 

     

    }

     

    void dlgLogic(int selected){

    if (selected == 1){     //alignToGrid

    alignComponents = 0;

    alignToObject = 0;

    }

     

    if (selected == 2){     //alignToObject

    alignToGrid = 0;

    alignComponents = 0;

    }

     

    if (selected == 3){     //alignComponents

    alignToGrid = 0;

    alignToObject = 0;

    }

     

    dlgRedisplay();

    }

     

    // ULN begins here

     

     

    initParamFile();

    getParams();

    Result = dlgDialog("AlignD ULP") {

      dlgVBoxLayout {

         dlgStretch(0);

         dlgGroup("AlignD ULP by Paul Badger v0.2") {

            dlgStretch(1);

            dlgGridLayout {

             

               dlgCell(1, 1) {  dlgCheckBox("&Force Vertical", vertical) if (vertical) horizontal = 0; };

               dlgCell(2, 1) {  dlgCheckBox("&Force Horizontal", horizontal) if (horizontal) vertical = 0; };

               dlgCell(3, 1) {  dlgCheckBox("&Keep Parts In Order", keepInOrder); };

               dlgCell(4, 1) {  dlgCheckBox("&Snap to Grid ", snapGrid);  };

               dlgCell(5, 1) {  dlgCheckBox("&Align to Grid", alignToGrid) if (alignToGrid) dlgLogic(1); };                    

               dlgCell(6, 1) {  dlgCheckBox("&Reference Object to which to Align", alignToObject) if (alignToObject) dlgLogic(2); };

               dlgCell(7, 1) {  dlgStringEdit(ObjectString); };

               dlgCell(8, 1) {  dlgRadioButton("&Align Components in Group", alignComponents) if (alignComponents ) /*dlgLogic(3)*/; };

               dlgCell(9, 1) {  dlgRadioButton("&Align Components in List", alignComponents) if (alignComponents ) /*dlgLogic(3)*/ ;};

               dlgCell(10, 1){ dlgLabel("<font size=-1>Components separated by spaces. &quot;*&quot; is wildcard. </font>"); };

               dlgCell(11, 1){  dlgStringEdit(ComponentText); };

               dlgCell(12, 1){  dlgCheckBox("&Use Regular Expressions", dlgRegEx); };  

               dlgCell(13, 1){  dlgCheckBox("&Distribute", distribute) if (distribute) dlgIncrement = 0; };

               dlgCell(14, 1){  dlgCheckBox("&Increment (in mils)", dlgIncrement) if (dlgIncrement) distribute = 0; };

               dlgCell(15, 1){  dlgIntEdit(IncrementAmtInMils, -40000, 40000); }

               dlgRedisplay();

             }

              

          }

      

            dlgHBoxLayout {

                dlgPushButton("+OK"){

                saveParams();

                dlgAccept(1);          

                }

               dlgStretch(1);

               dlgSpacing(10);

            dlgPushButton("&HELP") help();

            dlgSpacing(10);

               dlgStretch(1);

               dlgPushButton("-CANCEL") dlgReject(-1);

               dlgStretch(0);

               }

      

              dlgStretch(0);

              dlgRedisplay();

           }

      };

     

    if (Result == -1){

    exit (0);

    }

     

    if (Result == 1){  // dialog exited with "OK"

    numberOfComponents = strsplit(ComponentList, ComponentText, ' ');   // parse out component list

     

    }

     

     

    // dialog box ends here

     

    int isMatch(string s, string test, int useRegex)

    {

    int j;

    //dlgMessageBox(s + ' ' + test + j++ );

     

     

        string regex = !useRegex ?  "^" : test;

        if (!useRegex)

        {

            for(int i = 0; test[i];)

            {

                switch(test[i])

                {

                    case '[': regex += strsub(test, i, strchr(test, ']', i) - i + 1), i += strchr(test, ']', i) - i + 1; break;

                    case '?': regex += ".", i++; break;

                    case '*': regex += ".*", i++; break;

                    case '+': case '^': case '$': case '.': case '{': case '}': case '(': case ')':  case '|': case '\\':

                    regex += "\\" + test[i], i++; break;

                    default: regex += test[i], i++;

                }

            }

            regex +='$';

        }

        return strxstr(s, regex, 0) == 0;

    }

     

     

     

    // argv is a list - two-dimensional text array

     

     

    int inList(string name)

    {

    //dlgMessageBox(name);

        for(int i = 0 /*firstInList*/; (i < numberOfComponents) && (ComponentList[i] != "")   /* argc && argv[i]  != ""*/ ; i++)

        {

            if (regexFlag)

            {

                if (isMatch(name, ComponentList[i] /*argv[i]*/ , regexFlag)) return true;

            }

            else

            {

                if (isMatch(strupr(name), strupr(ComponentList[i] /*argv[i]*/), regexFlag)){ /*dlgMessageBox("true");*/ return true; }

            }

        }

      //  dlgMessageBox("false");

        return false;

    }

     

    int snapToGrid(UL_BOARD brd, real coordinate)

    {

     

        real gSize;

        if (brd.grid.unitdist == GRID_UNIT_MIC) gSize = mic2u(brd.grid.distance);

        else if  (brd.grid.unitdist == GRID_UNIT_MM) gSize = mm2u(brd.grid.distance);

        else if  (brd.grid.unitdist == GRID_UNIT_MIL) gSize = mil2u(brd.grid.distance);

        else if  (brd.grid.unitdist == GRID_UNIT_INCH) gSize = inch2u(brd.grid.distance);

        // printf("# old coordinate=%f gSize=%f brd.grid.distance=%f\n", coordinate, gSize, brd.grid.distance);

        // printf("# new coordinate = %f mm2u=%d\n", (round (coordinate / gSize) * gSize), mm2u(1));

        return (round (coordinate / gSize) * gSize);

    }

     

    real input2u(UL_BOARD brd, real inputValue)

    {

        real convFactor;

        if (brd.grid.unitdist == GRID_UNIT_MIC) convFactor = mic2u(1);

        else if  (brd.grid.unitdist == GRID_UNIT_MM) convFactor = mm2u(1);

        else if  (brd.grid.unitdist == GRID_UNIT_MIL) convFactor = mil2u(1);

        else if  (brd.grid.unitdist == GRID_UNIT_INCH) convFactor = inch2u(1);

        return (round (inputValue * convFactor));

    }

     

     

     

    // Liste nach den Koordinatien sortieren, um ursprüngliche Reihenfolge beizubehalten

    int SortPartList (UL_BOARD brd, int nEls, int DirIsX, int reverse)

    {

        real coord[], c;

        int getauscht = 0;

        string t;

        int i, j;

     

        if (keepFlag == false) return 0;

     

        for (i=0; i < nEls; i++)

        {

        brd.elements(e1)

        {

            if (e1.name == partlist[i]) {

            coord[i] = (DirIsX==1) ? e1.x : e1.y;

            }

        }

        }

     

        do {

        getauscht = 0;

        for (i=0; i<nEls-1; i++)

        {

            j = i+1;

            if ((reverse == 0 && coord[i] > coord[j]) || (reverse == 1 && coord[i] < coord[j]))

            {

            getauscht = 1;

            t = partlist[i];

            partlist[i] = partlist[j];

            partlist[j] = t;

            c = coord[i];

            coord[i] = coord[j];

            coord[j] = c;

            // printf ("# Getauscht: %d=%s %d=%s\n", i, partlist[i], j, partlist[j]);

            }

        }

        } while (getauscht == 1);

     

        return 0;

    }

     

     

    //        ***** The ulp begins here *****

    if ((!board && !library ) && !dlgMessageBox("Can only be used in the board editor.\n")) exit(1);

    if (EAGLE_VERSION < 6 && !dlgMessageBox("Requires Eagle v5.7 or later.\n")) exit(1);

     

    // parse out dialog box attributes  the logic in the flag list below

    // and the "illegal flag test has been moved to the dialog box

            if (distribute) distributeFlag = true;

            if (dlgRegEx) regexFlag = true;

            if (horizontal) alignOnHorizontalLine = true;

            if (keepInOrder) keepFlag = true;

            if (dlgIncrement) incrementFlag = true;

            if (alignToGrid) { alignToGridFlag = true; }

            if (alignComponents)  alignToComponentFlag = true;

            if (alignToObject){ alignToObjectFlag = true; }

            if (snapGrid) snapFlag = true;

            if (vertical) alignOnVerticalLine = true;

     

             // this is kind of clunky - needed to trigger flag parsing below - PAB

             if ( distribute || dlgRegEx || horizontal || keepInOrder || keepInOrder || dlgIncrement || snapGrid || alignComponents || alignToObject || vertical){

              flagsSet = 1; }

                            

                       

    if (flagsSet)

    {

            /*for (int i = 1; flags[i]; i++)  // flags from original code - for reference

            {           

                switch (flags[i])

                {

                    case 'c' : alignToComponentFlag = true; break;

                    case 'd' : distributeFlag = true; break;

                    case 'e' : regexFlag = true; break;

                    case 'g' : alignToGridFlag = true; alignToComponentFlag = false; break;

                    case 'h' : alignOnHorizontalLine = true; break;

                    case 'k' : keepFlag = true; break;

                    case 'i' : incrementFlag = true; break;

                    case 'o' : alignToObjectFlag = true; alignToComponentFlag = false; break;

                    case 's' : snapFlag = true; break;

                    case 'v' : alignOnVerticalLine = true; break;

                    //default  : dlgMessageBox("No such flag.\n"); exit(3);

                }

            }  */

            firstInList++;  // what does this do? Pointer to flag?

            if (((alignOnHorizontalLine && alignOnVerticalLine) || (incrementFlag && distributeFlag) || (alignToGridFlag && alignToObjectFlag) || (alignToComponentFlag && alignToObjectFlag) || (alignToGridFlag && alignToComponentFlag)) && !dlgMessageBox("Illegal flag combination.\n")) exit(1);

            if (incrementFlag)

            {

                if (incrementFlag  && !(IncrementAmtInMils) && !dlgMessageBox("No increment specified.\n")) exit(1);

                board(brd) {

                  if (IncrementAmtInMils != 0) increment = input2u(brd,real(IncrementAmtInMils)); //PAB

                }

                  //firstInList++; 

            }

            if (alignToObjectFlag)

            {

                if (alignToObjectFlag  && (ObjectString == "")  && !dlgMessageBox("No object specified.\n")) exit(1);

                board(brd) { brd.elements(element) { if (element.name == ObjectString) xRefObject = element.x, yRefObject = element.y; } }

                if ((xRefObject == INT_MAX && yRefObject == INT_MAX) && !dlgMessageBox("No such object.\n")) exit(1);

                //firstInList++;

            }

        else;    // There are no flags therefore use the default align to bottommost/leftmost object in the direction with the most spread

    }

     

    if (alignToComponentFlag){

    mode = LIST; 

    }

    else{

       mode = GROUP;

    }

     

    board(brd)

    {

        int nEls = 0;

        int i;

     

        outputFileName = filedir(brd.name)+outputFileName;

        output(outputFileName, "wtD")

        {

        status("Aligning Objects...");

        brd.elements(element)

        {

            if ((mode == GROUP && ingroup(element)) || (mode == LIST && inList(element.name)))      //  inList(element.name))) 

            {

            noElements += 1;

            if (element.x < xMin) xMin = element.x;

            if (element.x > xMax) xMax = element.x;

            if (element.y < yMin) yMin = element.y;

            if (element.y > yMax) yMax = element.y;

            xAvg += element.x;

            yAvg += element.y;

            partlist[nEls] = element.name;

            nEls ++;

            }

        }

     

        if ((noElements < 2) && !dlgMessageBox("Minimum 2 objects in group/list required.\n")) exit(1);

        xAvg = xAvg / noElements;

        yAvg = yAvg / noElements;

     

        if (alignOnHorizontalLine) alignment = ALIGN_ALONG_XAXIS;                                    // Alignment in X direction forced by -h flag ?

        else if (alignOnVerticalLine) alignment = ALIGN_ALONG_YAXIS;                                // Alignment in Y direction forced by -v flag ?

        else alignment = ((xAvg - xMin) > (yMax - yAvg)) ? ALIGN_ALONG_XAXIS : ALIGN_ALONG_YAXIS;    // Alignment autodetected on basis of spread

     

        if (alignment == ALIGN_ALONG_YAXIS)

        {

            if (alignToObjectFlag) xAligned = xRefObject;                                            // Align on a vertical line going through the reference object ?

            else brd.elements(element)                                                                // Align on a vertical line going through to the leftmost bottommost object

            {

            if ((mode == GROUP && ingroup(element)) || (mode == LIST && inList(element.name)))   //inList(element.name)))

            {

                if (element.y == yMin) xAligned = (snapFlag || alignToGridFlag) ? snapToGrid(brd, element.x) : ((element.x < xAligned) ? element.x : xAligned);

            }

            }

            if (distributeFlag)

                distance = (yMax - yMin)/(noElements-1);

            else if (incrementFlag)

                distance = increment;

            SortPartList (brd, nEls, 0, 0);

        }

        else

        {

            if (alignToObjectFlag) yAligned = yRefObject;            // Align on a horizontal line going through the reference object ?

            else brd.elements(element)                                // Align on a horizontal line going through to the leftmost bottommost object

            {

            if ((mode == GROUP && ingroup(element)) || (mode == LIST && inList(element.name)))               //inList(element.name)))

            {

                if (element.x == xMin) yAligned = (snapFlag || alignToGridFlag) ? snapToGrid(brd, element.y) : ((element.y < yAligned) ? element.y : yAligned);

            }

            }

            if (distributeFlag)

                distance = (xMax - xMin)/(noElements-1);

            else if (incrementFlag)

                distance = increment;

            SortPartList (brd, nEls, 1, 0);

        }

     

     

        int n = 0, totalDistance;

        for (i=0; i<nEls; i++) {

            brd.elements(element)

            {

            if (element.name == partlist[i])

            {

                if (distributeFlag || incrementFlag)

                {

                    totalDistance = ((alignment == ALIGN_ALONG_YAXIS) ? yMin : xMin) + distance * n;

     

                    if (alignment == ALIGN_ALONG_YAXIS)

                    yAligned = (snapFlag || alignToGridFlag) ? snapToGrid(brd, totalDistance) : totalDistance;

                    else

                    xAligned = (snapFlag || alignToGridFlag) ? snapToGrid(brd, totalDistance) : totalDistance;

                    printf("MOVE %s (%fmm %fmm)\n", element.name, u2mm(xAligned), u2mm(yAligned));

                    n++;

                }

                else

                {

                    if (alignment == ALIGN_ALONG_YAXIS)

                    printf("MOVE %s (%fmm %fmm)\n", element.name, u2mm(xAligned), u2mm(snapFlag ? snapToGrid(brd, element.y) : element.y));

                    else

                    printf("MOVE %s (%fmm %fmm)\n", element.name, u2mm(snapFlag ? snapToGrid(brd, element.x) : element.x), u2mm(yAligned));

                }

            }

            }

        }

        }

    }

     

    exit("script '" + outputFileName + "'");

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • autodeskguest
    0 autodeskguest over 8 years ago in reply to hbridge99

    On 20/06/2015 4:00 a.m., Paul Badger wrote:

    I'm probably remiss for not posting the ulp code.

    I've tried several versions of exit with no joy.

     

    It occured to me while thinking through this that

    maybe the issue is my dialog, which has closed, but that "space" may be

    where the ULP ends up now.

    I'm trying to get the ULP to do the script, then exit to the board from

    where it was called, selecting the MOVE tool.

     

     

    You should have said this was alignd.ulp which you had previously

    uploaded to the Cadsoft ULP downloads pages.

     

    exit("script '" + outputFileName + "'; move");

     

    HTH

    Warren

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • hbridge99
    0 hbridge99 over 8 years ago in reply to autodeskguest

    Thanks for the help Warren,

     

    It would have been many years of trial and error ...

     

    exit("script '" + outputFileName + "'; move");

     

    Paul

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • hbridge99
    0 hbridge99 over 8 years ago in reply to hbridge99

    The window still doesn't activate though.

     

    Is there a way to change the focus to the board? It's really weird - it sets the tools correctly but without activating the window, which then requires another click.

     

    no joy with this

    exit("script '" + outputFileName + "'; board; move; group");

     

    throws error "board command can only be used in a schematic"

     

    FWIW - There doesn't seem to be a "schematic" command?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • autodeskguest
    0 autodeskguest over 8 years ago in reply to hbridge99

    On 20/06/2015 10:03 a.m., Paul Badger wrote:

    The window still doesn't activate though.

     

    Is there a way to change the focus to the board? It's really weird - it

    sets the tools correctly but without activating the window, which then

    requires another click.

     

    no joy with this

    exit("script '" + outputFileName + "'; board; move; group");

     

    throws error "board command can only be used in a schematic"

     

    FWIW - There doesn't seem to be a "schematic" command?

     

    --

    To view any images and attachments in this post, visit:

    http://www.element14.com/community/message/153182

     

     

     

    I think you should explain fully what you are doing step by step,

    stating which editor you run the ulp from and where you want to be when

    the ulp finishes. Have you one problem you are trying to solve are you

    moving through a number of them? Is it all to do with running alignd.ulp

    or is there another in play?

     

    The information I provided earlier works for the information you

    provided. alignd.ulp only works in the board editor so as it is now it

    ends in the board editor. My information let you end in the board editor

    with the move command active.

     

    If you want to finish in the schematic with the move command active, you

    need to exit the ulp with commands to do that. Remember, a ulp can  only

    influences your design by doing exactly the same commands as you can

    enter into the command line so review "Editor commands" in the HELP and

    you will find what you need in the command "Edit'

     

    All the best

    Warren

     

     

     

     

     

     

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • hbridge99
    0 hbridge99 over 8 years ago in reply to autodeskguest

    Here's an overview of what I am trying to do.

     

    I would like to run my ULP AlignD which only works from the board context - although of course I'd like it to work from other contexts but that's another story.

     

    I would them like the ULP to return to the board with the group tool selected, ready to make another selection and continue lining things up.

    For some reason the window doesn't activate when the ULP returns. None of the other Eagle windows have focus either.

    One hypothesis is that the dialog window (which has closed) still has the focus (so basically nothing has the focus?).

    It may be way off base.

     

    I'm trying to avoid some the endless mouse clicks of Eagle. In the grand scheme of things there are already so many extra mouse clicks ...

    I would just like not to contribute to more extra mouse clicks.

     

    And I'd like my ULP to at least be as fluid as possible in trying to remediate some of the missing functionality in Eagle.

    If it can't happen then as I said above, no one will likely notice a few more mouse clicks.

     

    Years ago I wrote some plugins for Photoshop. It was really exemplary what Adobe gave users / developers in working with photoshop.

    Basically one could manipulate any of the image buffers from within the plugin structure. I'd like to see CadSoft go in that direction.

     

    Paul

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • autodeskguest
    0 autodeskguest over 8 years ago in reply to hbridge99

    On 06/20/2015 12:07 AM, Paul Badger wrote:

    One hypothesis is that the dialog window (which has closed) still has

    the focus (so basically nothing has the focus?).

    It may be way off base.

    I did not notice what OS and which version you are using. Under Linux

    window manager and graphics driver can cause focus issues.

    Paul

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • hbridge99
    0 hbridge99 over 8 years ago in reply to autodeskguest

    OSX  10.9.5 

     

    I notice other people are complaining about OSX graphics issues in 10.9, 10.10.

    Thanks for the help. I'm signing off this  issue. In the grand scheme of all the things that are awkward, missing and broken with the Eagle GUI,

    spending time on another mouse click is probably not that productive.

     

    Paul

    • Cancel
    • Vote Up +1 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 © 2023 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