Jump to content

Manual Entry between Lisp Routine.


gmmdinesh

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Right now i want to enter the offset distance manually.

Link to comment
Share on other sites

(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)   
 ))

Link to comment
Share on other sites

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" "")

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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) ...

Link to comment
Share on other sites

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])))

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...