Author Topic: Change Layer Linetype LISP  (Read 6645 times)

0 Members and 1 Guest are viewing this topic.

mdvynld85

  • Guest
Change Layer Linetype LISP
« on: April 30, 2015, 07:34:15 PM »
Hello,

I've been looking, with no luck, for a lisp that can quickly change a layers linetype without having to open the layer properties box.  I would like to select an object and then be able to change the linetype of the layer by selecting from a list of the linetypes loaded within the drawing.  It would be awesome if it could also work with objects within xrefs.

Any guidance would be appreciated - Thanks   :-)

-Kique- 

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Change Layer Linetype LISP
« Reply #1 on: April 30, 2015, 08:03:07 PM »
Where are you getting stuck?  You've already outlined the basic process:

  • Pick an object (check for actual pick)
  • Get layer of object
  • Provide user list of linetypes (check for OK/cancel)
  • Modify layer setting
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

mdvynld85

  • Guest
Re: Change Layer Linetype LISP
« Reply #2 on: May 01, 2015, 01:50:15 PM »
Yes I have the process for what I want it to do but I haven't been able to put together a lisp (I'm new to this) or find one that does that.
With the lisp I have below I'm able to enter the name of the linetype I want to use and then select the object.  It only changes the linetype of the object itself and not the layer and it doesn't work for xrefs.  It's close to what I'm looking for but not exactly.  (I found the lisp here: http://www.autolisp.com/forum/threads/774-linetype-change)

Code: [Select]
(defun c:LtChange (/ lt fnd s i sn name blocks)
  (vl-load-com)

  (if (not acdoc)
    (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
  )
  (if (and (not (eq (setq lt (getstring "\n Specify lineType :")) ""))
           (setq fnd (tblsearch "LTYPE" lt))
           (setq s (ssget "_:L"))
      )
    (repeat (setq i (sslength s))
      (setq sn (ssname s (setq i (1- i))))
      (if (not (eq (cdr (assoc 0 (entget sn))) "INSERT"))
        (vla-put-linetype (vlax-ename->vla-object sn) lt)
        (if
          (not (member (setq name (cdr (assoc 2 (entget sn)))) blocks)
          )
           (progn
             (setq blocks (cons name blocks))
             (vlax-for each (vla-item (vla-get-blocks acdoc) name)
               (vla-put-linetype each lt)
             )
           )
        )
      )
    )
    (cond ((not lt) (princ "\n LineType is nil "))
          ((not fnd)
           (princ "\n Couldn't find the Linetype or not loaded ")
          )
          (t (princ "\n Nothing has been Selected"))
    )
  )
  (vla-regen acdoc AcallViewports)
  (princ)
)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Change Layer Linetype LISP
« Reply #3 on: May 01, 2015, 02:30:57 PM »
Here's two I wrote long ago that I use quite often. DosLib is needed for the linetype one.

Code: [Select]
(defun c:CLC (/ ss color i layer lst)
  ;; Change color of selected objects' layer
  ;; Alan J. Thompson, 07.23.09 / 05.16.11 / 2014.05.21
  (if (and (setq ss (ssget))
           (setq color (acad_colordlg
                         (if (eq (sslength ss) 1)
                           (cdr (assoc 62 (tblsearch "LAYER" (cdr (assoc 8 (entget (ssname ss 0)))))))
                           1
                         )
                         nil
                       )
           )
      )
    (repeat (setq i (sslength ss))
      (if (not (member (setq layer (cdr (assoc 8 (entget (ssname ss (setq i (1- i))))))) lst))
        (vla-put-color
          (vlax-ename->vla-object (tblobjname "LAYER" (car (setq lst (cons layer lst)))))
          color
        )
      )
    )
  )
  (princ)
)




(defun c:CLL (/ ss linetype i layer lst)
  ;; Change linetype of selected objects' layer
  ;; DosLib required (dos_linetypebox)
  ;; Alan J. Thompson, 05.16.11
  (if dos_linetypebox
    (if (and (setq ss (ssget)) (setq linetype (dos_linetypebox)))
      (repeat (setq i (sslength ss))
        (if (not (member (setq layer (cdr (assoc 8 (entget (ssname ss (setq i (1- i))))))) lst))
          (vla-put-linetype
            (vlax-ename->vla-object (tblobjname "LAYER" (car (setq lst (cons layer lst)))))
            linetype
          )
        )
      )
    )
    (progn (alert "DosLib must be loaded!")
           (command "_.browser" "http://www.en.na.mcneel.com/doslib.htm")
    )
  )
  (princ)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Change Layer Linetype LISP
« Reply #4 on: May 02, 2015, 05:14:40 AM »
It would be awesome if it could also work with objects within xrefs.
For that you'd need to be able to select the nested object. I.e. instead of ssget you'd use nentsel.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Change Layer Linetype LISP
« Reply #5 on: May 04, 2015, 08:51:20 AM »
It would be awesome if it could also work with objects within xrefs.
For that you'd need to be able to select the nested object. I.e. instead of ssget you'd use nentsel.
Completely overlooked that part.
Here's one I posted a few years ago: http://www.theswamp.org/index.php?topic=32277.0
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

mdvynld85

  • Guest
Re: Change Layer Linetype LISP
« Reply #6 on: May 04, 2015, 10:09:13 AM »
The cll lisp is exactly what I was looking for.  I have never used anything with DosLib, definitely want to learn more about it.

Thank you so much for the help alanjt!  :-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Change Layer Linetype LISP
« Reply #7 on: May 04, 2015, 10:15:43 AM »
The cll lisp is exactly what I was looking for.  I have never used anything with DosLib, definitely want to learn more about it.

Thank you so much for the help alanjt!  :-)
You're welcome. :)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox