Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Auto change to layer 0 and linetype

20 REPLIES 20
SOLVED
Reply
Message 1 of 21
Anonymous
1408 Views, 20 Replies

Auto change to layer 0 and linetype

Hi, anyone know how to write a lisp that when i activate it, it will change all the objects in the drawings to be change to "Layer 0" and all linetypes "Dashed" change to be "hidden"...

20 REPLIES 20
Message 2 of 21
3wood
in reply to: Anonymous

Please try CHZ20.vlx

 

3wood

CAD KITS

Message 3 of 21
_Tharwat
in reply to: Anonymous

Check this out ....

 

(defun c:Test (/ ss i sn)
  ;;; Tharwat 10. March. 2012 ;;;
  (vl-load-com)
  (if (not (tblsearch "LTYPE" "HIDDEN"))
    (vla-load
      (vla-get-Linetypes
        (vla-get-ActiveDocument
          (vlax-get-acad-object)
        )
      )
      "HIDDEN"
      "acadiso.lin"
    )
    (princ)
  )
  (defun LTYPE2Hidden (sn)
    (entupd
      (cdr
        (assoc
          -1
          (entmod
            (subst (cons 6 "HIDDEN") (assoc 6 (entget sn)) (entget sn))
          )
        )
      )
    )
  )

  (defun ChangeLayers (sn)
    (entupd
      (cdr
        (assoc -1
               (entmod
                 (subst (cons 8 "0") (assoc 8 (entget sn)) (entget sn))
               )
        )
      )
    )
  )

  (if (setq ss (ssget "_x"))
    (repeat (setq i (sslength ss))
      (setq sn (ssname ss (setq i (1- i))))
      (if (eq (cdr (assoc 6 (entget sn))) "DASHED")
        (LTYPE2Hidden sn)
      )
      (ChangeLayers sn)
    )
    (princ)
  )
  (princ)
)

 

Message 4 of 21
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

Hi, anyone know how to write a lisp that when i activate it, it will change all the objects in the drawings to be change to "Layer 0" and all linetypes "Dashed" change to be "hidden"...



Minimally tested, but I think you can do it as simply as this:

 

(defun C:Whatever (/ ss)
  (if
    (setq ss (ssget "_X" '((6 . "DASHED"))))
    (command "_.chprop" ss "" "_ltype" "HIDDEN" "")
  ); if
  (command "_.chprop" "_all" "" "_layer" "0" "")
); defun

 

[It's not necessary to ensure that the Hidden linetype is loaded -- CHPROP will find it.]

 

That won't find parts within Block definitions, and will only find things with an override Dashed linetype, not things that are Bylayer and only of Dashed linetype because that's the linetype of their Layer.  But at quick glance, it appears the same limitations are true of TharwaT313's suggestion.

 

I think you'll find similar threads in the Discussion Group with a Search, and probably something that can dig into Block definitions, change the Dashed linetype of a Layer to Hidden, etc.  The former is mildly complicated, but the latter is pretty easy, if you need to do that.

Kent Cooper, AIA
Message 5 of 21
Anonymous
in reply to: Anonymous

Dear Kent,

I just now try to modify the lisp abit, but then i not sure where is my error..Somehow i can't make all my hidden lines to be in "magenta"..Please advise where is my mistake.

 

Here is what i wish to have:

 

1) Make all objects to be in "LAYER 0" + color "BYLAYER)

2) Make all objects lineweight to be "BYLAYER"

3) Make all "DASHED" to be "HIDDEN" + "MAGENTA" color

 

Message 6 of 21
pbejse
in reply to: Anonymous


@Anonymous wrote:

Dear Kent,

 

Here is what i wish to have:

 

1) Make all objects to be in "LAYER 0" + color "BYLAYER)

2) Make all objects lineweight to be "BYLAYER"

3) Make all "DASHED" to be "HIDDEN" + "MAGENTA" color

 


Judging by the sequence you are proposing, i would assume "DASHED" and "MAGENTA" are Layer properties.

Is that correct?

 

 

Message 7 of 21
Anonymous
in reply to: pbejse

Dear pbejse

Yes, i need to change all objects in "DASHED lintype" to be change to "HIDDEN linetype" and with color properties of "MAGENTA".

Message 8 of 21
_Tharwat
in reply to: Anonymous


@Anonymous wrote:

Dear @pbejse

Yes, i need to change all objects in "DASHED lintype" to be change to "HIDDEN linetype" and with color properties of "MAGENTA".


Did not my code work for you ? or did you even see it ?

Message 9 of 21
pbejse
in reply to: Anonymous


@Anonymous wrote:

Dear pbejse

Yes, i need to change all objects in "DASHED lintype" to be change to "HIDDEN linetype" and with color properties of "MAGENTA".



Still not clear lai,

Layers with "DASHED" will be change to HIDDEN" and color to "MAGENTA"

 

I'm talking about layer properties here and not object properties.

 

as you posted before:

1) Make all objects to be in "LAYER 0" + color "BYLAYER)

2) Make all objects lineweight to be "BYLAYER"

 

I would think, there wont be any property overrides left on the drawing and ALL entity properties will be BYLAYER

 

Are we on the same page lai?

 

 

 

 

 

Message 10 of 21
Anonymous
in reply to: _Tharwat

Dear Tharwat,

Yes, i have try it before, but after a few time trys, somehow i didn't see the original "dashed" line been change to "Hidden" line..After i load the LISP, i type "TEST", then all the object properties seems no any changes..Please advise if in case i have done wrongly anythings. Thanks.

Message 11 of 21
Anonymous
in reply to: pbejse

