New ULP to measure distance between contacts from Board/Library editor  - Page 1
Forum section: electronics / general

author: YTusername
author_rank: Regular Contributor
timestamp: July 07, 2020, 01:28:22 am
content: HiMeasuring distance between footprint objects(lines, pads,smds,...etc) is not straight forward, as it needs to use the measurement tool and change grid to a fine grid size, or you need to get coordination of each object and do the distance measurement manually.I decided to make a new ULP to automate the process and show the distance between selected objects inside a group.https://github.com/yahyatawil/ContactsRuler/And here is an example of using the new ULP. What do you think of it ?

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: July 07, 2020, 07:15:14 pm
content: The standard ruler tool is a pain in the ass through Eagle.This would be a good tool to fix their problem, but it's not working in version 7. It gives an error 74.I can help you with the readme, here is an improvement to the English syntax in the .md file if you wish:# ContactsRulerThis ULP makes measuring distances between footprint contacts easierYou can use this in the Library and board editors## Usage in the Library editor:* Usingthe group tool, select any 2 of the following: pads, smds, holes and lines.* Run ContactsRuller.ulp* You will have the X and Y result difference in 3 different units: mm, mil and inch.Note: Don't select more than 2 objects in the group.## Usage in the Board editor:* Usingthe Group tool, select the part you want to measure, for the distance between its pads.* You will will then have a dialog with check box beside each contact name.* Select any 2 contacts.* Press OK. Next you will have a dialog with the difference in X and Y in 3 units: mm, mil and inch.Note: Don't select more than 1 part in the group, and don't check more than 2 boxes in the dialog screen.Sorry the animated picture runs too fast to grasp everything. Perhaps a YouTube video? No speaking is needed if you don't want to.

author: YTusername
author_rank: Regular Contributor
timestamp: July 07, 2020, 11:39:15 pm
content: Thanks for the incompatibility with Eagle version 7 feedback, I had to make a simple change to make it work. This is because Eagle team made a change of one of the used ulp functions from 9.1 version. Please try it now.However, I will add soon an icon to call the ulp from the toolbar directly, and maybe enhance a little the user experience especially for Library usage.Thanks for the Readme language check, I updated it.I will make a post on my blog soon, to explain usage, but I wanted to get feedback first before doing the post.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: July 07, 2020, 11:55:08 pm
content: The revised version works in the library, but it crashes Eagle in the board mode.

author: YTusername
author_rank: Regular Contributor
timestamp: July 08, 2020, 01:19:31 am
content: Hmmm .. what Eagle version exactly ? I tried with V7.1-light from board and library editors.Also, did you try it with different parts ? Could it be because of a bug in the ULP for a certain part ?

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: July 09, 2020, 06:56:53 pm
content: 7.3

author: jpanhalt
author_rank: Super Contributor
timestamp: July 09, 2020, 07:18:17 pm
content: I have ever needed that function, but one could simply draw a wire between the two pads (it starts and stops at the centers). Then click on the properties of that wire. Alternatively, just get the X-distance from the properties menu and do a subtraction.Eagle 7.2.0 and 7.7.0The latter may be what you are doing with the ULP, but unfortunately the demo started too soon for me to read it.Anyway, I can't see having too many ULP's even if I never use them.Thank you for that effort.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: July 09, 2020, 07:24:02 pm
content: That's how I have done it in the library editor for years now. It's just a few more steps to do. Then there's the not ready for prime time Kicad. One day when it is ready, (Crashes on Win 7 and Linux, 3 different machines) then I will invest in a learning curve. I've been using paid Eagle since the 3.xx days.Quote from: jpanhalt onTodayat 04:18:17

author: westfw
author_rank: Super Contributor
timestamp: July 10, 2020, 09:44:50 am
content: I usually just use the "mark" command and than watch the relative and/or polar coordiate display...

author: YTusername
author_rank: Regular Contributor
timestamp: July 11, 2020, 02:30:54 am
content: jpanhalt and westfw, thanks for you inputs, great tricks! There are many ways indeed to do the measurement, but I find it too much steps, especially that will need changing grid size usually. Maybe this ULP is useful for revising a board to check many footprints, without going back and forth between footprint and library editors, assuming that we have all components library.Quarl, I will look for it in 7.3 version.

author: jpanhalt
author_rank: Super Contributor
timestamp: July 11, 2020, 09:37:17 am
content: I do not know about versions after 8.0. One thing I would like in 7.x would be the ability to toggle between grid settings. One can, of course, set up keys to show grid settings and and to switch grid on and off, but changing the settings always requires keyboard entries.I didn't use to do that much, but as devices have gotten smaller and metric more common, I need to do it more and more, particularly when editing a library. What I would envision is simply setting up 2 grids, imperial and metric, then assigning a function key to toggle between them.The closest one can do now is to assign the alternate grid as metric, but then one loses the ability to switch between coarse and fine grids.

author: westfw
author_rank: Super Contributor
timestamp: July 12, 2020, 07:32:22 am
content: >QuoteYou know you can set up a GUI menu as well, right? I have one that doubles or halves the grid size, that I really like...

author: jpanhalt
author_rank: Super Contributor
timestamp: July 12, 2020, 09:24:46 am
content: I didn't know that. Is that capability in version 7.x? Where is it located?

author: YTusername
author_rank: Regular Contributor
timestamp: July 13, 2020, 03:57:42 am
content: You can set the grid settings, then save the setting by clicking on grid icon usingleftright mouse key and save it (from "New..."). The same applies to layer button (I used to use this trick in old Eagle version to switch fast between Top and Bottom layers while reviewing).What @westfw mentioned is to add buttons to tool bar using Eagle scripts. In the attachments a picture of a menu script example to add few buttons. You can duplicate the same example and add your own commands.BTW, in the past I gathered some of like tricks in series of article published on AllAboutCircuits, please have a check here:https://www.allaboutcircuits.com/technical-articles/eagle-cad-tips-and-tricks/

author: westfw
author_rank: Super Contributor
timestamp: July 13, 2020, 07:22:09 am
content: QuoteYeah, it goes way back to Version 4 - I'm stuck on a non-profit 7.x license, myself.)See "Help Menu", and you may have to check "Command Texts" in the Options/UserInterface panel.The customizability (scripts, ULPs, menus) of eagle is one of the major reasons I've been unmotivated to try KiCAD.

author: jpanhalt
author_rank: Super Contributor
timestamp: July 13, 2020, 07:23:43 am
content: As mentioned earlier, I use 7.x (mostly 7.2). Here is the Grid menu:There is no "new" button. I saw the AAC articles before. They relate to a new version. Of course one can use grid to set a dimension when drawing a complicated package or PCB outline. I simply use a regular CAD program, which is far simpler, and import it. Then with the command line or by grid settings, I get it centered. Usually the command line is easier to use, but doing it with grid setting is pretty intuitive and only a slightly longer process as you have to set each axis separately.I have been using Eagle for a long time and am comfortable with most of its capabilities. The use of a script for setting up a GUI is something I have not gotten into. I spent a fair bit of time on Google yesterday and every link pertaining to how to do that for older versions is broken or redirects to Autodesk. One comment, maybe by Jorge, suggests it is done with a "C-type language." That is as far as I got.

author: jpanhalt
author_rank: Super Contributor
timestamp: July 13, 2020, 07:58:59 am
content: Quote from: westfw on July 13, 2020, 07:22:09 amSorry, we cross posted. We have the same license. Mine is non-profit 7.x too. My experience with any high level language is virtually nil. I do not do C. All of my microcontroller work is in Assembly. I have done a little scripting with MPLab SIM, but that just a short list in notepad. I also do some simple command line entries in Eagle, but nothing I have tried to save as a ulp or scr.What I was looking for was a description of the Eagle script -- maybe a tutorial. The User's Manual for 7.3 (page 13) is way over my head.Would you be willing to share what you wrote for the grid that could be used as a model for modification?The only time I really use the grid as a tool is for designing a package and routing a PCB. For the package, grid changes are dependent on the package, and I am not too worried about having "1-click" changes. For the PCB, I find it convenient to have a regular and fine grid in both imperial and metric. It's relatively uncommon that I change any of those four settings. Being able to switch easily between imperial coarse/fine and metric coarse/fine would be an asset.Regards, John

author: YTusername
author_rank: Regular Contributor
timestamp: July 13, 2020, 08:34:08 am
content: Quote from: jpanhalt on July 13, 2020, 07:23:43 amSorry, I made a typo in the last reply. you can save the grid setting by clicking on grid icon usingrightmouse key and save it (from "New...").

author: jpanhalt
author_rank: Super Contributor
timestamp: July 13, 2020, 11:57:35 am
content: @YTusernameI got it to work and noticed an interesting quirk. I use classic icons. If I go to View, the grid icon works as shown in my previous post. There is no "new" or other option. But, if I go to the grid icon in the header, then a right click gives the options you show.Frankly, I hadn't even noticed that icon before as it with all the element14 stuff (e.g., BOM quote) that I wish I could remove and is identical to the icon in the dropdown.1) I set up Imperial and Metric grids.2) Assigned each to a function key (Options>Assign....>Change>Fn Grid Imperial, rinse and repeat for Metric).Now, I can simply select which grid to use with a single key stroke.Thanks to you both.PS: I would still like to see what the script looks looks like.John

author: jpanhalt
author_rank: Super Contributor
timestamp: July 13, 2020, 04:11:26 pm
content: Quote from: Quarlo Klobrigney on July 13, 2020, 02:22:36 pmTo what does your "it" refer. The grids I set up are 1 keystroke, e.g., F4 (special function) gives me one grind; F3 another. The alternate key while routing with either gives me the corresponding fine or alternate version.No problem saving them either.As for a restriction on the first character of a "name/identifier" being a numeral, that restriction is fairly common.

author: Quarlo Klobrigney
author_rank: Super Contributor
timestamp: July 13, 2020, 05:03:31 pm
content: I was speaking in terms of the grid icon and mouse functions. I can't use macro keys due to spies listening to the usual macro keys while I use other technical software. Nothing bad, just a PIA.I don't and won't use a scrolling mouse. It's trackball all the way. Nice for drawing without sliding off the mousepad.

