TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: GDF on February 20, 2017, 01:21:19 PM

Title: Modify Existing Layer Properties
Post by: GDF on February 20, 2017, 01:21:19 PM
I can not get the line type to change.
Example:  (MakeModifyLayer "VP" 5 "HIDDEN" 0 T 0 "Vport Boundary Layer")
Yes, the line type is loaded.

Thanks for any help.

Code: [Select]
;;  Modified by CAB , apologies to Lee for the hack.
;;  Make or Modify a layer

(defun MakeModifyLayer ( name colour linetype lineweight willplot bitflag description / ent elst layer)
  ;; © Lee Mac 2010
  ;;  06/14/2011 CAB added ability to modify existing layer data
  (if (setq ent (tblobjname "LAYER" name))
    (progn
      (setq elst (entget ent)
            elst (subst (cons 6 (if (and linetype (tblsearch "LTYPE" linetype))
                                       linetype "CONTINUOUS")) (assoc 70 elst) elst)
            elst (if (assoc 62 elst)
                   (subst (cons 62 (if (and colour (< 0 (abs colour) 256)) colour 7)) (assoc 62 elst) elst)
                   (append elst (list (cons 62 (if (and colour (< 0 (abs colour) 256)) colour 7))))
                 )
            elst (if (assoc 70 elst) (subst (cons 70 bitflag) (assoc 70 elst) elst)
                   (append elst (list (cons 70 bitflag))))
            elst (subst (cons 290 (if willplot 1 0)) (assoc 290 elst) elst)
            elst (subst (cons 370
                          (if (minusp lineweight) -3
                            (fix
                              (* 100
                                 (if (and lineweight (<= 0.0 lineweight 2.11)) lineweight 0.0)
                              )
                             )
                          )
                        )
                     (assoc 370 elst) elst)
      )
      (entmod elst)
      (if (and description (setq layer (vlax-ename->vla-object ent)))
            (if (vlax-property-available-p layer 'Description)
              (vla-put-Description layer description)
            )
      )
    )
    (entmake
      (append
        (list
          (cons 0 "LAYER")
          (cons 100 "AcDbSymbolTableRecord")
          (cons 100 "AcDbLayerTableRecord")
          (cons 2  name)
          (cons 70 bitflag)
          (cons 290 (if willplot 1 0))
          (cons 6
            (if (and linetype (tblsearch "LTYPE" linetype))
              linetype "CONTINUOUS"
            )
          )
          (cons 62 (if (and colour (< 0 (abs colour) 256)) colour 7))
          (cons 370
            (if (minusp lineweight) -3
              (fix
                (* 100
                  (if (and lineweight (<= 0.0 lineweight 2.11)) lineweight 0.0)
                )
              )
            )
          )
        )
        (if description
          (list
            (list -3
              (list "AcAecLayerStandard" (cons 1000 "") (cons 1000 description))
            )
          )
        )
      )
    )
  ) ; endif
)
Title: Re: Modify Existing Layer Properties
Post by: Lee Mac on February 20, 2017, 01:33:45 PM
After a cursory glance, this:
Code: [Select]
(subst (cons 6 (if (and linetype (tblsearch "LTYPE" linetype))
                                       linetype "CONTINUOUS")) (assoc 70 elst) elst)

Should be:
Code: [Select]
(subst (cons 6 (if (and linetype (tblsearch "LTYPE" linetype))
                                       linetype "CONTINUOUS")) (assoc 6 elst) elst)
Title: Re: Modify Existing Layer Properties
Post by: GDF on February 20, 2017, 01:50:14 PM
Thank you Lee.
Title: Re: Modify Existing Layer Properties
Post by: GDF on February 27, 2017, 10:50:32 AM
If you go from one cad standard to another Lee's modify layer routine works fantastic. Its very simple to change those hard to modify block attributes. Here is an example of what I do:

Code: [Select]
;;changing layer standard to the following:
(defun C:FixAtt ()
    (MakeModifyLayer "A-SYMB-ROOM" 3 "continuous" 0.30 T 0 "Room Name Symbol Mark")
    (MakeModifyLayer "A-ROOM-NOTE" 2 "continuous" 0.20 T 0 "Room Note")
    (MakeModifyLayer "A-SYMB-DOOR" 30 "continuous" 0.15 T 0 "Door Symbol Mark")
    (MakeModifyLayer "A-SYMB-WDW" 30 "continuous" 0.15 T 0 "Window Symbol Mark")
    (MakeModifyLayer "A-SYMB-WDWT" 250 "continuous" 0.15 T 0 "Window Symbol Hidden Mark")

  (command "insert" (strcat "SYMRM" "=" ARCH#CUSF "Builders Plan Service/Syms/Arch_syms/" "SYMRM") ^c^c)
  (if (/= (ssget "x" '((2 . "SYMRM"))) nil)
    (command "_ATTSYNC" "select" (ssget "x" '((2 . "SYMRM"))) "yes"))
 
  (command "insert" (strcat "SYMDR" "=" ARCH#CUSF "Builders Plan Service/Syms/Arch_syms/" "SYMDR") ^c^c)
  (if (/= (ssget "x" '((2 . "SYMDR"))) nil)
    (command "_ATTSYNC" "select" (ssget "x" '((2 . "SYMDR"))) "yes"))

  (command "insert" (strcat "SYMWDW" "=" ARCH#CUSF "Builders Plan Service/Syms/Arch_syms/" "SYMWDW") ^c^c)
  (if (/= (ssget "x" '((2 . "SYMWDW"))) nil)
    (command "_ATTSYNC" "select" (ssget "x" '((2 . "SYMWDW"))) "yes"))

  (command "insert" (strcat "SYMWDW2" "=" ARCH#CUSF "Builders Plan Service/Syms/Arch_syms/" "SYMWDW2") ^c^c)
  (if (/= (ssget "x" '((2 . "SYMWDW2"))) nil)
    (command "_ATTSYNC" "select" (ssget "x" '((2 . "SYMWDW2"))) "yes")) 

  (princ)
)

Thanks again Lee
Title: Re: Modify Existing Layer Properties
Post by: ronjonp on February 27, 2017, 11:21:00 AM
Gary,

Just a quick look, but I think your code could be simplified to this.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:fixatt (/ ss)
  2.   (makemodifylayer "A-SYMB-ROOM" 3 "continuous" 0.30 t 0 "Room Name Symbol Mark")
  3.   (makemodifylayer "A-ROOM-NOTE" 2 "continuous" 0.20 t 0 "Room Note")
  4.   (makemodifylayer "A-SYMB-DOOR" 30 "continuous" 0.15 t 0 "Door Symbol Mark")
  5.   (makemodifylayer "A-SYMB-WDW" 30 "continuous" 0.15 t 0 "Window Symbol Mark")
  6.   (makemodifylayer "A-SYMB-WDWT" 250 "continuous" 0.15 t 0 "Window Symbol Hidden Mark")
  7.   (foreach block '("SYMRM" "SYMDR" "SYMWDW" "SYMWDW2")
  8.     (command "_.insert" (strcat block "=" arch#cusf "Builders Plan Service/Syms/Arch_syms/" block))
  9.     (if (setq ss (ssget "_x" (list (cons 2 block))))
  10.       (command "_ATTSYNC" "select" ss "yes")
  11.     )
  12.   )
  13.   (princ)
  14. )
Title: Re: Modify Existing Layer Properties
Post by: GDF on February 27, 2017, 11:31:46 AM
Thanks Ron
Title: Re: Modify Existing Layer Properties
Post by: ChrisCarlson on February 27, 2017, 11:39:59 AM
Just a suggestion, that routine from Lee is quite old and I think he does this on his new routines but I would add the prefix LM: to MakeModifyLayer.

Code - Auto/Visual Lisp: [Select]
  1. LM:MakeModifyLayer

This will prevent any potential future routines from having a conflict.
Title: Re: Modify Existing Layer Properties
Post by: GDF on February 27, 2017, 12:00:59 PM
Good point.

Also need to thank Alan