Author Topic: Set to Layer - by color of entity  (Read 2509 times)

0 Members and 1 Guest are viewing this topic.

rhino

  • Guest
Set to Layer - by color of entity
« on: May 01, 2010, 12:42:16 AM »
I need a LISP that will allow the user to select entities that are drawn - these entities will be set to certain colors which will also be the same as layers created in the drawing.

The LISP needs to be able to get the color of the entity and then put it on the layer with same entity color - the color is then changed to ByLayer and the linetype ByLayer.

Entities will not be blocks.

http://www.theswamp.org/index.php?topic=28349.msg339348#msg339348

I think an extension to Ron's code is all thats required... :kewl:

Need this really bad as we have to prepare drawings to the CAD standards set by the client - very frustrating  :pissed:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Set to Layer - by color of entity
« Reply #1 on: May 01, 2010, 01:17:55 AM »
If you want this to work fast and efficient and with a reduced likelyhood of errors it's best to provide an association list of  Color.layers.

Can you complete this list ??
Code: [Select]
(setq Color_Alias_List
       (list
         (cons 1 "LayerWithColor1")
         (cons 2 "LayerWithColor2")
         ;; etc etc etc
       )
)
BUT ..
do you happen to have the same color for Layers with differing LineTypes ?? ... if so you'll need a 3 part List

Something Like
Code: [Select]
(setq Color_Alias_List
       (list
         (list 1 "CONTINUOUS" "LayerWithColor1")
         (list 1 "HIDDEN" "LayerWithColor1H")
         (list 2 "CONTINUOUS" "LayerWithColor2")
         ;; etc etc etc
       )
)

I'll wait to hear from you ..
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Set to Layer - by color of entity
« Reply #2 on: May 01, 2010, 01:31:48 AM »


And also ..
Do you want to consider which types of entitys will not change ??

You mentioned blocks,
what about any others ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Set to Layer - by color of entity
« Reply #3 on: May 01, 2010, 06:54:40 AM »
If you want this to work fast and efficient and with a reduced likelyhood of errors it's best to provide an association list of  Color.layers.

Perhaps run this at the start of the code?

Code: [Select]
(defun GetColorList ( / def c )
  (while (setq def (tblnext "LAYER" (null def)))
    (setq c
      (cons
        (cons
          (cdr (assoc 62 def))
          (cdr (assoc  2 def))
        )
        c
      )
    )
  )
  c
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Set to Layer - by color of entity
« Reply #4 on: May 01, 2010, 10:44:37 AM »


Lee, have you actually tried that on a production drawing with multiple objects with different colors, linetypes, ltscales etc ??

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Set to Layer - by color of entity
« Reply #5 on: May 01, 2010, 01:09:06 PM »
Lee, have you actually tried that on a production drawing with multiple objects with different colors, linetypes, ltscales etc ??

1) I don't have any production drawings whatsoever as I don't work in the CAD sector... 2) No, it is untested...

rhino

  • Guest
Re: Set to Layer - by color of entity
« Reply #6 on: May 01, 2010, 02:46:12 PM »
If you want this to work fast and efficient and with a reduced likelyhood of errors it's best to provide an association list of  Color.layers.

Can you complete this list ??
Code: [Select]
(setq Color_Alias_List
       (list
         (cons 1 "LayerWithColor1")
         (cons 2 "LayerWithColor2")
         ;; etc etc etc
       )
)
BUT ..
do you happen to have the same color for Layers with differing LineTypes ?? ... if so you'll need a 3 part List

Something Like
Code: [Select]
(setq Color_Alias_List
       (list
         (list 1 "CONTINUOUS" "LayerWithColor1")
         (list 1 "HIDDEN" "LayerWithColor1H")
         (list 2 "CONTINUOUS" "LayerWithColor2")
         ;; etc etc etc
       )
)

I'll wait to hear from you ..

I have not yet dived in to this shark pool fully so I did not notice the problem of having the same color but a different linetype - hence different layer.

I've attached the layer lists that they've provided us - the upside is that we are steel building manufacturers and hence would be able to get away by just using steel beam & sheeting anchor bolt etc.

to create the layers in the first place ill be using this lisp snippet:

Code: [Select]
(defun c:lay_man (/ linelist lin lay_tbl lay_list vlay)
  (vl-load-com)
;Line Load Module
  (setq linelist '(("Center" . "acadiso.lin")
                   ("Hidden" . "acadiso.lin"))
)
    (foreach  lin linelist
      (or (tblsearch "LTYPE" (car lin))
        (command "._-linetype" "_Load" (car lin) (cdr lin) "")
      )
    )
  (princ)
 
  (setq lay_tbl  (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
        lay_list '(("S-BEAM-STEL" 4 "Continuous" 2)
                    ("S-ANNO-TEXT" 131 "Continuous" 1)
           ("S-ANNO-TABL" 2 "Continuous" 1)
                    ("S-ANNO-NOTE" 71 "Continuous" 1)
                    ("S-ANNO-MARK" 52 "Continuous" 2)
                    ("S-GRID" 10 "CENTER" 0)
                  )
  )
  (foreach n lay_list
    (if (setq vlay (vla-add lay_tbl (car n)))
      (progn
(vla-put-color vlay (cadr n))
        (vla-put-linetype vlay (caddr n))
        ;(vla-put-LineWeight vlay (nth 3 n)) ;have to confirm what is meant by the values on clinet layer list for the linetypes
)
    )
  )
) ; end lay_man - using Visual Lisp Code

Thanks a bunch for helping me with this  8-)