Jump to content
gmmdinesh

Manual Entry between Lisp Routine.

Recommended Posts

gmmdinesh

Hi Everyone.

I have Lisp file to make double offset, offset distance are getting automatically as per lisp. but i want enter that distance manually and that entered value will be taken as offset distance.

Please anyone tell me how to change this.

 

(defun c:oly (/ l s p e)
(command ".undo" "m")
(command "-layer" "M" "DELETE-LAYER" "c" "green" "DELETE-LAYER" "" "")
 (setq l (entlast))
 (if (tblsearch "LAYER" "DELETE-LAYER")
   (while (and
            (setq s (car (entsel "\nPick Line/Polyline to offset :")))
            (wcmatch (cdr (assoc 0 (entget s))) "LINE,*POLYLINE")
            (setq p (getpoint "\nSpecify offset side :"))
            )
     (foreach x '((1.25 6) (1.75 3))
       (command "_.offset" (car x) (ssadd s) "_non" p "")
       (and
         (not (= (setq e (entlast)) l))
         (entmod
           (append
             (entmod
               (subst
                 '(8 . "DELETE-LAYER")
                 (assoc 8 (entget e))
                 (entget e)
                 )
               )
             (list (cons 62 (cadr x)))
             )
           )
         (setq l e)
         )
       )
     )
   (alert "Layer name <DELETE-LAYER> is not found in drawing <!>.")
   )
 (princ)
 )

 

Thanks in Advance

Share this post


Link to post
Share on other sites
Emmanuel Delay

So, now that distance is here:

 