Dear All,

Sorry if i have give any misunderstand...i have attach a sample drawing with end result that i need for a better understanding.

Message 12 of 21
pbejse
in reply to: Anonymous


@Anonymous wrote:

Dear All,

Sorry if i have give any misunderstand...i have attach a sample drawing with end result that i need for a better understanding.


The key here would be finding all Entities with an overriden linetype property of"DASHED" and change those to "HIDDEN"/"MAGENTA"

 

both codes by tharwat and kent would work then. but with this statement

1) Make all objects to be in "LAYER 0" + color "BYLAYER)  doenst jibe with the result you want as those "DASHED" lines would have a color property of "BYLAYER", so you understand my confusion.

 

so it can be as simple as this one

 

(defun C:Whatever (/ ss)
  (if
    (setq ss (ssget "_X" '((6 . "DASHED"))))
    (command "_.chprop" ss "" "_ltype" "HIDDEN" "_lweight" "bylayer" "_color" "6" "")
  )
      )

 

as you had it on your test.lsp

 

 

 

 

 

 

 

 

 

 


 

Message 13 of 21
Anonymous
in reply to: pbejse

Hi pbejse,

 

This is my final LISP...all goes good, except that somehow my hidden lines wont change to be color "6"...Where is my mistake?

 

(defun C:Whatever (/ ss)   

(if    

(setq ss (ssget "_X" '((6 . "DASHED"))))    

(command "_.chprop" ss "" "_ltype" "HIDDEN" "_lweight" "bylayer" "_color" "6" "")  

); if   (command "_.chprop" "_all" "" "_layer" "0" "_color" "bylayer" "_lweight" "bylayer" "")

); defun

Message 14 of 21
pbejse
in reply to: Anonymous


@Anonymous wrote:

Hi pbejse,

 

This is my final LISP...all goes good, except that somehow my hidden lines wont change to be color "6"...Where is my mistake?

 

(defun C:Whatever (/ ss)   

(if    

(setq ss (ssget "_X" '((6 . "DASHED"))))    

(command "_.chprop" ss "" "_ltype" "HIDDEN" "_lweight" "bylayer" "_color" "6" "")  

); if   (command "_.chprop" "_all" "" "_layer" "0" "_color" "bylayer" "_lweight" "bylayer" "")

); defun


Why you asked? because right after you change the objects on selection set ss you changed "ALL" colors to bylayer. so you see the predicament there lai.

 

but it can be done done of course 🙂

 

EDIT: but with the issues Kent pointed out earlier. this method wont work for entities inside a block nor objects NOT within the active viewport.

 

try this for now

 

(defun C:Whatever (/ ss ss2)
	(if (setq ss (ssget "_X" (list '(6 . "DASHED")(cons 410 (getvar 'Ctab)))))
            (progn
            (command "_.chprop" ss "" "_ltype" "HIDDEN" "_lweight" "bylayer" "_color" "6" "")
            (setq ss2 (ssget "_X" (list (cons 410 (getvar 'Ctab)))))
      		(repeat (setq i (sslength ss))
                              		(ssdel (ssname ss (setq i (1- i))) ss2))
      		  (command "_.chprop" ss2 "" "_layer" "0" "_color" "bylayer" "_lweight" "bylayer" "")
      		  )
            )
      )

 

 

HTH
 

Message 15 of 21
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

.... Somehow i can't make all my hidden lines to be in "magenta"..Please advise where is my mistake.

....


I think you are only missing the closing right parenthesis for the second (if) function:

 

    (command "_.chprop" ss "" "_color" "magenta" "")

  ); if

); defun

Kent Cooper, AIA
Message 16 of 21
Anonymous
in reply to: Kent1Cooper

Dear Kent,

Thanks for your advise...Anyway, to give a better understanding for everyone, i have attach along the lisp which work without problem.

Message 17 of 21
Anonymous
in reply to: Anonymous

Hi all, after sometime of using this lisp, i have tot of want to modify it abit...i wish to when i activate the lisp, it will ask me " Do you want to make changes? (Y/N)" and then i have option to choose yes or no..

 

Reason is because without this quote i have been a few time accidentally go change all my layer base on the lisp criteria and i find it quite dangerous without being inform me..Thanks.

Message 18 of 21
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

....i wish to when i activate the lisp, it will ask me " Do you want to make changes? (Y/N)" and then i have option to choose yes or no..

....


Here is one way to do that [untested]:

 

(defun C:changer (/ ss)
  (initget "Yes No")
  (if
    (=
      (getkword "\nDo you want to make changes? [Y/N] <N>: ")
      "Yes"
    ); =
    (progn
      (if
        (setq ss (ssget "_X" '((6 . "DASHED"))))
        (command "_.chprop" ss "" "_ltype" "HIDDEN" "_lweight" "bylayer" "")
      ); if
      (command "_.chprop" "_all" "" "_layer" "0" "_color" "bylayer" "_lweight" "bylayer" "")
      (if
        (setq ss (ssget "_X" '((6 . "HIDDEN"))))
        (command "_.chprop" ss "" "_color" "magenta" "_Scale" "0.6" "")
      );if
    ); progn
  ); if
); defun

Kent Cooper, AIA
Message 19 of 21
Anonymous
in reply to: Kent1Cooper

Thanks Kent,

It works fine for me at the moment..Will test it out a few more times...

Message 20 of 21
lingam2904
in reply to: Anonymous

I would like to change the linetype in the "E-Switching" layer from "Hidden" to "Continuous" by executing a lisp program. can anyone assist how to resolve the above.

 

Thank you

lingam

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost