+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    Full Member
    Using
    AutoCAD 2015
    Join Date
    Sep 2016
    Posts
    99

    AutoCAD Manual Entry between Lisp Routine.

    Registered forum members do not see this ad.

    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.

    Code:
    (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

  2. #2
    Full Member
    Using
    AutoCAD 2014
    Join Date
    Dec 2010
    Posts
    79

    Default

    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?

  3. #3
    Full Member
    Using
    AutoCAD 2015
    Join Date
    Sep 2016
    Posts
    99

    Default

    Yes still i need to offset two lines both are coming with different colours..
    Right now i want to enter the offset distance manually.

  4. #4
    Full Member
    Using
    AutoCAD 2014
    Join Date
    Dec 2010
    Posts
    79

    Default

    Code:
    (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:

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

  5. #5
    Quantum Mechanic BIGAL's Avatar
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,577

    Default

    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.

    Code:
    (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
    Code:
    (setq obj (entlast))
    (chprop obj "la" "delete-layer" "")
    A man who never made mistakes never made anything

  6. #6
    Full Member
    Using
    AutoCAD 2015
    Join Date
    Sep 2016
    Posts
    99

    Default

    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.

  7. #7
    Full Member
    Using
    AutoCAD 2014
    Join Date
    Dec 2010
    Posts
    79

    Default

    4 lines:

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

  8. #8
    Super Member hanhphuc's Avatar
    Using
    AutoCAD 2007
    Join Date
    Apr 2013
    Location
    Happy Garden
    Posts
    707

    Default

    Quote Originally Posted by Emmanuel Delay View Post
    4 lines:

    Code:
      (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
    Code:
    (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:
    Code:
    (setq A (_getreal "\nEnter multiple offset distance," nil ))
    Enter multiple offset distance, nil ? : 1 2 3 4 5 ;<--user input separate by space 
    (1 2 3 4 5)
    
    (setq B (_getreal "\nEnter multiple offset distance," A ))
    Enter multiple offset,  |1 |2 |3 |4 |5| ? : ; <Enter> to accept default values 
    (1 2 3 4 5)
    
    ;from your test
    (setq data (_getreal "\nEnter multiple offset distance," B ))
    Enter multiple offset,  |1 |2 |3 |4 |5| ? : 6 3 4 5  ;<--user overrides default 
    (6 3 4 5)
    
    ;data to be used 
    (foreach x data 
    
    ; offset x bla bla 
    
    )
    Last edited by hanhphuc; 14th Jun 2018 at 10:32 am. Reason: _prompt to _getreal
    _$ ( apply 'equal "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" )
    ; error: too many arguments

  9. #9
    Quantum Mechanic BIGAL's Avatar
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    10,577

    Default

    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
    Code:
    (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 "")
    )
    )
    Last edited by BIGAL; 14th Jun 2018 at 09:55 am.
    A man who never made mistakes never made anything

  10. #10
    Super Member hanhphuc's Avatar
    Using
    AutoCAD 2007
    Join Date
    Apr 2013
    Location
    Happy Garden
    Posts
    707

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by BIGAL View Post
    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
    _$ ( apply 'equal "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" )
    ; error: too many arguments

Similar Threads

  1. Repeat Data Entry in Routine
    By Arizona in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 27th Dec 2016, 11:57 pm
  2. Wipeout Lisp That helps me avoid the manual typing.
    By SunnyTurtle in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 2nd Sep 2013, 04:25 pm
  3. [LISP] First time writing LISP routine... trying to rotate, move and scale
    By chiimayred in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 18th Jul 2013, 06:02 pm
  4. Combine three lisp routine into one routine.
    By BrianTFC in forum AutoLISP, Visual LISP & DCL
    Replies: 0
    Last Post: 7th Feb 2012, 05:11 pm
  5. Plotting Routine - Allow word with spaces for text entry for paper size??
    By ILoveMadoka in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 21st Jun 2011, 01:09 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts