TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Sam on March 04, 2013, 02:24:22 AM

Title: offset code it s ok or any modification this code
Post by: Sam on March 04, 2013, 02:24:22 AM
Dear sir,
please see this offset code it s ok or any modification this code


Code - Auto/Visual Lisp: [Select]
  1. (defun c:150 () (command "offset" "150"))
  2. (defun c:230 () (command "offset" "230"))
  3. (defun c:100 () (command "offset" "100"))
  4.  

or
Code - Auto/Visual Lisp: [Select]
  1. (defun c:150    () (command "Offset" 150 pause)(princ))


What is difference between below code

Code - Auto/Visual Lisp: [Select]
  1. (defun c:150 () (command "offset" "150") (princ))
  2. (defun c:150 () (command "offset" "150"))
  3. (defun c:150 () (command "Offset" 150 pause)
  4.  
Title: Re: offset code it s ok or any modification this code
Post by: roy_043 on March 04, 2013, 10:32:27 AM
Code - Auto/Visual Lisp: [Select]
  1. (defun c:150 () (command "offset" "150") (princ))
  2. (defun c:150 () (command "offset" "150"))
  3. (defun c:150 () (command "Offset" 150 pause)

In all these examples the command continues beyond the scope of the function. This is not good programming practice. My suggestions:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:150 ()
  2.   (command "_.offset" 150)
  3.   (while (> (getvar 'cmdactive) 0)
  4.     (command pause)
  5.   )
  6.   (princ)
  7. )

Code - Auto/Visual Lisp: [Select]
  1. (defun c:150 ()
  2.   (command "_.offset" 150 pause pause "")
  3.   (princ)
  4. )
Title: Re: offset code it s ok or any modification this code
Post by: Sam on March 04, 2013, 11:42:06 PM
In all these examples the command continues beyond the scope of the function. This is not good programming practice. My suggestions:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:150 ()
  2.   (command "_.offset" 150)
  3.   (while (> (getvar 'cmdactive) 0)
  4.     (command pause)
  5.   )
  6.   (princ)
  7. )

Code - Auto/Visual Lisp: [Select]
  1. (defun c:150 ()
  2.   (command "_.offset" 150 pause pause "")
  3.   (princ)
  4. )

Dear Sir,
Thx for guidance
Thx for Reply
Title: Re: offset code it s ok or any modification this code
Post by: Sam on March 05, 2013, 01:54:24 AM
Dear Sir,
i am combing of varies offset this code ok or any suggestion
 
Code - Auto/Visual Lisp: [Select]
  1. (defun c:100 ()
  2.   (command "_.offset" 100)
  3.   (defun c:150 ()
  4.     (command "_.offset" 150)
  5.     (defun c:230 ()
  6.       (command "_.offset" 230)
  7.       (while (> (getvar 'cmdactive) 0)
  8.         (command pause)
  9.       )
  10.       (princ)
  11.     )
  12.   )
  13. )
Title: Re: offset code it s ok or any modification this code
Post by: roy_043 on March 05, 2013, 03:04:56 AM
If you test your code in a new drawing you will find that the nested functions only become available after their parent functions have been called. This means that you have to use the c:100 function at least once for the c:150 function to become available. And the c:150 function must be called for the c:230 function to become available. And of the three functions only c:230 will behave properly.

The question is what are you trying to do? You should not nest functions without a good reason.

If you want to use an 'offset template' function, consider this example:
Code - Auto/Visual Lisp: [Select]
  1. (defun OffsetTemplate (dist)
  2.   (command "_.offset" dist)
  3.   (while (> (getvar 'cmdactive) 0)
  4.     (command pause)
  5.   )
  6. )
  7.  
  8. (defun c:100 () (OffsetTemplate 100) (princ))
  9. (defun c:150 () (OffsetTemplate 150) (princ))
  10. (defun c:230 () (OffsetTemplate 230) (princ))
Title: Re: offset code it s ok or any modification this code
Post by: Sam on March 05, 2013, 05:12:42 AM

The question is what are you trying to do? You should not nest functions without a good reason.

If you want to use an 'offset template' function, consider this example:
Code - Auto/Visual Lisp: [Select]
  1. (defun OffsetTemplate (dist)
  2.   (command "_.offset" dist)
  3.   (while (> (getvar 'cmdactive) 0)
  4.     (command pause)
  5.   )
  6. )
  7.  
  8. (defun c:100 () (OffsetTemplate 100) (princ))
  9. (defun c:150 () (OffsetTemplate 150) (princ))
  10. (defun c:230 () (OffsetTemplate 230) (princ))
[/quote]

Dear Sir,

Thx for help
i am study