Jump to content

line new layer my lisp not working please fix


sanjeeve

Recommended Posts

Hi I want draw lines it has create new layer and snap end point and Ortho on once I right click or cancel it has to go back to old layer and snap off and Ortho off

Link to comment
Share on other sites

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • sanjeeve

    9

  • BIGAL

    6

  • Lee Mac

    4

  • MSasu

    2

Hi

I want lisp to draw line create new layer and Ortho on snap end

One I right click or cancel it has to go back old layer and Ortho and snap off

Link to comment
Share on other sites

This what wrote it is not working any one help me to fix

(define c:line()
(setq a( getvar "player"))
(setvar "Ortho" 1)
(setvar "snap" 1)
(command "line")
(setvar "player" a)
(setvar "Ortho" 0)
(setvar "snap" 0)
)

Edited by SLW210
Code Tags Added!
Link to comment
Share on other sites

You already started a thread on this topic that Lee Mac responded to. There is no need to create a new thread every time you respond as it just causes confusion. Thank you.

Link to comment
Share on other sites

Sanjeeve 1st comment dont use c:line as line is a reserved word and you may have problems,

 

(defun c:lll ()
(setq a( getvar "clayer"))
(setvar "Ortho" 1)
(setvar "snap" 1)
;(command "line")
; create line by picking points press enter when finished
(command "_line")
(while (= (getvar "cmdactive") 1 ) (command "pause")
)
(setvar "clayer" a)
(setvar "Ortho" 0)
(setvar "snap" 0)
) 

Edited by BIGAL
Link to comment
Share on other sites

To review your code, please check my comments:

([color=red]define[/color] [color=magenta]c:line[/color]()              ;bad function name, should be DEFUN; pay attention to redefining built-in commands
(setq a( getvar "[color=red]player[/color]"))   ;the name of the variable is VPLAYER
(setvar "[color=red]Ortho[/color]" 1)           ;the name of the variable is ORTHOMODE
(setvar "[color=red]snap[/color]" 1)            ;the name of the variable is SNAPMODE
(command "line")             ;this call will not allow to reach following statements, thus restoring environment will fails
(setvar "[color=red]player[/color]" a)          ;see above
(setvar "[color=red]Ortho[/color]" 0)           ;see above
(setvar "[color=red]snap[/color]" 0)            ;see above
)

Link to comment
Share on other sites

Sanjeeve 1st comment dont use c:line as line is a reserved word and you may have problems,

 

(define c:lll ()
(setq a( getvar "clayer"))
(setvar "Ortho" 1)
(setvar "snap" 1)
;(command "line")
; create line by picking points press enter when finished
(command "_line")
(while (= (getvar "cmdactive") 1 ) (command pause
)
(setvar "clayer" a)
(setvar "Ortho" 0)
(setvar "snap" 0)
) 

 

 

This is not working why

Link to comment
Share on other sites

This is not working why

Please check the post #9 where I added comments to your code to allow you understand what prevent it to work; then check also what BIGAL proposed for line repetitively input and those should alow you to debug. Please don't forget that you will benefit more if you will understand what was wrong then from just getting the fixed code.

Link to comment
Share on other sites

Perhaps the following example will also help you:

(defun c:myline ( / lay val var )
   
   ;; Layer for Lines:
   (setq lay "My Line Layer")
   
   ;; Store current system variable values
   (setq var '(cmdecho clayer orthomode osmode)
         val  (mapcar 'getvar var)
   ) ;; end SETQ
   
   ;; Suppress command-line output
   (setvar 'cmdecho 0)
   
   ;; Create/set/thaw/turn on/unlock the required layer
   (command "_.-layer" "_m" lay "_t" lay "_on" lay "_u" lay "")
   
   ;; Set other system variable values
   (setvar 'orthomode 1) ;; Ortho ON
   (setvar 'osmode    1) ;; Snap set to Endpoint
   (setvar 'cmdecho   1) ;; Now we want the command-line output
   
   ;; Invoke the LINE command
   (command "_.line")
   
   ;; While the command is active
   (while (= 1 (logand 1 (getvar 'cmdactive)))
       ;; Pause for user input
       (vl-cmdf "\\") 
       ;; vl-cmdf is used to test the validity of the user input
       ;; before submitting it to the command-line.
       
   ) ;; end WHILE
   
   ;; Reset system variable values
   (mapcar 'setvar var val)

   ;; Suppress the return of the last evaluated expression
   (princ)
) ;; end DEFUN

 

Please take some time to carefully read the comments.

 

Lee

Link to comment
Share on other sites

Sanjeeve 1st comment dont use c:line as line is a reserved word and you may have problems,

 

(defun c:lll ()
(setq a( getvar "clayer"))
(setvar "Ortho" 1)
(setvar "snap" 1)
;(command "line")
; create line by picking points press enter when finished
(command "_line")
(while (= (getvar "cmdactive") 1 ) (command pause)
)
(setvar "clayer" a)
(setvar "Ortho" 0)
(setvar "snap" 0)
) 

yes, I change that to defun it is not working

Link to comment
Share on other sites

Hi Lee

 

Thanks alot man this save my time it is working for me

 

You're welcome sanjeeve -

Be sure to read the comments so that you have a good understanding of what the code is doing.

 

Lee

Link to comment
Share on other sites

You're welcome sanjeeve -

Be sure to read the comments so that you have a good understanding of what the code is doing.

 

Lee

Yes I am able to understand bit I could write simple lisp when ever I put two or more commands together it is not working I am tryin to under stand while and progan

 

 

Normally to create new layer

I use (command "layer" "myline" "color" "red" "" "")

but I couldn't see that line in you lisp but it create layer how

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...