author: westfw
author_rank: Super Contributor
timestamp: July 13, 2020, 08:55:45 pm
content: QuoteQuoteSo you already know that for any GUI action on your project can also be entered as a text command in the CLI window. That's a start.QuoteSure, I'll try. I don't know how far you'll get without C or other HLL experience.-EAGLE extensions are very "clever." Which is not at all the same as "elegant", but it does fit my personality.Everything is tied to the "cli commands."-The "menu" command lets you tie any text command to some menu buttons."initialization" scripts load at startup, and can distinguish between SCH/BRC/LBR...So, for example, in the schematic editor I added a menu that has my favorite parts, so I don't have to keep going to the ADD panel:Code:menu 'R {1/4 W TH : add R-US_0207/10 | \SMT1206: add R-US_R1206 \}' \'C: add C-US*' \'CPOL: add CPOL-US*' \'WIRE: add WIRE-via8@mylib4' \'GND: add gnd@supply1' \'VCC: add vcc@supply1' \;It ends up looking like:The syntax is a bit ugly, but relatively straightforward until you make your menus too deeply nested.-Since the menu buttons can have any EAGLE cli command, they can also invoke "Scripts" or "ULPs".A "script" (.scr file) is just a file with a bunch of EAGLE cli commands in it. It can "do things" to your project, but it does so "blindly", so it can't (for example) say "set the grid to half of its previous size" because while it has access to the "grid" command, it doesn't have any access to the old grid size.-"User Language Programs" are where you get to "C-like syntax." Essentially "C with strings, objects, and libraries", you get your standard programing constructs, plus the ability to pop up dialog boxes (ugly, again), plus read-only access to much of the data that makes up your board, schematics, and a fair amount of EAGLE internal data structures.To actually DO anything, a ULP generates a string or file that is a Script.For better or worse, there are MANY existing ULPs, and they're widely shared, so you can build up a useful menu that uses ULPs without actually having to write C-like code.-My Board "menu" looks like:Code:menu 'Layers {\Top : display NONE top torigins tKeepout tRestrict borigins pads vias dimension unrouted; | \Bottom : display NONE bottom borigins bKeepout bRestrict torigins pads vias dimension unrouted; | \All : display top bottom pads vias dimension unrouted tplace \torigins tnames tvalues bnames bvalues trestrict bplace borigins brestrict Document ?? Edit_history; | \NoNames : display -tnames -tvalues -bnames -bvalues; | \noDocu : display -tdocu -bdocu; | \AddDocu: display tdocu bdocu Document ?? Edit_History; | \SilkScreen: display NONE tplace -tvalues -tdocu dimension top tStop; \}' \'TogScreen : run toglays 21 22 25 26 27 28 51 52;' \'DrawOn {\Top : change layer top; | \Bottom : change layer bottom; | \tPlace : change layer tPlace; | \Dim : change layer Dimension; | \History: change layer History; \}' \'Grid {\Toggle : run gridhalf 1 t ; info | \Smaller : run gridhalf 0.5; move | \Bigger : run gridhalf 2; move | \OnOff : grid; move \}' \'Circle : run circle;' \'Count : run count;' \'DrlAid : run drill-aid;' \'RipPoly : ripup @;' \;Note "Count" and "DrlAid" which simply run the EAGLE-provided ULPs.The "Grid" menu (sub-menus Taggle, Smaller, Bigger) runs a ULP (gridhalf.ulp) I wrote with arguments that include a multiplier, and whether the units should change. The ULP reads the current grid info from the board data structures, multiplies it by the factor provided, constructs a new "grid NNmm" command (or whatever) and returns that string, which is executed as a script and changes the grid. There are some other complications associated with changing the units at the same time, but I don't remember exactly what they were :-(gridhalf.ulp looks like:Code:#usage "<qt><b>gridmult.ulp <mult> m|i|t""<p>Multiply the current grid setting by a factor.""<p>""<author>Author: Bill Westfield xxxxxx@xxxxxx</author></qt>"real griddistance;real multiplier = 1.0;string cmd = "";string units;string newgrid;UL_GRID oldgrid;char arg2;string gu2str (int unittype){switch (unittype) {case GRID_UNIT_MIC:return " mic";case GRID_UNIT_MM:return " mm";case GRID_UNIT_MIL:return " mil";case GRID_UNIT_INCH:return " inch";}}if (board) board(B) {oldgrid = B.grid;} else if (library) library(L) {oldgrid = L.grid;}if (argc > 0) {if (argc > 2) {if (oldgrid.unit == GRID_UNIT_INCH) {newgrid = "grid mm;";} else {newgrid = "grid inch;";}} else newgrid = "";multiplier = strtod(argv);griddistance = oldgrid.distance * multiplier;if (oldgrid.unit == oldgrid.unitdist) {/** original units still being used. No conversion necessary!*/sprintf(cmd, "grid %f;%s\n", griddistance, newgrid);exit(cmd);} else {/** We have to play with units. We could convert, but let's* switch the commands around instead (gives us compatibility* with the menus, hopefully!)*/sprintf(cmd, "grid %s; grid %f; grid %s;%s\n", gu2str(oldgrid.unitdist),griddistance, gu2str(oldgrid.unit), newgrid);exit(cmd);}}(look at that lovely comment about needing to "play with units" but not WHY. Sigh.)

author: jpanhalt
author_rank: Super Contributor
timestamp: July 13, 2020, 09:09:42 pm
content: Wow, that is so much more help than I had hoped for. I will definitely learn from it.John