Jump to content

Offsetting polyline to new global width


Fierce12

Recommended Posts

I'm looking for a LISP that will allow me to offset a polyline on one layer with a global width (any varying width) to another layer (a specific layer written into the code) with a global width of 0. Please help

Link to comment
Share on other sites

This .. ?

 

(defun c:Test (/ *error* w l cl)
 ;;--- Tharwat 14. May. 2013 ---;;
 (defun *error* (x)
   (if cl (setvar 'clayer cl))
   (princ "\n*Cancel*")
 )
 (setq w [color=red]1.0[/color]            [color=royalblue]; Width Value[/color]
       l [color=red]"0"[/color]        [color=royalblue] ; Layer Name[/color]
 )
 (if
   (and (if (or (eq (type w) 'INT)
                (eq (type w) 'REAL)
            )
          t
          (progn
            (alert "Width Value must be either INTER , REAL Number <!>")
            nil
          )
        )
        (if (tblsearch "LAYER" l)
          t
          (progn
            (alert "Layer name is not found in drawing <!>")
            nil
          )
        )
   )
    (progn
      (setq cl (getvar 'clayer))
      (setvar 'clayer l)
      (command "_.offset" "_Layer" "_Current" w "\\" "\\" "")
      (setvar 'clayer cl)
    )
 )
 (princ)
)

Link to comment
Share on other sites

Here's a simple sample to get you started:

 

(defun c:test (/ layer width entl dist ent pnt data)

 (setq layer "LAYER"
       width 2.
       entl  (entlast)
 )

 (initget 6)
 (if (and (setq dist (getdist "\nSpecify offset distance: "))
          (setq ent (entsel "\nSelect LWPolyline to offset: "))
          (or (eq (cdr (assoc 0 (entget (car ent)))) "LWPOLYLINE")
              (progn (princ "\nInvalid object!") nil)
          )
          (setq pnt (getpoint "\nSpecify point on side to offset: "))
     )
   (progn
     (command "_.offset" dist ent "_non" pnt "_EXIT")
     (if (not (equal entl (setq entl (entlast))))
       (entmod (subst (cons 8 layer)
                      (assoc 8 (setq data (entget entl)))
                      (subst (cons 43 width) (assoc 43 data) data)
               )
       )
     )
   )
 )
 (princ)
)

Link to comment
Share on other sites

Thanks alan! This works perfectly!

 

It's not beautiful, but it's enough to get you started. Happy coding.

Link to comment
Share on other sites

Thanks thwart! I think you were really close! Unless I was missing something, I couldn't get the global width to change. Thanks for the quick response.

Link to comment
Share on other sites

Tharwat, be careful when changing the offset command settings. You aren't changing them back to their original setting.

Link to comment
Share on other sites

Tharwat, be careful when changing the offset command settings. You aren't changing them back to their original setting.

Entirely correct , Thank you Alan for your for precious comments .:thumbsup:

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