Calling a lisp routine with an argument from command line or menu/button.

Calling a lisp routine with an argument from command line or menu/button.

PDACTL
Enthusiast Enthusiast
1,814 Views
5 Replies
Message 1 of 6

Calling a lisp routine with an argument from command line or menu/button.

PDACTL
Enthusiast
Enthusiast

I have a series of lisp functions for layer manipulation in the form:

(defun c:YY_LAYnn ()
  ;do stuff here with LAYnn
)

where the code is identical but for the layer name.

 

I would like a single generic function where the layer name is passed as an argument, like so:

(defun c:YY ( LAYnn )
  ;do stuff here with LAYnn
)


How would I invoke this from the command line or toolbar button?

0 Likes
Accepted solutions (1)
1,815 Views
5 Replies
Replies (5)
Message 2 of 6

cadffm
Consultant
Consultant

hi

 

it isn't usefull to use a name starting with "c:", starting with "c:" defines an AutoCAD-command call for functions without arguments.

(it also works with a c: like "c:myfunc" but you can not use them as AutoCAD-Command, so get rid of the "c:" part)

 

(defun YY ( LAYnn )
;do stuff here with LAYnn
)


>>"How would I invoke this from the command line or toolbar button?"

(YY "MyLayerName")

 

 

Sebastian

0 Likes
Message 3 of 6

PDACTL
Enthusiast
Enthusiast

That sorted it. Thank you!

I now have a different syntax problem.

In the following situation where entities have their linetypes amended...

 

(defun ChangeLinetype( nnn )
(IF (/= nil (SETQ EN (SSGET)))
(PROGN
(SETQ C 0)
(WHILE (< C (SSLENGTH EN))
(PROGN
(entmod (append (ENTGET (SSNAME EN C)) '((6 . "GHOST"))))
(SETQ C (+ C 1))
)
)
)
)
)


I want to replace "GHOST" with whatever the argument nnn is.

How do I do this?

0 Likes
Message 4 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

If it could be loaded from the default *.lin.

 

(defun ChangeLinetype ( nnn / s i)

  (or (tblsearch "ltype" nnn)
      (command "_.-LINETYPE" "_L" nnn "" "")
      
  (if (setq s (ssget "_:L"))
    (repeat (setq i (sslength s))
      (entmod (append (entget (ssname s (setq i (1- i)))) (list (cons 6 nnn))))))
  (princ)
  )

 

0 Likes
Message 5 of 6

PDACTL
Enthusiast
Enthusiast

@ВeekeeCZ wrote:

If it could be loaded from the default *.lin.

 

(list (cons 6 nnn))

 


This was the bit I needed. Thanks.

0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

Expanding the beekeecz solution, the multi getvals.lsp could be used as it will allow one entry and is only a few line of code as the core code is loaded as required.

 

SeaHaven_0-1651194165149.png

 

 

 

 

(defun c:ChangeLinetype ( / s i nnn)
(if (not AH:getvalsm)(load "Multi Getvals.lsp"))
(setq nnn (car (AH:getvalsm (list "Enter layer " "Layer " 20 19  "Continuous"))))
  (or (tblsearch "ltype" nnn)
      (command "_.-LINETYPE" "_L" nnn "" "")   
  (if (setq s (ssget "_:L"))
    (repeat (setq i (sslength s))
      (entmod (append (entget (ssname s (setq i (1- i)))) (list (cons 6 nnn))))))
  (princ)
  )
)
(c:changelinetype)

 

 

if you do this a lot look at a menu or use AUTOLOAD in a startup lisp.

 

 Multi getvals.lsp must be saved in a support path. 

0 Likes