Author Topic: When I run a lisp routine I get "error: too many arguments"  (Read 6129 times)

0 Members and 1 Guest are viewing this topic.

jtigrett

  • Guest
When I run a lisp routine I get "error: too many arguments"
« on: March 18, 2015, 04:39:58 AM »
When I try to run the lisp routine posted below I get the following in my command line: ; error: too many arguments.

To be clear I am very new at writing lisp routines. I have been, and am still in the process of, learning as much as I can from various websites and reference/help files published by AutoDesk. This being said when viewing the code below (yes, I am aware that it is quite possibly horrible and that even if it did run might not accomplish what I am after) my main concern is why am I getting the too many arguments error.

I am vaguely aware that it has something to do with the way I have constructed the lisp (almost like a script) but, although I am at the moment reading through the AutoCAD help files I haven't been able to quite understand where I went wrong.

And lastly, since anyone who might be willing to help will probably see the code below and wonder what in the world I am trying to accomplish... I have a large number of dxf files created from a 3d model that have to go out to the fabrication shop where I work. When the software I am using (Advance Steel) creates the dxf files it shows two views of the part and creates duplicates as well. Therefore I need to go into each drawing delete 3 views and keep one along with the mtext that shows the part number. And finally I have to mirror the part and then move on to the next drawing. I am trying to eliminate the time it takes to open each drawing and clean it up one by one. The reason I am using (entnext) is because every entity in the drawing aside from the one line of text is a polyline on the same layer, color, etc. I realize there is probably a better way to go about this and I would be delighted if someone could help but the main thing is to understand where I have gone wrong in my structuring of the code.

Thanks for any help that anyone can lend.

Code: [Select]
(defun c:DXFCleanup (/ ss1 e1 e2 e3)
(setq ss1 (ssget "X"))
(setq e1 (entnext))
(setq e2 (entnext e1))
(setq e3 (entnext e2))
(ssdel e2 e3 ss1)
(command ".erase" ss1 "")
(command "setvar" "mirrtext" "0")
(command "select" "all" "mirror" "0,0" "60,0" "y" "")
)

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: When I run a lisp routine I get "error: too many arguments"
« Reply #1 on: March 18, 2015, 04:50:55 AM »
The error you are encountering is because the ssdel function will only accept two arguments: an entity name and a selection set.

Hence, to remove entities e2 & e3 from your selection set, you will need to use two separate ssdel expressions:
Code - Auto/Visual Lisp: [Select]
  1. (ssdel e2 ss1)
  2. (ssdel e3 ss1)

You could also use the setvar function over the setvar command, i.e. this:
Code - Auto/Visual Lisp: [Select]
  1. (command "setvar" "mirrtext" "0")

Could become:
Code - Auto/Visual Lisp: [Select]
  1. (setvar 'mirrtext 0)


jtigrett

  • Guest
Re: When I run a lisp routine I get "error: too many arguments"
« Reply #2 on: March 18, 2015, 05:44:34 AM »
Lee,

Thanks so much for your quick and to-the-point answers.

By the way, your website is fantastic; it has been on my favorites bar for two years. I just wish I had more time to study!!

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: When I run a lisp routine I get "error: too many arguments"
« Reply #3 on: March 18, 2015, 06:16:32 AM »
Thanks so much for your quick and to-the-point answers.

My pleasure  :-)

By the way, your website is fantastic; it has been on my favorites bar for two years. I just wish I had more time to study!!

Wow - thank you! I feel honoured to have a place on your favourites bar  8-)

jtigrett

  • Guest
Re: When I run a lisp routine I get "error: too many arguments"
« Reply #4 on: March 19, 2015, 11:41:12 PM »
Ok, thanks to Lee my initial problem has been solved. Now for the follow up. The code that I posted is not working (big surprise right) and I am almost certain it is because, fundamentally, I don't quite grasp how to work with a selection set after it has been created. I feel quite sure that the difficulty I am having has already been addressed (in a tutorial, reference guide, or possibly even in this forum). I have done quite a bit of reading about selection sets over the last few days but when I have made it to the end of an article, tutorial, etc. either, it does not give specific examples of practical applications or, I am just missing something.

I am quite willing to look like a dunce if someone could just help me understand how I can retrieve and manipulate a selection set after I have created it. It would be ideal if someone could help me understand the concept in the context of my train-wreck of a lisp routine.


NICK_VNV

  • Newt
  • Posts: 63
Re: When I run a lisp routine I get "error: too many arguments"
« Reply #5 on: March 20, 2015, 08:25:03 AM »
Hi, here is an example for you showing how to change some properies of each entity in selection set (simplified for understanding)
Code - Auto/Visual Lisp: [Select]
  1. (setq ss (ssget "X"  (list  (cons 0 "text")(cons 8 "0") )))  ; make selection set ss (all texts in layer "0")
  2. (setq n (sslength ss))  ; n = number of entities in selection set ss
  3. (setq i 0)              ; i = counter for loop
  4. ; next loop will change some properies of each entity in selection:
  5.  (repeat n
  6.   (setq obj (vlax-EName->vla-Object (ssname ss i))); obj = vla-oject of i-entity from selection set ss
  7.   (vlax-put-property obj 'Height 3.0)                   ; change Height of text
  8.   (vlax-put-property obj 'ScaleFactor 0.75)             ; change ScaleFactor of text
  9.   (vlax-put-property obj 'Color 1)                      ; change Color of text to red
  10.   (vlax-invoke-method obj 'Highlight 1)                 ; Highlight this object
  11.   (setq i (1+ i))                                       ; increase counter and go for next entity
  12.  )
  13.  
You can use
Code - Auto/Visual Lisp: [Select]
  1. (vlax-dump-object (vlax-EName->vla-Object (car(entsel))) t)
to list all available properties and methods for selected object
« Last Edit: March 20, 2015, 08:30:45 AM by NICK_VNV »
Sorry for my English...

NICK_VNV

  • Newt
  • Posts: 63
Re: When I run a lisp routine I get "error: too many arguments"
« Reply #6 on: March 20, 2015, 08:44:38 AM »
Also use this to see which objects do you have in selection set ss:
Code - Auto/Visual Lisp: [Select]
  1. (sssetfirst nil ss)
Sorry for my English...

jtigrett

  • Guest
Re: When I run a lisp routine I get "error: too many arguments"
« Reply #7 on: March 20, 2015, 08:14:17 PM »
Thanks for the reply Nick.

I will make a go at it and I should be able to make a good start with the code you provided. As with all learning one thing always leads to another. I think I can focus in on the issue at hand more easily now. I had not given much thought to ActiveX - so once again... thanks.

jtigrett

  • Guest
Re: When I run a lisp routine I get "error: too many arguments"
« Reply #8 on: April 03, 2015, 12:47:02 PM »
I just wanted to thank Lee and Nick one more time. I am finally starting to get the hang of things. I am having great success putting into place some automated processes that are really benefiting my team.