Author Topic: Change layer properties problem  (Read 1023 times)

0 Members and 1 Guest are viewing this topic.

Jim2018

  • Mosquito
  • Posts: 16
Change layer properties problem
« on: February 17, 2022, 05:12:55 AM »
I needed a routine, either to create a new layer or to modify an existing layer and I made this one

Code - Auto/Visual Lisp: [Select]
  1. ;;; create_change_layer
  2. ;;; ------------------------------------------------------------------------------
  3. (defun create_change_layer (l_name l_linetype l_color l_status )
  4.   (cond
  5.    ((setq this_layer(tblobjname "layer" l_name))
  6.      (progn
  7.       (if (tblobjname "LTYPE" l_linetype)
  8.          (entmod (subst (cons 6  l_linetype) (assoc 6  (entget this_layer)) (entget this_layer)))
  9.          (entmod (subst (cons 6 "CONTINUOUS")(assoc 6  (entget this_layer)) (entget this_layer)))
  10.       );;;end if
  11.       (if (and (> l_color -256)(< l_color 256))
  12.          (entmod (subst (cons 62 l_color)(assoc 62 (entget this_layer)) (entget this_layer)))
  13.          (entmod (subst (cons 62 256)(assoc 62 (entget this_layer)) (entget this_layer)))
  14.       );;;endif
  15.       (entmod (subst (cons 70 l_status)(assoc 70 (entget this_layer)) (entget this_layer)))      
  16.       (entupd this_layer)
  17.       (command "regen")
  18.      );;;end progn
  19.    );;;end 1 cond
  20.    (t
  21.     (progn
  22.          (setq elist (list    (cons 0 "LAYER")
  23.                               (cons 100 "AcDbSymbolTableRecord")
  24.                               (cons 100 "AcDbLayerTableRecord")
  25.                               (cons 2 l_name)
  26.                               (cons 6
  27.                                     (cond ((if (tblobjname "LTYPE" l_linetype) l_linetype)
  28.                                           );;;end first cond
  29.                                           (t "Continuous")
  30.                                           );;;end second cond
  31.                                     ) ;;;end of conditions
  32.                               (cons 62 l_color)
  33.                               (cons 70 l_status)
  34.                      );;;end of list
  35.          );;;end of setq
  36.          (entmake elist)
  37.     );;;end progn
  38.    );;;end 2 cond
  39.   );;;end condition
  40. );;;end defunn

The problem I encounter:
When I want to change the status of an existing layer to freeze, it works.
When I want to change this layer to be active this layer does not appear even with <command “regen”>.
On the Layer Properties Manager seems to be active.
In the AutoCAD database exist with the settings I had done.
I found it, when in such a case I save the plan immediately after that procedure and when I opened the plan, that layer appeared normally with the settings that I had given.
I don't understand what is happening, I am confused, if any one knows let's help.



EDIT (John): Added code tags.
« Last Edit: February 17, 2022, 01:33:46 PM by JohnK »

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change layer properties problem
« Reply #1 on: February 17, 2022, 08:02:48 AM »
You are updating the dxf codes of the layer but you did not assign them to a variable to continue to next update and that's why your updates take a place on the last entmod function and what's worse, is that the entupd does nothing due to same issue previously described. lol

I did not try it but it should solve your issue, although you can try to write the codes in another way and you don't need all of these repeated codes / entmods nor regen command.

NOTE: You can't set any layer name on if it is Frozen.

