Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Active Contributor
pfilters
Posts: 28
Registered: ‎05-30-2006
Message 1 of 8 (264 Views)

LISP based on variables defined in the LISP file

264 Views, 7 Replies
06-11-2012 12:20 PM

I have a very limited amount of knowledge and experience in creating LISP routines, but i have been able to get by.

 

Every two weeks, I print out a time sheet (attached) for each of our employees showing the current pay period dates which is manually filled out by the employee with hours worked.  I have to manually edit the name on the time sheet and print it out for every person.  i developed the attached LISP to speed up the process and it works great.  What i would like to do is have a list of variables in the LISP file, one for each employee name, and have the routine reference the variables so i can more easily manage personnel changes by adding or subtracting the variables in the list.  

 

this is way beyond my capabilties.  can anyone help me do this?  i asuume the LISP could be setup to run for n amount of variables and know that it's finished when it reaches the end of the list so all i have to do is maintain the list and not edit the code.

*Expert Elite*
Kent1Cooper
Posts: 5,600
Registered: ‎09-13-2004
Message 2 of 8 (260 Views)

Re: LISP based on variables defined in the LISP file

06-11-2012 12:37 PM in reply to: pfilters

pfilters wrote:

.... 

Every two weeks, I print out a time sheet (attached) for each of our employees showing the current pay period dates which is manually filled out by the employee with hours worked.  ....  What i would like to do is have a list of variables in the LISP file, one for each employee name, and have the routine reference the variables so i can more easily manage personnel changes by adding or subtracting the variables in the list.

....


CAD doesn't seem like the best way to go about this.  Could you do it as a word-processor document instead, and use a feature such as what I believe some word processors call Mail Merge?  I think that kind of thing is specifically designed to do this kind of thing.
 

But if you want to stick with the .DWG approach, you could probably do something like this, using not variables but just a list of names [untested]:

 

(foreach x '("LYNN" "ANTHONY" "CHRIS" "TIM" "BRAD")

  (command "-attedit" "n" "n" "header" "employee" "*" "-" x "-plot" "" "" "" "" "" "" "" "_u")

); foreach

 

The undo at the end should set the value back to - after the iteration for each name, so you don't need to look for a different current value each time.

 

Then you could just add or remove names from that employee names list as needed.

Kent Cooper
Active Contributor
pfilters
Posts: 28
Registered: ‎05-30-2006
Message 3 of 8 (247 Views)

Re: LISP based on variables defined in the LISP file

06-11-2012 02:10 PM in reply to: Kent1Cooper

Thanks.  i had to make the following changes, though:

 

(defun c:tc ()

(foreach x '("LYNN" "ANTHONY" "CHRIS" "TIM" "BRAD")

  (command "-attedit" "n" "n" "header" "employee" "*" "-" x "-plot" "" "" "" "" "" "" "" "_u" "_u")

))

 

the first undo only undid the plot, so i added another. i also added a parentheses at the end to counter the one prior to "defun".  Lastly, I removed the "; foreach" from the end because i didnt understand it, and it works without it.

 

I'll admit, it took me a while to understand how this all fit together with the "(defun c:tc ()" portion missing from your explanation.  i actually had it running as soon as the drawing opened for a while there.  Neat, but not practical.

 

Anyway, this was exactly what i was looking for.  i'd never heard of the "foreach" function.  I'll try to use it in another LISP sometime.  Thanks so much.  

*Expert Elite*
Kent1Cooper
Posts: 5,600
Registered: ‎09-13-2004
Message 4 of 8 (244 Views)

Re: LISP based on variables defined in the LISP file

06-11-2012 02:49 PM in reply to: pfilters

pfilters wrote:

Thanks.  i had to make the following changes, though:

 

(defun c:tc ()

(foreach x '("LYNN" "ANTHONY" "CHRIS" "TIM" "BRAD")

  (command "-attedit" "n" "n" "header" "employee" "*" "-" x "-plot" "" "" "" "" "" "" "" "_u" "_u")

))

 

the first undo only undid the plot, so i added another. i also added a parentheses at the end to counter the one prior to "defun".  Lastly, I removed the "; foreach" from the end because i didnt understand it, and it works without it.

.... 


Ah, of course -- I didn't have an undo in there for both the Plot and the Attedit, as of course you would need.  The "; foreach" was just there to identify that the right parenthesis it follows is the closing one for the (foreach) function -- some people would [and I generally used to, until recently]  say "; end foreach" to make that more explicit, but I've taken to omitting the word "end" lately.  And in a shorter function like this, it's not as important to identify what a closing parenthesis is closing -- it means more when you have a long series of nested functions.  But yes, it certainly will work without it -- anything following a semicolon is just commentary, which has no operational effect.

Kent Cooper
*Expert Elite*
scot-65
Posts: 2,189
Registered: ‎12-11-2003
Message 5 of 8 (241 Views)

Re: LISP based on variables defined in the LISP file

06-11-2012 03:30 PM in reply to: pfilters

Give this some thought in taking your routine to the next level:

 

Create a dialog interface using list_box to display the employee names.

Add buttons along the bottom to "Add", "Remove", "Sort", and "Print".

 

Above the list_box, use popup_lists for the month, day, and year for "From" and "Thru".

 

The print button would be the "Accept" trigger that would only be pressed once.

 

Here's something similar I developed not too long ago, given this same general idea:

 

PNotes01.gif

 

THIS IS WHAT YOU ARE LOOKING FOR:

Data storage in the form of a LIST inside the Dictionary.

Access using VLAX-LDATA-GET.

Then do the FOREACH...

 

:-)

Scot-65
Dyslexia is a permanent physical disability that cannot be seen.
Introverts is proof that there is indeed intelligent life on this planet.
*Expert Elite*
pbejse
Posts: 2,500
Registered: ‎11-24-2009
Message 6 of 8 (226 Views)

Re: LISP based on variables defined in the LISP file

06-11-2012 10:03 PM in reply to: scot-65

scot-65 wrote:

 Here's something similar I developed not too long ago, given this same general idea:

 

 

Data storage in the form of a LIST inside the Dictionary.

Access using VLAX-LDATA-GET.

Then do the FOREACH...

 

:-)


Nice Idea scot-65.

*Expert Elite*
dbroad
Posts: 1,601
Registered: ‎08-16-2007
Message 7 of 8 (206 Views)

Re: LISP based on variables defined in the LISP file

06-12-2012 05:23 AM in reply to: pfilters

I had a similar system about 15 years ago before I switched to using spreadsheets to manage this task.  The spreadsheet option has been much easier to implement and manage and has worked very nicely.  I can log out and in of any project quickly, annotate what I did and automate bill production.  A database solution would probably have been better.  If I was thinking about changing systems now however, I would think about using an out-of-the-box solution like Quick Books. Waste of time to do this stuff in drawings with lisps IMO.

 

Good luck.

*Expert Elite*
scot-65
Posts: 2,189
Registered: ‎12-11-2003
Message 8 of 8 (185 Views)

Re: LISP based on variables defined in the LISP file

06-12-2012 03:17 PM in reply to: pfilters

Here's something I put together this morning - maybe a total of one hour spent on it.

There is still a little more *inside* work that is needed to get it to a point where you

will be able to incorporate what you have now to make it work.

 

Test03.gif

 

I personally don't like to see command UNDO inside LISP.

Instead of ATTEDIT, Start with -INSERT, then -PLOT, then Erase (entlast).

And (setvar "ATTDIA" 0) is required here.

 

:-)

Scot-65
Dyslexia is a permanent physical disability that cannot be seen.
Introverts is proof that there is indeed intelligent life on this planet.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.