Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

unknow command, using while

1 REPLY 1
Reply
Message 1 of 2
robert06
189 Views, 1 Reply

unknow command, using while

Using these two lisps alternately, CAD does not recognize one or the other, it says 'unknown command' and executes then the one which was used first:

 

(defun c:os1 ()
    (command ".undo" "begin")
    (while (vl-cmdf "offset" ".25" pause pause "")
    (vl-cmdf "chprop" "l" "" "lt" "continuous" ""))
    (command "undo" "end")
    (princ)
)

(defun c:os2 ()
    (command ".undo" "begin")
    (while (vl-cmdf "offset" ".2" pause pause "")
    (vl-cmdf "chprop" "l" "" "lt" "continuous" ""))
    (command "undo" "end")
        (princ)
)

 

I must have done something wrong when I added repeating functionality, as they worked fine before that (below):

 

(defun c:os1 ()
    (command ".undo" "begin")
    (command "offset" ".25" pause pause "")
    (command "chprop" "l" "" "lt" "continuous" "")
    (command "undo" "end")
    (princ)
)

thanks!

 

1 REPLY 1
Message 2 of 2
Kent1Cooper
in reply to: robert06


@robert06 wrote:

Using these two lisps alternately, CAD does not recognize one or the other, it says 'unknown command' and executes then the one which was used first:

 

(defun c:os1 ()
    (command ".undo" "begin")
    (while (vl-cmdf "offset" ".25" pause pause "")
    (vl-cmdf "chprop" "l" "" "lt" "continuous" ""))
    (command "undo" "end")
    (princ)
)
...


The AutoLISP Reference says that (vl-cmdf) returns T, apparently regardless of anything the User does, which means the (while) loop won't ever end on its own.  But you could try a different way of going about it, that also doesn't require changing the linetypes of each resulting object individually:

 

(defun C:OS1 (/ celt)

  (command "_.undo" "_begin")

  (setq celt (getvar 'celtype)); save current value

  (command "_.offset" 0.25); leave User at selection prompt

  (while (> (getvar 'cmdactive) 0) (command pause)); let User keep offsetting things until they end it

  (setvar 'celtype celt); reset

  (command "_.undo" "_end")

  (princ)

)

 

It could probably use an error handler, to make sure CELTYPE gets reset if the User cancels or something.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost