Author Topic: offset code it s ok or any modification this code  (Read 1757 times)

0 Members and 1 Guest are viewing this topic.

Sam

  • Bull Frog
  • Posts: 201
offset code it s ok or any modification this code
« 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.  
« Last Edit: March 04, 2013, 09:05:21 AM by Sam »
Every time we waste electricity, we put our planet's future in the dark. Let's turn around our attiude and start saving power and our planet, before it's too late
http://www.theswamp.org/donate.html

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: offset code it s ok or any modification this code
« Reply #1 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. )

Sam

  • Bull Frog
  • Posts: 201
Re: offset code it s ok or any modification this code
« Reply #2 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
Every time we waste electricity, we put our planet's future in the dark. Let's turn around our attiude and start saving power and our planet, before it's too late
http://www.theswamp.org/donate.html

Sam

  • Bull Frog
  • Posts: 201
Re: offset code it s ok or any modification this code
« Reply #3 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. )
Every time we waste electricity, we put our planet's future in the dark. Let's turn around our attiude and start saving power and our planet, before it's too late
http://www.theswamp.org/donate.html

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: offset code it s ok or any modification this code
« Reply #4 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))

Sam

  • Bull Frog
  • Posts: 201
Re: offset code it s ok or any modification this code
« Reply #5 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
Every time we waste electricity, we put our planet's future in the dark. Let's turn around our attiude and start saving power and our planet, before it's too late
http://www.theswamp.org/donate.html