Code - Auto/Visual Lisp: [Select]
  1. (defun create_change_layer (l_name l_linetype l_color l_status / this_layer elist)
  2.   (cond
  3.    ((setq this_layer (tblobjname "layer" l_name))
  4.      (progn
  5.       (setq elist (if (tblobjname "LTYPE" l_linetype)
  6.                     (entmod (subst (cons 6  l_linetype) (assoc 6  (entget this_layer)) (entget this_layer)))
  7.                     (entmod (subst (cons 6 "CONTINUOUS")(assoc 6  (entget this_layer)) (entget this_layer)))
  8.                     )
  9.       );;;end if
  10.       (setq elist  (if (and (> l_color -256)(< l_color 256))
  11.                      (entmod (subst (cons 62 l_color)(assoc 62 (entget this_layer)) (entget this_layer)))
  12.                      (entmod (subst (cons 62 256)(assoc 62 (entget this_layer)) (entget this_layer))))
  13.       );;;endif
  14.       (setq elist (entmod (subst (cons 70 l_status)(assoc 70 (entget this_layer)) (entget this_layer))))
  15.       (entupd elist)
  16.       (command "regen")
  17.      );;;end progn
  18.    );;;end 1 cond
  19.    (t
  20.  

Jim2018

  • Mosquito
  • Posts: 16
Re: Change layer properties problem
« Reply #2 on: February 17, 2022, 09:57:36 AM »
Thank you for your answer, but why you can't set any layer name on if it is Frozen?

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change layer properties problem
« Reply #3 on: February 17, 2022, 10:13:54 AM »
Your question should be forwarded to Autodesk and logically it should not be and further more, off layers also should not be allowed as well.

Jim2018

  • Mosquito
  • Posts: 16
Re: Change layer properties problem
« Reply #4 on: February 17, 2022, 10:30:26 AM »
ok Thank you!

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Change layer properties problem
« Reply #5 on: February 17, 2022, 10:39:48 AM »
You are welcome anytime.

Did you get the codes working the right way ?

JohnK

  • Administrator
  • Seagull
  • Posts: 10663
Re: Change layer properties problem
« Reply #6 on: February 17, 2022, 01:49:51 PM »
I'm confused by the statement: "cannot set any layer name on if it is Frozen".

Here is one of my old "make-or-modify-layer" routines from years ago. You can use this code to create/modify the layer and just set it current. ?
Code - Auto/Visual Lisp: [Select]
  1. (defun make-or-modify-layer (LNAM$ LCLR# LTYP$ LWGT# / #prog)
  2.    ;;
  3.    ;; Ex:
  4.    ;; (make-or-modify-layer "Test-Layer" 1 "Continuous" 18)
  5.    ;;  > create the layer
  6.    ;; (make-or-modify-layer "Test-Layer" 1 "Continuous" 18)
  7.    ;;  > would override the current layer def.
  8.    ;;
  9.    ;; By: John K
  10.    ;;
  11.   (if (null (tblsearch "layer" LNAM$))
  12.     (set '#prog (lambda ( x ) (entmake x)))
  13.     (set '#prog (lambda (x / ent y)
  14.                   (setq ent (entget (tblobjname "LAYER" LNAM$)))
  15.                   (foreach y x
  16.                            (if (not (member (car y) '(0 100 2)))
  17.                              (setq ent (subst y (assoc (car y) ent) ent))))
  18.                   (entmod ent) )))
  19.   (#prog
  20.    (list
  21.      (cons 0   "LAYER")
  22.      (cons 100 "AcDbSymbolTableRecord")
  23.      (cons 100 "AcDbLayerTableRecord")
  24.      (cons 2    LNAM$)
  25.      (cons 6    LTYP$)
  26.      (cons 62   LCLR#)
  27.      (cons 70   0)
  28.      (cons 290  1)
  29.      (cons 370  LWGT#)
  30.      )
  31.    )
  32.  (princ)
  33.  )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Jim2018

  • Mosquito
  • Posts: 16
Re: Change layer properties problem
« Reply #7 on: February 17, 2022, 05:46:36 PM »
Thank you for your answer.
This code is amazing!

JohnK

  • Administrator
  • Seagull
  • Posts: 10663
Re: Change layer properties problem
« Reply #8 on: February 17, 2022, 06:51:18 PM »
I'm not sure what to say; no one has ever called my code amazing and I barely get an acknowledgement most times so, you are very welcome!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Jim2018

  • Mosquito
  • Posts: 16
Re: Change layer properties problem
« Reply #9 on: February 18, 2022, 05:51:10 AM »
This is my opinion and I'm not a rookie, I deal many years with autolisp.
I have a few questions about the code but also with the autocad database with non graphical objects as layers.