(foreach x '((1.25 6) (1.75 3))

 

first offset:

distance: 1.25, color: 6

 

second offset:

distance: 1.75, color: 3

 

Do you still want 2 lines?

What about those colors?

Share this post


Link to post
Share on other sites
gmmdinesh

Yes still i need to offset two lines both are coming with different colours..

Right now i want to enter the offset distance manually.

Share this post


Link to post
Share on other sites
Emmanuel Delay

(setq offsetdistance 0.0)  ;; just to remember it next time
(setq offsetdistance2 0.0)  ;; just to remember it next time

(defun c:oly (/ l s p e x prompt data)

 (if (> offsetdistance 0.0) 
   (setq prompt (strcat "\nEnter distance 1 <" (rtos offsetdistance 2 2) ">: "))
   (setq prompt "\nEnter distance 1: ")
 )
 (if (setq x (getreal prompt))
   (setq offsetdistance x)
 )

 (if (> offsetdistance2 0.0) 
   (setq prompt (strcat "\nEnter distance 2 <" (rtos offsetdistance2 2 2) ">: "))
   (setq prompt "\nEnter distance 2: ")
 )
 (if (setq x (getreal prompt))
   (setq offsetdistance2 x)
 )

 (setq data (list 
   (list offsetdistance 6)
   (list offsetdistance2 3)
 ))

 (command ".undo" "m")
 (command "-layer" "M" "DELETE-LAYER" "c" "green" "DELETE-LAYER" "" "")
   (setq l (entlast))
   (if (tblsearch "LAYER" "DELETE-LAYER")
     (while (and
              (setq s (car (entsel "\nPick Line/Polyline to offset :")))
              (wcmatch (cdr (assoc 0 (entget s))) "LINE,*POLYLINE")
              (setq p (getpoint "\nSpecify offset side :"))
              )
      (foreach x data
       (command "_.offset"  (car x) (ssadd s) "_non" p "")
         (and
           (not (= (setq e (entlast)) l))
           (entmod
             (append
               (entmod
                 (subst
                   '(8 . "DELETE-LAYER")
                   (assoc 8 (entget e))
                   (entget e)
                   )
                 )
               (list (cons 62 (cadr x)))
               )
             )
           (setq l e)
           )
         )
       )
     (alert "Layer name <DELETE-LAYER> is not found in drawing <!>.")
     )
   (princ)
)

If you want different colors, change the 6 and the 3 in these lines:

 

  
 (setq data (list      
   (list offsetdistance 6)
   (list offsetdistance2 3)   
 ))

Share this post


Link to post
Share on other sites
BIGAL

I am going to say I did not look to closely will try to find I did a offset routine that just allowed like a csv as input 3,2,-3,-2 so end up with 4 lines +/ve I guess could add color also.

 

Somethings just write and post and dont really save then this happens can not find.

 

This is not what I was looking for but a simple offset you can enter -ve to go other side.

 

(defun C:MULOFF ( / obj s off)
(vl-load-com)
(setq obj (entsel "\nSelectObject"))
(setq s (getpoint "\nPick Offset side"))
(while (/= (setq off (getreal "\nEnter offset or Enter to exit")) nil)
(vl-cmdf "_.offset" off obj s "")
(setq obj (entlast))
)
)
(c:muloff)

 

If you want change layer

(setq obj (entlast))
(chprop obj "la" "delete-layer" "")

Share this post


Link to post
Share on other sites
gmmdinesh

Thank you so much Emmanuel,

It's working perfectly.

One more Help, I want to offset two more lines (total 4 lines) with different distances, Please tell me how to change the lisp.

Share this post


Link to post
Share on other sites
Emmanuel Delay

4 lines:

 

(setq offsetdistance 0.0)  ;; just to remember it next time
(setq offsetdistance2 0.0)  ;; just to remember it next time
(setq offsetdistance3 0.0) 
(setq offsetdistance4 0.0) 


(defun c:oly (/ l s p e x prompt data)

 (if (> offsetdistance 0.0) 
   (setq prompt (strcat "\nEnter distance 1 <" (rtos offsetdistance 2 2) ">: "))
   (setq prompt "\nEnter distance 1: ")
 )
 (if (setq x (getreal prompt))
   (setq offsetdistance x)
 )

 (if (> offsetdistance2 0.0) 
   (setq prompt (strcat "\nEnter distance 2 <" (rtos offsetdistance2 2 2) ">: "))
   (setq prompt "\nEnter distance 2: ")
 )
 (if (setq x (getreal prompt))
   (setq offsetdistance2 x)
 )

(if (> offsetdistance3 0.0) 
   (setq prompt (strcat "\nEnter distance 3 <" (rtos offsetdistance3 2 2) ">: "))
   (setq prompt "\nEnter distance 3: ")
 )
 (if (setq x (getreal prompt))
   (setq offsetdistance3 x)
 )

(if (> offsetdistance4 0.0) 
   (setq prompt (strcat "\nEnter distance 4 <" (rtos offsetdistance4 2 2) ">: "))
   (setq prompt "\nEnter distance 4: ")
 )
 (if (setq x (getreal prompt))
   (setq offsetdistance4 x)
 )

 (setq data (list 
   (list offsetdistance 6)
   (list offsetdistance2 3)
   (list offsetdistance3 4)
   (list offsetdistance4 5)
 ))

 (command ".undo" "m")
 (command "-layer" "M" "DELETE-LAYER" "c" "green" "DELETE-LAYER" "" "")
   (setq l (entlast))
   (if (tblsearch "LAYER" "DELETE-LAYER")
     (while (and
              (setq s (car (entsel "\nPick Line/Polyline to offset :")))
              (wcmatch (cdr (assoc 0 (entget s))) "LINE,*POLYLINE")
              (setq p (getpoint "\nSpecify offset side :"))
              )
      (foreach x data
       (command "_.offset"  (car x) (ssadd s) "_non" p "")
         (and
           (not (= (setq e (entlast)) l))
           (entmod
             (append
               (entmod
                 (subst
                   '(8 . "DELETE-LAYER")
                   (assoc 8 (entget e))
                   (entget e)
                   )
                 )
               (list (cons 62 (cadr x)))
               )
             )
           (setq l e)
           )
         )
       )
     (alert "Layer name <DELETE-LAYER> is not found in drawing <!>.")
     )
   (princ)
)

Share this post


Link to post
Share on other sites
hanhphuc
Posted (edited)
4 lines:

 

 (setq data (list 
   (list offsetdistance 6)
   (list offsetdistance2 3)
   (list offsetdistance3 4)
   (list offsetdistance4 5)
 ))

 

hi, FWIW prompt is a protective symbol. my $0.05 (setq str .. ) instead of (setq prompt (getstring ))

 

another, my suggestion for multiple getreal :)

it accepts zero & negative, you can modify to suit you


(defun _getreal (msg lst / np str l )
;hanhphuc 
 (while (not np )
   (setq str  (getstring t
                         (strcat msg
                                 " "
                                 (vl-string-translate
                                   "()"
                                   " |"
                                   (vl-princ-to-string (mapcar '(lambda (x) (strcat "|" (rtos x 2))) lst))
                                   )
                                 " ? : "
                                 )
                         )
         l    (cond ((read (strcat "(" str ")")))
                    (lst)
                    )
         np (if (and l (vl-every 'numberp l))
                l
                (prompt "\nOops! Invalid value !!")
                )
         )
   )
 l
 )

 

Example:

(setq A (_getreal "\nEnter multiple offset distance," [color="blue"]nil[/color] ))
Enter multiple offset distance, nil ? : 1 2 3 4 5 [color="green"];<--user input separate by space [/color]
(1 2 3 4 5)

(setq B (_getreal "\nEnter multiple offset distance," A ))
Enter multiple offset,  |1 |2 |3 |4 |5| ? : [color="green"]; <Enter> to accept default values[/color] 
(1 2 3 4 5)

;from your test
(setq [color="red"]data[/color] (_getreal "\nEnter multiple offset distance," B ))
Enter multiple offset,  |1 |2 |3 |4 |5| ? : [b]6 3 4 5[/b]  [color="green"];<--user overrides default[/color] 
(6 3 4 5)

[color="green"];data to be used [/color]
(foreach [b]x[/b] [color="red"]data[/color] 

[color="green"]; offset [b]x[/b] bla bla [/color]

)

Edited by hanhphuc
_prompt to _getreal

Share this post


Link to post
Share on other sites
BIGAL
Posted (edited)

hahnphuc basicly the same as I suggested but csv style still loooking when you have so many hard to remember where you put the code some times.

 

for fun the bla bla

(defun c:muloff(/ o s l)
(setq o (entsel "\nSelect Object"))
(setq pt (getpoint "\nPick Offset side"))
(setq data (_prompt "\nEnter multiple offset distance," B ))
(foreach i data
(vl-cmdf "_.offset" i o pt "")
)
)

Edited by BIGAL

Share this post


Link to post
Share on other sites
hanhphuc
hahnphuc basicly the same as I suggested but csv style still loooking when you have so many hard to remember where you put the code some times.

 

yeah BIGAL, csv is good solution too :)

i just offer generic suggestion rather than @Emmanuel Delay to rewrite his code if OP request more offsets :)

Share this post


Link to post
Share on other sites
Emmanuel Delay

Thanks guys

Share this post


Link to post
Share on other sites
Emmanuel Delay

When using csv as a data import/export, have you guys found a way for Excel to not turn entity handle 34E57 in 34*10^57, and not omit all the leading zeros, not turn things into dates, ...

I know, it's not Autocad or LISP's fault, but maybe you found some obvious solution...

I can't explain to my colleagues how to import it in excel, set the data formatting, (Meanwhile I use notedpad++ to adapt data in the csv) ...

Share this post


Link to post
Share on other sites
hanhphuc

hi,

do you notice command : ATTOUT , 'handles' output with quote mark, i.e: '34E57

Share this post


Link to post
Share on other sites
hanhphuc
hahnphuc basicly the same as I suggested but csv style still loooking when you have so many hard to remember where you put the code some times.

 

for fun the bla bla

(defun c:muloff(/ o s l)
(setq o (entsel "\nSelect Object"))
(setq pt (getpoint "\nPick Offset side"))
(setq data ([color="blue"]_getreal[/color] "\nEnter multiple offset distance," [color="red"][b]B[/b][/color] ))
(foreach i data
(vl-cmdf "_.offset" i o pt "")
)
)

sorry BIGAL i've changed the symbol _prompt to _getreal which naming is more relevant :oops:

 

Although global variable is not preferable than csv , another suggestion - store as 'list' string

(setvar '[b][color="purple"]users1[/color][/b] (vl-princ-to-string [color="red"]'(1 2 3 4 5)[/color])) [color="green"]; as default[/color] or (_getreal  "msg" nil)
(setq [b][color="red"]B[/color][/b] (read (getvar '[b][color="purple"]users1[/color][/b])))

Share this post


Link to post
Share on other sites
gmmdinesh

Thank you so much.. All of you for your code.

Thank Emmanuel..... code was worked perfectly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×