Jump to content

Offset polyline


Jojo

Recommended Posts

I'm using Carlson Software. The lsp is awesome but instead of offsetting it one at a time, I was wondering if we could highlight all the numbers (text with different numbers) to offset a single line to a different distance. I don't want to offset the text. I really apologize for confusing you.

Link to comment
Share on other sites

So take the zero line and offset it ?

 

Need a dwg before and  after, use Wblock to make a new dwg with only relevant objects.

Edited by BIGAL
Link to comment
Share on other sites

Added to my "to do list". fairly simple just offset or copy a line based on the chainage, will add a Horizontal scale factor. 

Link to comment
Share on other sites

On 9/6/2024 at 6:24 PM, BIGAL said:

Added to my "to do list". fairly simple just offset or copy a line based on the chainage, will add a Horizontal scale factor. 

Good Morning Bigal.

Link to comment
Share on other sites

Sorry been busy getting behind in a few things. Maybe today.

 

Ok found some time this needs a little bit of adjustment but try it 1st.

 

; https://www.cadtutor.net/forum/topic/78552-offset-polyline/page/2/

(defun c:loff ( / oldsnap ss ent pt1)
; before & after dwg

;;  Parses a list of numerical values from a supplied string. ;;
;;-------------------=={ Parse Numbers }==--------------------;;
;;                                                            ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  s - String to process                                     ;;
;;------------------------------------------------------------;;
;;  Returns:  List of numerical values found in string.       ;;
;;------------------------------------------------------------;;

(defun LM:ParseNumbers ( s )
  (
    (lambda ( l )
      (read
        (strcat "("
          (vl-list->string
            (mapcar
              (function
                (lambda ( a b c )
                  (if
                    (or
                      (< 47 b 58)
                      (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                      (and (= 46 b) (< 47 a 58) (< 47 c 58))
                    )
                    b 32
                  )
                )
              )
              (cons nil l) l (append (cdr l) (list nil))
            )
          )
          ")"
        )
      )
    )
    (vl-string->list s)
  )
)

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)

(prompt "\nSelect text ")
(setq ss (ssget '((0 ."TEXT"))))
(setq ent (entsel "\nPick zero line "))


(repeat (setq x (sslength ss))
 (setq str (cdr (assoc 1 (entget (ssname ss (setq x (1- x)))))))
 (setq d (car (LM:ParseNumbers str)))
 (command "copy" ent "" "0,0,0" (list d 0.0 0.0))
 (setq pt1 (cdr (assoc 10 (entget (entlast)))))
 (command "text" pt1 2.5 90 str)
)

(setvar 'osmode oldsanp)
(princ)
)

 

Edited by BIGAL
Link to comment
Share on other sites

17 hours ago, BIGAL said:

Sorry been busy getting behind in a few things. Maybe today.

 

Ok found some time this needs a little bit of adjustment but try it 1st.

 

; https://www.cadtutor.net/forum/topic/78552-offset-polyline/page/2/

(defun c:loff ( / oldsnap ss ent pt1)
; before & after dwg

;;  Parses a list of numerical values from a supplied string. ;;
;;-------------------=={ Parse Numbers }==--------------------;;
;;                                                            ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  s - String to process                                     ;;
;;------------------------------------------------------------;;
;;  Returns:  List of numerical values found in string.       ;;
;;------------------------------------------------------------;;

(defun LM:ParseNumbers ( s )
  (
    (lambda ( l )
      (read
        (strcat "("
          (vl-list->string
            (mapcar
              (function
                (lambda ( a b c )
                  (if
                    (or
                      (< 47 b 58)
                      (and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
                      (and (= 46 b) (< 47 a 58) (< 47 c 58))
                    )
                    b 32
                  )
                )
              )
              (cons nil l) l (append (cdr l) (list nil))
            )
          )
          ")"
        )
      )
    )
    (vl-string->list s)
  )
)

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)

(setq ss (ssget '((0 ."TEXT"))))
(setq ent (entsel "\nPick zero line "))


(repeat (setq x (sslength ss))
(setq str (cdr (assoc 1 (entget (ssname ss (setq x (1- x)))))))
(setq d (car (LM:ParseNumbers str)))
(command "copy" ent "" "0,0,0" (list d 0.0 0.0))
(setq pt1 (cdr (assoc 10 (entget ent2))))
(command "text" pt1 ht 90 str)
)

(setvar 'osmode oldsanp)
(princ)
)

 

Yeah, this one did not work. I was just looking for a regular offset by highlighting a bunch of numbers to offset one polyline.

 

Link to comment
Share on other sites

When you respond "did not work" it does not tell us anything, need to know did you get error messages or wrong objects drawn. 

 

Please provide more details.

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

19 hours ago, BIGAL said:

When you respond "did not work" it does not tell us anything, need to know did you get error messages or wrong objects drawn. 

 

Please provide more details.

I uppload the lsp and type "loff", and it just ask me to select an object to be frozen. I attached a "Recording 2" for you to see. it's not an offset. Or am I doing it wrong?

Link to comment
Share on other sites

Bigal. I was wondering if you can create a lsp that will offset a line with just highlighting bunch of numbers instead of one at a time. I attached a video as a sample. Thank you in advance.

Link to comment
Share on other sites

@Jojo According to your posted video ("Recording 2") and explanation in text, try this LISP and see if it works for your neededs.

 

***Did a little update in code (hope it can be helpful).

 

; *****************************************************************************************************************
; Functions     :  MOBT
; Description   :  Offset LINE or POLYLINE multiple times based on text or mtext in choosen direction
; Author        :  SAXLLE
; Date          :  September 14, 2024
; Update 1.0    :  Solved a problem when LINE or POLYLINE has been drawn from bottom-to-top or top-to-bottom
;                  where the user can choose to reverse the drawing direction or not
; Update date   :  September 15, 2024
; *****************************************************************************************************************

(prompt "\nTo run a LISP type: MOBT")
(princ)

(defun c:MOBT (/ ename spt ept answ dir ss len i data)
  (setq old_osm (getvar "osmode"))
  (setvar "osmode" 0)
  (setq ename (car (entsel "\nSelect LINE or POLYLINE to offset:")))
  (princ)
  (while (not (or (= "LINE" (cdr (assoc 0 (entget ename)))) (= "LWPOLYLINE" (cdr (assoc 0 (entget ename))))))
    (prompt "\nSelected entity must be LINE or POLYLINE. Try again...")
    (setq ename (car (entsel "\nSelect LINE or POLYLINE to offset:")))
    (princ)
    )
  (cond
    ((= "LINE" (cdr (assoc 0 (entget ename))))
     (setq spt (vlax-curve-getStartPoint (vlax-ename->vla-object ename)))
     (setq ept (vlax-curve-getEndPoint (vlax-ename->vla-object ename)))
     (if (> (cadr ept) (cadr spt))
       (progn
	 (setq answ (getstring "\nThe selected entity has been drawn from bottom-to-top. Do you want to reverse direction? [Yes/No]"))
	 (if (or (= answ "Y") (= answ "Yes") (= answ "yes") (= answ "YES"))
	   (progn
	     (command "._reverse" ename "")
	     (princ "\nThe selected entity has changed direction from top-to-bottom.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [- Left/+ Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   (progn
	     (prompt "\nThe selected entity retains the current direction from bottom-to-top.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [+ Left/- Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   )
	 )
       (progn
	 (setq answ (getstring "\nThe selected entity has been drawn from top-to-bottom. Do you want to reverse direction? [Yes/No]"))
	 (if (or (= answ "Y") (= answ "Yes") (= answ "yes") (= answ "YES"))
	   (progn
	     (command "._reverse" ename "")
	     (princ "\nTThe selected entity has changed direction from bottom-to-top.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [+ Left/- Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   (progn
	     (prompt "\nThe selected entity retains the current direction from top-to-bottom.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [- Left/+ Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   )
	 )
       )
     )
    ((= "LWPOLYLINE" (cdr (assoc 0 (entget ename))))
     (setq spt (vlax-curve-getStartPoint (vlax-ename->vla-object ename)))
     (setq ept (vlax-curve-getEndPoint (vlax-ename->vla-object ename)))
     (if (> (cadr ept) (cadr spt))
       (progn
	 (setq answ (getstring "\nThe selected entity has been drawn from bottom-to-top. Do you want to reverse direction? [Yes/No]"))
	 (if (or (= answ "Y") (= answ "Yes") (= answ "yes") (= answ "YES"))
	   (progn
	     (command "._reverse" ename "")
	     (princ "\nThe selected entity has changed direction from top-to-bottom.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [+ Left/- Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   (progn
	     (prompt "\nThe selected entity retains the current direction from bottom-to-top.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [- Left/+ Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   )
	 )
       (progn
	 (setq answ (getstring "\nThe selected entity has been drawn from top-to-bottom. Do you want to reverse direction? [Yes/No]"))
	 (if (or (= answ "Y") (= answ "Yes") (= answ "yes") (= answ "YES"))
	   (progn
	     (command "._reverse" ename "")
	     (princ "\nThe selected entity has changed direction from bottom-to-top.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [- Left/+ Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   (progn
	     (prompt "\nThe selected entity retains the current direction from top-to-bottom.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [+ Left/- Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   )
	 )
       )
     )
    )
  (setvar "osmode" old_osm)
  (princ (strcat "\nThe " (cdr (assoc 0 (entget ename))) " is offseted " (rtos len 2 0) " times."))
  (princ)
  )

 

Best regards.

Edited by Saxlle
The code has been updated and changes have been made
Link to comment
Share on other sites

This line has no sense since it's not doing anything...

 

(vlax-safearray->list (vlax-variant-value offLine))

  • Thanks 1
Link to comment
Share on other sites

Thank you Marko (Hvala ti puno! Pozdrav 🙂). I did make a mistake. Also, i did a little update in posted code from above.

 

Best regards.

Link to comment
Share on other sites

  • 2 weeks later...
On 9/14/2024 at 4:02 AM, Saxlle said:

@Jojo According to your posted video ("Recording 2") and explanation in text, try this LISP and see if it works for your neededs.

 

***Did a little update in code (hope it can be helpful).

image.png.e46212cd3e768bdc39e98b9a538dae5d.png This is what I was looking for but I was getting error.

 

; *****************************************************************************************************************
; Functions     :  MOBT
; Description   :  Offset LINE or POLYLINE multiple times based on text or mtext in choosen direction
; Author        :  SAXLLE
; Date          :  September 14, 2024
; Update 1.0    :  Solved a problem when LINE or POLYLINE has been drawn from bottom-to-top or top-to-bottom
;                  where the user can choose to reverse the drawing direction or not
; Update date   :  September 15, 2024
; *****************************************************************************************************************

(prompt "\nTo run a LISP type: MOBT")
(princ)

(defun c:MOBT (/ ename spt ept answ dir ss len i data)
  (setq old_osm (getvar "osmode"))
  (setvar "osmode" 0)
  (setq ename (car (entsel "\nSelect LINE or POLYLINE to offset:")))
  (princ)
  (while (not (or (= "LINE" (cdr (assoc 0 (entget ename)))) (= "LWPOLYLINE" (cdr (assoc 0 (entget ename))))))
    (prompt "\nSelected entity must be LINE or POLYLINE. Try again...")
    (setq ename (car (entsel "\nSelect LINE or POLYLINE to offset:")))
    (princ)
    )
  (cond
    ((= "LINE" (cdr (assoc 0 (entget ename))))
     (setq spt (vlax-curve-getStartPoint (vlax-ename->vla-object ename)))
     (setq ept (vlax-curve-getEndPoint (vlax-ename->vla-object ename)))
     (if (> (cadr ept) (cadr spt))
       (progn
	 (setq answ (getstring "\nThe selected entity has been drawn from bottom-to-top. Do you want to reverse direction? [Yes/No]"))
	 (if (or (= answ "Y") (= answ "Yes") (= answ "yes") (= answ "YES"))
	   (progn
	     (command "._reverse" ename "")
	     (princ "\nThe selected entity has changed direction from top-to-bottom.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [- Left/+ Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   (progn
	     (prompt "\nThe selected entity retains the current direction from bottom-to-top.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [+ Left/- Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   )
	 )
       (progn
	 (setq answ (getstring "\nThe selected entity has been drawn from top-to-bottom. Do you want to reverse direction? [Yes/No]"))
	 (if (or (= answ "Y") (= answ "Yes") (= answ "yes") (= answ "YES"))
	   (progn
	     (command "._reverse" ename "")
	     (princ "\nTThe selected entity has changed direction from bottom-to-top.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [+ Left/- Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   (progn
	     (prompt "\nThe selected entity retains the current direction from top-to-bottom.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [- Left/+ Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   )
	 )
       )
     )
    ((= "LWPOLYLINE" (cdr (assoc 0 (entget ename))))
     (setq spt (vlax-curve-getStartPoint (vlax-ename->vla-object ename)))
     (setq ept (vlax-curve-getEndPoint (vlax-ename->vla-object ename)))
     (if (> (cadr ept) (cadr spt))
       (progn
	 (setq answ (getstring "\nThe selected entity has been drawn from bottom-to-top. Do you want to reverse direction? [Yes/No]"))
	 (if (or (= answ "Y") (= answ "Yes") (= answ "yes") (= answ "YES"))
	   (progn
	     (command "._reverse" ename "")
	     (princ "\nThe selected entity has changed direction from top-to-bottom.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [+ Left/- Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   (progn
	     (prompt "\nThe selected entity retains the current direction from bottom-to-top.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [- Left/+ Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   )
	 )
       (progn
	 (setq answ (getstring "\nThe selected entity has been drawn from top-to-bottom. Do you want to reverse direction? [Yes/No]"))
	 (if (or (= answ "Y") (= answ "Yes") (= answ "yes") (= answ "YES"))
	   (progn
	     (command "._reverse" ename "")
	     (princ "\nThe selected entity has changed direction from bottom-to-top.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [- Left/+ Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   (progn
	     (prompt "\nThe selected entity retains the current direction from top-to-bottom.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [+ Left/- Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   )
	 )
       )
     )
    )
  (setvar "osmode" old_osm)
  (princ (strcat "\nThe " (cdr (assoc 0 (entget ename))) " is offseted " (rtos len 2 0) " times."))
  (princ)
  )

 

Best regards.

 

Link to comment
Share on other sites

On 9/14/2024 at 4:02 AM, Saxlle said:

@Jojo According to your posted video ("Recording 2") and explanation in text, try this LISP and see if it works for your neededs.

 

***Did a little update in code (hope it can be helpful).

 

; *****************************************************************************************************************
; Functions     :  MOBT
; Description   :  Offset LINE or POLYLINE multiple times based on text or mtext in choosen direction
; Author        :  SAXLLE
; Date          :  September 14, 2024
; Update 1.0    :  Solved a problem when LINE or POLYLINE has been drawn from bottom-to-top or top-to-bottom
;                  where the user can choose to reverse the drawing direction or not
; Update date   :  September 15, 2024
; *****************************************************************************************************************

(prompt "\nTo run a LISP type: MOBT")
(princ)

(defun c:MOBT (/ ename spt ept answ dir ss len i data)
  (setq old_osm (getvar "osmode"))
  (setvar "osmode" 0)
  (setq ename (car (entsel "\nSelect LINE or POLYLINE to offset:")))
  (princ)
  (while (not (or (= "LINE" (cdr (assoc 0 (entget ename)))) (= "LWPOLYLINE" (cdr (assoc 0 (entget ename))))))
    (prompt "\nSelected entity must be LINE or POLYLINE. Try again...")
    (setq ename (car (entsel "\nSelect LINE or POLYLINE to offset:")))
    (princ)
    )
  (cond
    ((= "LINE" (cdr (assoc 0 (entget ename))))
     (setq spt (vlax-curve-getStartPoint (vlax-ename->vla-object ename)))
     (setq ept (vlax-curve-getEndPoint (vlax-ename->vla-object ename)))
     (if (> (cadr ept) (cadr spt))
       (progn
	 (setq answ (getstring "\nThe selected entity has been drawn from bottom-to-top. Do you want to reverse direction? [Yes/No]"))
	 (if (or (= answ "Y") (= answ "Yes") (= answ "yes") (= answ "YES"))
	   (progn
	     (command "._reverse" ename "")
	     (princ "\nThe selected entity has changed direction from top-to-bottom.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [- Left/+ Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   (progn
	     (prompt "\nThe selected entity retains the current direction from bottom-to-top.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [+ Left/- Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   )
	 )
       (progn
	 (setq answ (getstring "\nThe selected entity has been drawn from top-to-bottom. Do you want to reverse direction? [Yes/No]"))
	 (if (or (= answ "Y") (= answ "Yes") (= answ "yes") (= answ "YES"))
	   (progn
	     (command "._reverse" ename "")
	     (princ "\nTThe selected entity has changed direction from bottom-to-top.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [+ Left/- Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   (progn
	     (prompt "\nThe selected entity retains the current direction from top-to-bottom.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [- Left/+ Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   )
	 )
       )
     )
    ((= "LWPOLYLINE" (cdr (assoc 0 (entget ename))))
     (setq spt (vlax-curve-getStartPoint (vlax-ename->vla-object ename)))
     (setq ept (vlax-curve-getEndPoint (vlax-ename->vla-object ename)))
     (if (> (cadr ept) (cadr spt))
       (progn
	 (setq answ (getstring "\nThe selected entity has been drawn from bottom-to-top. Do you want to reverse direction? [Yes/No]"))
	 (if (or (= answ "Y") (= answ "Yes") (= answ "yes") (= answ "YES"))
	   (progn
	     (command "._reverse" ename "")
	     (princ "\nThe selected entity has changed direction from top-to-bottom.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [+ Left/- Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   (progn
	     (prompt "\nThe selected entity retains the current direction from bottom-to-top.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [- Left/+ Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   )
	 )
       (progn
	 (setq answ (getstring "\nThe selected entity has been drawn from top-to-bottom. Do you want to reverse direction? [Yes/No]"))
	 (if (or (= answ "Y") (= answ "Yes") (= answ "yes") (= answ "YES"))
	   (progn
	     (command "._reverse" ename "")
	     (princ "\nThe selected entity has changed direction from bottom-to-top.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [- Left/+ Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   (progn
	     (prompt "\nThe selected entity retains the current direction from top-to-bottom.")
	     (princ)
	     (setq dir (getstring "\nChoose a side for offset [+ Left/- Right]:"))
	     (princ)
	     (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
	     (terpri)
	     (setq ss (ssget '((0 . "TEXT,MTEXT"))))
	     (setq len (sslength ss))
	     (setq i 0)
	     (while (< i len)
	       (setq data (entget (ssname ss i)))
	       (vla-Offset (vlax-ename->vla-object ename) (strcat dir (cdr (assoc 1 data))))
	       (setq i (1+ i))
	       )
	     )
	   )
	 )
       )
     )
    )
  (setvar "osmode" old_osm)
  (princ (strcat "\nThe " (cdr (assoc 0 (entget ename))) " is offseted " (rtos len 2 0) " times."))
  (princ)
  )

 

Best regards.

Marko. please see attached video. Thank you.

Link to comment
Share on other sites

@Jojo

The problem is that you type a "r" to offset. You need to enter "+" or "-", or just pick a desire direction to offset line or polyline from command line (you will see a highlighted values "+" or "-"). 

 

Best regards. 

Link to comment
Share on other sites

Also I've made few changes to original code... (added - (initget) before (getstring) which is changed to (getkword)) and (atof (strcat dir (cdr (assoc 1 data))))

Not tested though...

(Pozdrav, Saxlle...)

 

; *****************************************************************************************************************
; Functions     :  MOBT
; Description   :  Offset LINE or POLYLINE multiple times based on text or mtext in choosen direction
; Author        :  SAXLLE
; Date          :  September 14, 2024
; Update 1.0    :  Solved a problem when LINE or POLYLINE has been drawn from bottom-to-top or top-to-bottom
;                  where the user can choose to reverse the drawing direction or not
; Update date   :  September 15, 2024
; *****************************************************************************************************************

(prompt "\nTo run a LISP type: MOBT")
(princ)

(defun c:MOBT (/ ename spt ept answ dir ss len i data)

  (or (not (vl-catch-all-error-p (vl-catch-all-apply (function vlax-get-acad-object) nil))) (vl-load-com))

  (setq old_osm (getvar "osmode"))
  (setvar "osmode" 0)
  (setq ename (car (entsel "\nSelect LINE or POLYLINE to offset:")))
  (princ)
  (while (not (or (= "LINE" (cdr (assoc 0 (entget ename)))) (= "LWPOLYLINE" (cdr (assoc 0 (entget ename))))))
    (prompt "\nSelected entity must be LINE or POLYLINE. Try again...")
    (setq ename (car (entsel "\nSelect LINE or POLYLINE to offset:")))
    (princ)
    )
  (cond
    ((= "LINE" (cdr (assoc 0 (entget ename))))
     (setq spt (vlax-curve-getStartPoint (vlax-ename->vla-object ename)))
     (setq ept (vlax-curve-getEndPoint (vlax-ename->vla-object ename)))
     (if (> (cadr ept) (cadr spt))
       (progn
         (initget 1 "Y N y n Yes No yes no YES NO")
         (setq answ (getkword "\nThe selected entity has been drawn from bottom-to-top. Do you want to reverse direction? [Yes/No]"))
         (if (or (= answ "Y") (= answ "y") (= answ "Yes") (= answ "yes") (= answ "YES"))
           (progn
             (command "._reverse" ename "")
             (princ "\nThe selected entity has changed direction from top-to-bottom.")
             (princ)
             (initget 1 "- +")
             (setq dir (getkword "\nChoose a side for offset [- Left/+ Right]:"))
             (princ)
             (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
             (terpri)
             (setq ss (ssget '((0 . "TEXT,MTEXT"))))
             (setq len (sslength ss))
             (setq i 0)
             (while (< i len)
               (setq data (entget (ssname ss i)))
               (vla-Offset (vlax-ename->vla-object ename) (atof (strcat dir (cdr (assoc 1 data)))))
               (setq i (1+ i))
               )
             )
           (progn
             (prompt "\nThe selected entity retains the current direction from bottom-to-top.")
             (princ)
             (initget 1 "- +")
             (setq dir (getkword "\nChoose a side for offset [+ Left/- Right]:"))
             (princ)
             (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
             (terpri)
             (setq ss (ssget '((0 . "TEXT,MTEXT"))))
             (setq len (sslength ss))
             (setq i 0)
             (while (< i len)
               (setq data (entget (ssname ss i)))
               (vla-Offset (vlax-ename->vla-object ename) (atof (strcat dir (cdr (assoc 1 data)))))
               (setq i (1+ i))
               )
             )
           )
         )
       (progn
         (initget 1 "Y N y n Yes No yes no YES NO")
         (setq answ (getkword "\nThe selected entity has been drawn from top-to-bottom. Do you want to reverse direction? [Yes/No]"))
         (if (or (= answ "Y") (= answ "y") (= answ "Yes") (= answ "yes") (= answ "YES"))
           (progn
             (command "._reverse" ename "")
             (princ "\nThe selected entity has changed direction from bottom-to-top.")
             (princ)
             (initget 1 "- +")
             (setq dir (getkword "\nChoose a side for offset [+ Left/- Right]:"))
             (princ)
             (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
             (terpri)
             (setq ss (ssget '((0 . "TEXT,MTEXT"))))
             (setq len (sslength ss))
             (setq i 0)
             (while (< i len)
               (setq data (entget (ssname ss i)))
               (vla-Offset (vlax-ename->vla-object ename) (atof (strcat dir (cdr (assoc 1 data)))))
               (setq i (1+ i))
               )
             )
           (progn
             (prompt "\nThe selected entity retains the current direction from top-to-bottom.")
             (princ)
             (initget 1 "- +")
             (setq dir (getkword "\nChoose a side for offset [- Left/+ Right]:"))
             (princ)
             (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
             (terpri)
             (setq ss (ssget '((0 . "TEXT,MTEXT"))))
             (setq len (sslength ss))
             (setq i 0)
             (while (< i len)
               (setq data (entget (ssname ss i)))
               (vla-Offset (vlax-ename->vla-object ename) (atof (strcat dir (cdr (assoc 1 data)))))
               (setq i (1+ i))
               )
             )
           )
         )
       )
     )
    ((= "LWPOLYLINE" (cdr (assoc 0 (entget ename))))
     (setq spt (vlax-curve-getStartPoint (vlax-ename->vla-object ename)))
     (setq ept (vlax-curve-getEndPoint (vlax-ename->vla-object ename)))
     (if (> (cadr ept) (cadr spt))
       (progn
         (initget 1 "Y N y n Yes No yes no YES NO")
         (setq answ (getkword "\nThe selected entity has been drawn from bottom-to-top. Do you want to reverse direction? [Yes/No]"))
         (if (or (= answ "Y") (= answ "y") (= answ "Yes") (= answ "yes") (= answ "YES"))
           (progn
             (command "._reverse" ename "")
             (princ "\nThe selected entity has changed direction from top-to-bottom.")
             (princ)
             (initget 1 "- +")
             (setq dir (getkword "\nChoose a side for offset [+ Left/- Right]:"))
             (princ)
             (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
             (terpri)
             (setq ss (ssget '((0 . "TEXT,MTEXT"))))
             (setq len (sslength ss))
             (setq i 0)
             (while (< i len)
               (setq data (entget (ssname ss i)))
               (vla-Offset (vlax-ename->vla-object ename) (atof (strcat dir (cdr (assoc 1 data)))))
               (setq i (1+ i))
               )
             )
           (progn
             (prompt "\nThe selected entity retains the current direction from bottom-to-top.")
             (princ)
             (initget 1 "- +")
             (setq dir (getkword "\nChoose a side for offset [- Left/+ Right]:"))
             (princ)
             (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
             (terpri)
             (setq ss (ssget '((0 . "TEXT,MTEXT"))))
             (setq len (sslength ss))
             (setq i 0)
             (while (< i len)
               (setq data (entget (ssname ss i)))
               (vla-Offset (vlax-ename->vla-object ename) (atof (strcat dir (cdr (assoc 1 data)))))
               (setq i (1+ i))
               )
             )
           )
         )
       (progn
         (initget 1 "Y N y n Yes No yes no YES NO")
         (setq answ (getkword "\nThe selected entity has been drawn from top-to-bottom. Do you want to reverse direction? [Yes/No]"))
         (if (or (= answ "Y") (= answ "y") (= answ "Yes") (= answ "yes") (= answ "YES"))
           (progn
             (command "._reverse" ename "")
             (princ "\nThe selected entity has changed direction from bottom-to-top.")
             (princ)
             (initget 1 "- +")
             (setq dir (getkword "\nChoose a side for offset [- Left/+ Right]:"))
             (princ)
             (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
             (terpri)
             (setq ss (ssget '((0 . "TEXT,MTEXT"))))
             (setq len (sslength ss))
             (setq i 0)
             (while (< i len)
               (setq data (entget (ssname ss i)))
               (vla-Offset (vlax-ename->vla-object ename) (atof (strcat dir (cdr (assoc 1 data)))))
               (setq i (1+ i))
               )
             )
           (progn
             (prompt "\nThe selected entity retains the current direction from top-to-bottom.")
             (princ)
             (initget 1 "- +")
             (setq dir (getkword "\nChoose a side for offset [+ Left/- Right]:"))
             (princ)
             (prompt "\nSelect the TEXT or MTEXT with numbers for offset:")
             (terpri)
             (setq ss (ssget '((0 . "TEXT,MTEXT"))))
             (setq len (sslength ss))
             (setq i 0)
             (while (< i len)
               (setq data (entget (ssname ss i)))
               (vla-Offset (vlax-ename->vla-object ename) (atof (strcat dir (cdr (assoc 1 data)))))
               (setq i (1+ i))
               )
             )
           )
         )
       )
     )
    )
  (setvar "osmode" old_osm)
  (princ (strcat "\nThe " (cdr (assoc 0 (entget ename))) " is offseted " (rtos len 2 0) " times."))
  (princ)
)

 

Edited by marko_ribar
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...