Create layer with true Color in Lisp

Create layer with true Color in Lisp

Anonymous
Not applicable
9,592 Views
25 Replies
Message 1 of 26

Create layer with true Color in Lisp

Anonymous
Not applicable

I have a routine that creates layers & assigns the color & linetype but now i have to create a few that have the true color instead of the standard autocad color index such as "0-255". Normally i would create a layer, assign it color 4 with a continuous linetype. How can i create a layer & assign it the color of "255,209,0" in lisp?

 

Here is a sample:

 

("K-BEV" "4" "CONTINUOUS")
("K-BEV-MISC" "11" "CONTINUOUS")
("K-CENT-CKEP" "4" "CONTINUOUS")
("K-CENT-XXEX" "4" "CONTINUOUS")
("K-CENT-XXXP" "4" "CONTINUOUS")
("K-CHAS-CKEP" "4" "CONTINUOUS")
("K-DEMO" "255,209,0" "HIDDEN4")

0 Likes
Accepted solutions (1)
9,593 Views
25 Replies
Replies (25)
Message 2 of 26

hak_vz
Advisor
Advisor

 

("K-BEV" "4" "CONTINUOUS")
("K-BEV-MISC" "11" "CONTINUOUS")
("K-CENT-CKEP" "4" "CONTINUOUS")
("K-CENT-XXEX" "4" "CONTINUOUS")
("K-CENT-XXXP" "4" "CONTINUOUS")
("K-CHAS-CKEP" "4" "CONTINUOUS")
("K-DEMO" "255,209,0" "HIDDEN4")

 


(defun truecolor (r g b)
 (+ (lsh (fix r) 16)
    (lsh (fix g) 8)
    (fix b)
 )
)

(defun create_layer (name linetype r g b)
  (setq lyr (tblsearch "layer" name) col (truecolor r g b) )
  (if (not lyr)
    (entmake
      (list (cons 0 "layer")
      (cons 100 "acdbsymboltablerecord")
      (cons 100 "acdblayertablerecord")
      (cons 2 name)
      (cons 6 linetype)
      (cons 62 198)
      (cons 420 col)
      (cons 70 0)))
    )
  (princ)
)

Usage:

(create_layer "K-DEMO" "HIDDEN4" 255 209 0)

I hope that's what you looking for!

At the time of layer creation you should have line type definition loaded.

If not use

 

(setvar "expert" 3)
(command "-linetype" "load" "*" "acad.lin" "")   ; or other

 

 

 

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 26

Anonymous
Not applicable

it might be but i do not understand all of the code. It looks like you are creating an entity with entmake & creating a list with some cons cells. What turns the layer color into 255,209,0 & what applies that to K-DEMO? Would i have to duplicate this code for the othe 3 layers that i need to have the true colors? I need to create these layers:

 

LAYER:                       COLOR          LINETYPE

K-DEMO                    255,209,0     HIDDEN 4

K-EQPM                     0,33,235      CONTINUOUS

K-EQPM-OPTIONAL   51,204,9      CONTINUOUS

K-EQPM-RELO           244,47,21    CONTINUOUS

 

 

0 Likes
Message 4 of 26

ronjonp
Advisor
Advisor

Try something like this:

(defun _addlayer (name color ltype plot / _rgb lt)
  (defun _rgb (l) (+ (lsh (fix (car l)) 16) (lsh (fix (cadr l)) 8) (fix (caddr l))))
  (cond	((not (tblsearch "layer" name))
	 (entmakex (list '(0 . "LAYER")
			 '(100 . "AcDbSymbolTableRecord")
			 '(100 . "AcDbLayerTableRecord")
			 '(70 . 0)
			 (cons 2 name)
			 (if (listp color)
			   (cons 420 (_rgb color))
			   (cons 62 color)
			 )
			 (cons 6
			       (if (tblsearch "ltype" ltype)
				 ltype
				 "continuous"
			       )
			 )
			 (cons 290 plot)
			 ;;1 = plottable 0 = not=plottable
		   )
	 )
	)
	((tblobjname "layer" name))
  )
)
;; (_addlayer "NewLayerName" '(69 69 69) "3Dash2" 1)
;; (_addlayer "NewLayerName2" 169 "3Dash2" 1)
Message 5 of 26

Anonymous
Not applicable

Would i be able to apply this to my existing routine? I apologize for my lack of knowledge, i am still trying to learn lisp. Here is how we currently create our layers

0 Likes
Message 6 of 26

ronjonp
Advisor
Advisor
Accepted solution

Something like this should work:

(defun _addlayer (name color ltype plot / _rgb lt)
  (defun _rgb (l) (+ (lsh (fix (car l)) 16) (lsh (fix (cadr l)) 8) (fix (caddr l))))
  (cond	((not (tblsearch "layer" name))
	 (entmakex (list '(0 . "LAYER")
			 '(100 . "AcDbSymbolTableRecord")
			 '(100 . "AcDbLayerTableRecord")
			 '(70 . 0)
			 (cons 2 name)
			 (if (listp color)
			   (cons 420 (_rgb color))
			   (cons 62 color)
			 )
			 (cons 6
			       (if (tblsearch "ltype" ltype)
				 ltype
				 "continuous"
			       )
			 )
			 (cons 290 plot)
			 ;;1 = plottable 0 = not=plottable
		   )
	 )
	)
	((tblobjname "layer" name))
  )
)
(mapcar	'(lambda (x) (_addlayer (car x) (cadr x) (caddr x) (last x)))
	'(("0" 9 "CONTINUOUS" 1)
	      ;; ** Example to create RGB layer **
	      ("A-ADA-ACC-EXST_RGB" (55 65 75) "CONTINUOUS" 1)
	      ("A-ADA-ACC-EXST" 9 "CONTINUOUS" 1)
	      ("A-ADA-ACC-NEW" 4 "CONTINUOUS" 1)
	      ("A-ADA-CLEAR" 223 "HIDDEN2" 1)
	      ("A-ADA-CLEAR-FIXT" 223 "HIDDEN2" 1)
	      ("A-ANNO-DIMS" 31 "CONTINUOUS" 1)
	      ("A-ANNO-REVS" 22 "CONTINUOUS" 1)
	      ("A-ANNO-TEXT" 31 "CONTINUOUS" 1)
	      ("A-ANNO-TTLB" 230 "CONTINUOUS" 1)
	      ("A-AREA-GROSS" 2 "CONTINUOUS" 1)
	      ("A-AREA-WORK" 252 "CONTINUOUS" 1)
	      ("A-CLNG-DEMO" 2 "HIDDEN2" 1)
	      ("A-CLNG-GRID" 9 "CONTINUOUS" 1)
	      ("A-CLNG-GRID-EXST" 9 "CONTINUOUS" 1)
	      ("A-CLNG-GRID-PATT" 143 "CONTINUOUS" 1)
	      ("A-CLNG-MISC" 3 "CONTINUOUS" 1)
	      ("A-CLNG-SHADE" 252 "CONTINUOUS" 1)
	      ("A-CLNG-SOFFIT-EXST" 4 "HIDDEN2" 1)
	      ("A-CLNG-SOFFIT-NEW" 3 "HIDDEN2" 1)
	      ("A-CNTR" 4 "CONTINUOUS" 1)
	      ("A-CNTR-NEW" 4 "CONTINUOUS" 1)
	      ("A-DEMO-GLAZ" 2 "HIDDEN2" 1)
	      ("A-DEMO-ITEM" 2 "HIDDEN2" 1)
	      ("A-DEMO-WALL" 2 "HIDDEN2" 1)
	      ("A-DET-HEAVY" 6 "CONTINUOUS" 1)
	      ("A-DET-LIGHT" 13 "CONTINUOUS" 1)
	      ("A-DET-MEDIUM" 3 "CONTINUOUS" 1)
	      ("A-DET-PATT" 143 "CONTINUOUS" 1)
	      ("A-DET-XHEAVY" 5 "CONTINUOUS" 1)
	      ("A-DET-XLIGHT" 9 "CONTINUOUS" 1)
	      ("A-DOOR-EXT-EXST" 3 "CONTINUOUS" 1)
	      ("A-DOOR-EXT-NEW" 14 "CONTINUOUS" 1)
	      ("A-DOOR-INT-EXST" 4 "CONTINUOUS" 1)
	      ("A-DOOR-INT-NEW" 12 "CONTINUOUS" 1)
	      ("A-ESD-DEMO" 2 "HIDDEN2" 1)
	      ("A-ESD-EXST" 163 "CONTINUOUS" 1)
	      ("A-ESD-GRID" 9 "CENTER2" 1)
	      ("A-ESD-GRID-IDEN" 31 "CONTINUOUS" 1)
	      ("A-ESD-HEAVY" 6 "CONTINUOUS" 1)
	      ("A-ESD-LIGHT" 13 "CONTINUOUS" 1)
	      ("A-ESD-MEDIUM" 3 "CONTINUOUS" 1)
	      ("A-ESD-PATT" 143 "CONTINUOUS" 1)
	      ("A-ESD-XHEAVY" 5 "CONTINUOUS" 1)
	      ("A-ESD-XLIGHT" 9 "CONTINUOUS" 1)
	      ("A-FIXT-EQPM" 9 "CONTINUOUS" 1)
	      ("A-FIXT-FLOR-EXST" 9 "CONTINUOUS" 1)
	      ("A-FIXT-FLOR-NEW" 4 "CONTINUOUS" 1)
	      ("A-FIXT-SIGN" 4 "CONTINUOUS" 1)
	      ("A-FLOR-AISLE" 143 "CONTINUOUS" 1)
	      ("A-FLOR-OTLN" 4 "CONTINUOUS" 1)
	      ("A-FLOR-PATT" 143 "CONTINUOUS" 1)
	      ("A-FLOR-RAIL" 9 "CONTINUOUS" 1)
	      ("A-GLAZ-EXST" 9 "CONTINUOUS" 1)
	      ("A-GLAZ-INT-EXST" 9 "CONTINUOUS" 1)
	      ("A-GLAZ-INT-NEW" 11 "CONTINUOUS" 1)
	      ("A-GLAZ-NEW" 11 "CONTINUOUS" 1)
	      ("A-GLAZ-SILL-EXST" 15 "CONTINUOUS" 1)
	      ("A-GLAZ-SILL-INT-EXST" 15 "CONTINUOUS" 1)
	      ("A-GLAZ-SILL-INT-NEW" 11 "CONTINUOUS" 1)
	      ("A-GLAZ-SILL-NEW" 11 "CONTINUOUS" 1)
	      ("A-ITEM-NO-PLOT" 223 "CONTINUOUS" 1)
	      ("A-ROOF-CNPY-NEW" 4 "CONTINUOUS" 1)
	      ("A-ROOF-EQPM" 9 "CONTINUOUS" 1)
	      ("A-ROOF-GUTTER" 9 "CONTINUOUS" 1)
	      ("A-ROOF-LADR-EXT" 9 "CONTINUOUS" 1)
	      ("A-ROOF-LADR-INT" 9 "CONTINUOUS" 1)
	      ("A-ROOF-OTLN" 3 "HIDDEN2" 1)
	      ("A-ROOF-OTLN-DEMO" 2 "HIDDEN2" 1)
	      ("A-ROOF-OTLN-EXST" 143 "HIDDEN2" 1)
	      ("A-ROOF-PARA" 2 "CONTINUOUS" 1)
	      ("A-ROOF-PATT" 143 "CONTINUOUS" 1)
	      ("A-ROOF-SCREEN" 9 "CONTINUOUS" 1)
	      ("A-ROOF-SHADE" 252 "CONTINUOUS" 1)
	      ("A-ROOF-SIGN-NEW" 4 "CONTINUOUS" 1)
	      ("A-ROOF-SLOP" 9 "CONTINUOUS" 1)
	      ("A-STAIR-RAIL" 9 "CONTINUOUS" 1)
	      ("A-STAIR-RAIL-NEW" 9 "CONTINUOUS" 1)
	      ("A-STAIR-RISER" 2 "HIDDEN2" 1)
	      ("A-STAIR-RISER-NEW" 2 "HIDDEN2" 1)
	      ("A-STAIR-TREAD" 2 "CONTINUOUS" 1)
	      ("A-STAIR-TREAD-NEW" 2 "CONTINUOUS" 1)
	      ("A-WALL-EXT-EXST" 7 "CONTINUOUS" 1)
	      ("A-WALL-EXT-FNSH" 4 "CONTINUOUS" 1)
	      ("A-WALL-EXT-NEW" 6 "CONTINUOUS" 1)
	      ("A-WALL-HEAD" 3 "HIDDEN2" 1)
	      ("A-WALL-INT-EXST" 7 "CONTINUOUS" 1)
	      ("A-WALL-INT-FNSH" 3 "CONTINUOUS" 1)
	      ("A-WALL-INT-NEW" 6 "CONTINUOUS" 1)
	      ("A-WALL-LOW-EXST" 9 "CONTINUOUS" 1)
	      ("A-WALL-LOW-NEW" 11 "CONTINUOUS" 1)
	      ("A-WALL-LOW-PATT" 143 "CONTINUOUS" 1)
	      ("A-WALL-OVHD-NEW" 3 "HIDDEN2" 1)
	      ("A-WALL-PATT" 143 "CONTINUOUS" 1)
	      ("A-WALL-PRHT" 3 "CONTINUOUS" 1)
	      ("A-WALL-SHADE" 252 "CONTINUOUS" 1)
	      ("A-WALL-SHADE-INT" 252 "CONTINUOUS" 1)
	      ("A-WALL-STUD" 4 "CONTINUOUS" 1)
	      ("A-WALL-UNDER" 4 "HIDDEN2" 1)
	      ("C-PKNG-AREA-CURB" 15 "CONTINUOUS" 1)
	      ("C-PKNG-AREA-IMP" 13 "CONTINUOUS" 1)
	      ("C-PKNG-AREA-LAND" 11 "CONTINUOUS" 1)
	      ("C-PKNG-AREA-PER" 15 "CONTINUOUS" 1)
	      ("C-PKNG-CURB-EXST" 4 "CONTINUOUS" 1)
	      ("C-PKNG-CURB-NEW" 3 "CONTINUOUS" 1)
	      ("C-PKNG-CURB-PATT" 143 "CONTINUOUS" 1)
	      ("C-PKNG-CURB-SHADE" 252 "CONTINUOUS" 1)
	      ("C-PKNG-LAND-EXST" 4 "CONTINUOUS" 1)
	      ("C-PKNG-LAND-NEW" 3 "CONTINUOUS" 1)
	      ("C-PKNG-STRP-EXST" 9 "CONTINUOUS" 1)
	      ("C-PKNG-STRP-NEW" 9 "CONTINUOUS" 1)
	      ("C-SITE-CARS" 9 "CONTINUOUS" 1)
	      ("C-SITE-DEMO-ITEM" 2 "HIDDEN2" 1)
	      ("C-SITE-EQPM" 7 "CONTINUOUS" 1)
	      ("C-SITE-PATT" 143 "CONTINUOUS" 1)
	      ("C-SITE-PROPLINE" 2 "DASHDOT" 1)
	      ("C-SITE-UTILITIES-EXST" 4 "HIDDEN2" 1)
	      ("C-SITE-UTILITIES-NEW" 3 "HIDDEN2" 1)
	      ("C-SITE-SHADE" 252 "CONTINUOUS" 1)
	      ("C-SITE-SIGN" 2 "CONTINUOUS" 1)
	      ("DEFPOINTS" 223 "CONTINUOUS" 1)
	      ("E-CCTV" 3 "CONTINUOUS" 1)
	      ("E-COND" 3 "CONTINUOUS" 1)
	      ("E-HVAC-EQP" 2 "CONTINUOUS" 1)
	      ("E-IT" 3 "CONTINUOUS" 1)
	      ("E-IT-POWR" 3 "CONTINUOUS" 1)
	      ("E-IT-TEXT" 31 "CONTINUOUS" 1)
	      ("E-LGHT" 2 "CONTINUOUS" 1)
	      ("E-LGHT-IDEN" 31 "CONTINUOUS" 1)
	      ("E-LGHT-ROOF" 2 "CONTINUOUS" 1)
	      ("E-LGHT-SOFF" 2 "CONTINUOUS" 1)
	      ("E-LITE-EMER" 3 "CONTINUOUS" 1)
	      ("E-LITE-EXT-EXST" 3 "CONTINUOUS" 1)
	      ("E-LITE-EXT-NEW" 3 "CONTINUOUS" 1)
	      ("E-LITE-EXT-ROOF" 3 "CONTINUOUS" 1)
	      ("E-LITE-FIXT-KITCHEN" 9 "CONTINUOUS" 1)
	      ("E-LITE-FLUR" 3 "CONTINUOUS" 1)
	      ("E-LITE-FLUR-EXST" 9 "CONTINUOUS" 1)
	      ("E-LITE-IDEN" 31 "CONTINUOUS" 1)
	      ("E-LITE-NOTE" 31 "CONTINUOUS" 1)
	      ("E-LITE-SECU" 6 "CONTINUOUS" 1)
	      ("E-LITE-SITE-NEW" 3 "CONTINUOUS" 1)
	      ("E-LITE-TRAC" 3 "CONTINUOUS" 1)
	      ("E-LITE-WIRE" 31 "CONTINUOUS" 1)
	      ("E-PNL" 3 "CONTINUOUS" 1)
	      ("E-POWR" 3 "CONTINUOUS" 1)
	      ("E-POWR-ROOF" 3 "CONTINUOUS" 1)
	      ("E-POWR-SWITCH" 3 "CONTINUOUS" 1)
	      ("E-POWR-WIRE" 2 "CONTINUOUS" 1)
	      ("E-PPWR-DIMS" 4 "CONTINUOUS" 1)
	      ("E-PPWR-ROOF-TEXT" 31 "CONTINUOUS" 1)
	      ("E-PPWR-SYMB" 3 "CONTINUOUS" 1)
	      ("E-PPWR-TEXT" 31 "CONTINUOUS" 1)
	      ("E-ROOF-NOTE" 31 "CONTINUOUS" 1)
	      ("E-ROOF-WIRE" 31 "CONTINUOUS" 1)
	      ("E-SITE-POWR" 3 "CONTINUOUS" 1)
	      ("E-SITE-POWR-TEXT" 31 "CONTINUOUS" 1)
	      ("E-SOUN" 3 "CONTINUOUS" 1)
	      ("E-SWCH" 3 "CONTINUOUS" 1)
	      ("F-ALRM-NOTE" 31 "CONTINUOUS" 1)
	      ("F-FIXT" 4 "CONTINUOUS" 1)
	      ("F-PROT-EQPM" 3 "CONTINUOUS" 1)
	      ("F-SPRN" 3 "CONTINUOUS" 1)
	      ("K-EQPH-CKXX" 4 "CONTINUOUS" 1)
	      ("K-EQPH-XXEP" 4 "CONTINUOUS" 1)
	      ("K-EQPH-XXEX" 4 "PHANTOM" 1)
	      ("K-EQPM-BLOK" 4 "CONTINUOUS" 1)
	      ("K-EQPM-BLOK-EXST" 255 "CONTINUOUS" 1)
	      ("K-EQPM-CASH" 4 "CONTINUOUS" 1)
	      ("K-EQPM-CKXX" 4 "CONTINUOUS" 1)
	      ("K-EQPM-CURB" 4 "CONTINUOUS" 1)
	      ("K-EQPM-EXST" 252 "CONTINUOUS" 1)
	      ("K-EQPM-GRILL" 4 "CONTINUOUS" 1)
	      ("K-EQPM-IDEN" 31 "CONTINUOUS" 1)
	      ("K-EQPM-MENU" 4 "HIDDEN2" 1)
	      ("K-EQPM-MISC" 11 "CONTINUOUS" 1)
	      ("K-EQPM-NEW" 4 "CONTINUOUS" 1)
	      ("K-EQPM-OPTIONAL-XXEP" 82 "PHANTOM4" 1)
	      ("K-EQPM-POS" 4 "CONTINUOUS" 1)
	      ("K-EQPM-RELO" 1 "CONTINUOUS" 1)
	      ("K-EQPM-RELO-XXEP" 1 "CONTINUOUS" 1)
	      ("K-EQPM-SAFE" 4 "CONTINUOUS" 1)
	      ("K-EQPM-XXEP" 170 "CONTINUOUS" 1)
	      ("K-EQPO-CKEP" 4 "CONTINUOUS" 1)
	      ("K-EQPO-CKEX" 4 "CONTINUOUS" 1)
	      ("K-EQPO-CKXX" 4 "CONTINUOUS" 1)
	      ("K-FRZH-XXEP" 4 "CONTINUOUS" 1)
	      ("K-FRZR-CKXX" 4 "CONTINUOUS" 1)
	      ("K-FRZR-CKXX-DOOR" 4 "CONTINUOUS" 1)
	      ("K-PCVR-DIMS" 4 "CONTINUOUS" 1)
	      ("K-PCVR-SYMB" 4 "CONTINUOUS" 1)
	      ("K-PCVR-TEXT" 4 "CONTINUOUS" 1)
	      ("K-PKIT-DIMS" 4 "CONTINUOUS" 1)
	      ("K-PKIT-SYMB" 3 "CONTINUOUS" 1)
	      ("K-PKIT-TEXT" 3 "CONTINUOUS" 1)
	      ("K-ROOF-EQPM-NEW" 3 "CONTINUOUS" 1)
	      ("M-ANNO-DIMS" 31 "CONTINUOUS" 1)
	      ("M-ANNO-TEXT" 31 "CONTINUOUS" 1)
	      ("M-CHAS-CENT" 2 "CENTER2" 1)
	      ("M-DUCT" 2 "CONTINUOUS" 1)
	      ("M-DUCT-CENT" 4 "CENTER8" 1)
	      ("M-DUCT-CENT-EXST" 2 "CENTER8" 1)
	      ("M-DUCT-CENT-NEW" 2 "CENTER8" 1)
	      ("M-DUCT-DMPR" 2 "CONTINUOUS" 1)
	      ("M-DUCT-FITT" 3 "CONTINUOUS" 1)
	      ("M-DUCT-FLEX" 2 "CONTINUOUS" 1)
	      ("M-DUCT-HOOD" 2 "CONTINUOUS" 1)
	      ("M-DUCT-HOOD-EXST" 2 "CONTINUOUS" 1)
	      ("M-DUCT-HOOD-NEW" 2 "CONTINUOUS" 1)
	      ("M-DUCT-HOOD-RELO" 2 "CONTINUOUS" 1)
	      ("M-DUCT-IDEN" 3 "CONTINUOUS" 1)
	      ("M-DUCT-INSL" 2 "CONTINUOUS" 1)
	      ("M-DUCT-NOTE" 31 "CONTINUOUS" 1)
	      ("M-FITT" 6 "CONTINUOUS" 1)
	      ("M-HOOD" 2 "CONTINUOUS" 1)
	      ("M-HOOD-DUCT" 2 "CONTINUOUS" 1)
	      ("M-HVAC-CDFF" 2 "CONTINUOUS" 1)
	      ("M-HVAC-CDFF-DUCT" 2 "CONTINUOUS" 1)
	      ("M-HVAC-CDFF-NEW" 3 "CONTINUOUS" 1)
	      ("M-HVAC-CLEAR" 4 "HIDDEN2" 1)
	      ("M-HVAC-CLNG" 2 "CONTINUOUS" 1)
	      ("M-HVAC-DMPR" 5 "DGN Style 2" 1)
	      ("M-HVAC-DUCT" 5 "DGN Style 2" 1)
	      ("M-HVAC-EQPM" 8 "HIDDEN2" 1)
	      ("M-HVAC-FLOR" 2 "CONTINUOUS" 1)
	      ("M-HVAC-NOTE" 31 "CONTINUOUS" 1)
	      ("M-PHVA-DIMS" 4 "CONTINUOUS" 1)
	      ("M-PHVA-SYMB" 3 "CONTINUOUS" 1)
	      ("M-PHVA-TEXT" 3 "CONTINUOUS" 1)
	      ("M-ROOF-EQPM-CLEAR" 4 "HIDDEN2" 1)
	      ("M-ROOF-EQPM-DEMO" 7 "HIDDEN2" 1)
	      ("M-ROOF-EQPM-EXST" 7 "CONTINUOUS" 1)
	      ("M-ROOF-EQPM-EXST-CURB" 1 "HIDDEN4" 1)
	      ("M-ROOF-EQPM-EXST-DROP" 1 "HIDDEN4" 1)
	      ("M-ROOF-EQPM-IDEN" 31 "CONTINUOUS" 1)
	      ("M-ROOF-EQPM-NEW" 3 "CONTINUOUS" 1)
	      ("M-ROOF-EQPM-NEW-CURB" 3 "HIDDEN4" 1)
	      ("M-ROOF-EQPM-NEW-DROP" 3 "HIDDEN4" 1)
	      ("M-ROOF-EQPM-TEXT" 31 "CONTINUOUS" 1)
	      ("M-ROOF-NOTE" 31 "CONTINUOUS" 1)
	      ("P-CENT" 4 "CONTINUOUS" 1)
	      ("P-DOMW-COLD" 160 "DOMESTIC_COLD_WATER" 1)
	      ("P-DOMW-COLD-N" 160 "DOMESTIC_COLD_WATER" 1)
	      ("P-DOMW-FILT" 161 "CONTINUOUS" 1)
	      ("P-DOMW-FILT-N" 161 "CONTINUOUS" 1)
	      ("P-DOMW-FIXT" 4 "CONTINUOUS" 1)
	      ("P-DOMW-H110" 210 "2DASHES" 1)
	      ("P-DOMW-H110-N" 210 "2DASHES" 1)
	      ("P-DOMW-H140" 20 "DOMESTIC_HOT_WATER" 1)
	      ("P-DOMW-H140-N" 20 "DOMESTIC_HOT_WATER" 1)
	      ("P-DOMW-NOTE" 31 "CONTINUOUS" 1)
	      ("P-FIXT" 4 "CONTINUOUS" 1)
	      ("P-FIXT-ABOV" 4 "CONTINUOUS" 1)
	      ("P-FIXT-EXST" 9 "CONTINUOUS" 1)
	      ("P-FIXT-FILT" 3 "CONTINUOUS" 1)
	      ("P-FIXT-NEW" 4 "CONTINUOUS" 1)
	      ("P-FIXT-NOTE" 31 "CONTINUOUS" 1)
	      ("P-FIXT-RELO" 4 "CONTINUOUS" 1)
	      ("P-FIXT-XXEX" 4 "CONTINUOUS" 1)
	      ("P-GAS" 4 "CONTINUOUS" 1)
	      ("P-GAS-FIXT" 4 "CONTINUOUS" 1)
	      ("P-GAS-NOTE" 31 "CONTINUOUS" 1)
	      ("P-PFLR-DIMS" 4 "CONTINUOUS" 1)
	      ("P-PFLR-LEAD" 4 "CONTINUOUS" 1)
	      ("P-PFLR-SYMB" 3 "CONTINUOUS" 1)
	      ("P-PFLR-TEXT" 3 "CONTINUOUS" 1)
	      ("P-PLMB" 3 "CONTINUOUS" 1)
	      ("P-PLMB-ROOF" 3 "CONTINUOUS" 1)
	      ("P-PLMB-ROUGH" 3 "CONTINUOUS" 1)
	      ("P-PLMB-SERV-GAS" 44 "PHANTOM4" 1)
	      ("P-PLMB-SERV-SANG" 191 "UNDERGROUND_GSANITARY" 1)
	      ("P-PLMB-SERV-SANS" 190 "UNDERGROUND_SANITARY" 1)
	      ("P-PLMB-SERV-VENT" 2 "CONTINUOUS" 1)
	      ("P-PLMB-SERV-WTR-COLD" 160 "CENTER2" 1)
	      ("P-PLMB-SERV-WTR-COLDF" 161 "CENTER4" 1)
	      ("P-PLMB-SERV-WTR-HOT" 20 "HIDDEN2" 1)
	      ("P-PLMB-SERV-WTR-HOTT" 210 "HIDDEN4" 1)
	      ("P-PLMB-SERV-STRM" 160 "CENTER2" 1)
	      ("P-ROOF-VENT" 3 "CONTINUOUS" 1)
	      ("P-SAN-FIXT" 4 "CONTINUOUS" 1)
	      ("P-SAN-NOTE" 31 "CONTINUOUS" 1)
	      ("P-SANR-EQPM" 4 "CONTINUOUS" 1)
	      ("P-SANR-SYMB" 3 "CONTINUOUS" 1)
	      ("P-SLAB" 3 "CONTINUOUS" 1)
	      ("P-SODA" 190 "FENCELINE1" 1)
	      ("P-SPRK" 60 "HIDDEN4" 1)
	      ("P-SPRK-FIXT" 3 "CONTINUOUS" 1)
	      ("P-SPRK-NOTE" 31 "CONTINUOUS" 1)
	      ("P-STRM" 3 "CONTINUOUS" 1)
	      ("P-STRM-FIXT" 3 "CONTINUOUS" 1)
	      ("P-STRM-NOTE" 31 "CONTINUOUS" 1)
	      ("P-STRM-ROOF" 3 "CONTINUOUS" 1)
	      ("P-SYMB" 3 "CONTINUOUS" 1)
	      ("P-UGRD-DIMS" 4 "CONTINUOUS" 1)
	      ("P-UGRD-SYMB" 3 "CONTINUOUS" 1)
	      ("P-UGRD-TEXT" 3 "CONTINUOUS" 1)
	      ("P-VENT" 3 "CONTINUOUS" 1)
	      ("S-COLS-EXST" 2 "CONTINUOUS" 1)
	      ("S-COLS-NEW" 6 "CONTINUOUS" 1)
	      ("S-CONC-CURB" 3 "CONTINUOUS" 1)
	      ("S-CONC-CURB-PATT" 143 "CONTINUOUS" 1)
	      ("S-DEMO-ITEM" 2 "HIDDEN2" 1)
	      ("S-FLOR-BEAM-EXST" 4 "CENTER2" 1)
	      ("S-FLOR-BEAM-NEW" 10 "CENTER2" 1)
	      ("S-FLOR-FRAM-EXST" 4 "CONTINUOUS" 1)
	      ("S-FLOR-FRAM-NEW" 3 "CONTINUOUS" 1)
	      ("S-FNDN-EXST" 3 "CONTINUOUS" 1)
	      ("S-FNDN-NEW" 6 "CONTINUOUS" 1)
	      ("S-FNDN-OUTLINE" 3 "HIDDEN2" 1)
	      ("S-FNDN-PATT" 143 "CONTINUOUS" 1)
	      ("S-FOOTING-EXST" 2 "HIDDEN2" 1)
	      ("S-FOOTING-NEW" 4 "HIDDEN2" 1)
	      ("S-GRID-EXST" 9 "CENTER2" 1)
	      ("S-GRID-IDEN-EXST" 31 "CONTINUOUS" 1)
	      ("S-GRID-IDEN-NEW" 31 "CONTINUOUS" 1)
	      ("S-GRID-NEW" 11 "CENTER2" 1)
	      ("S-ROOF-BEAM-EXST" 4 "CENTER2" 1)
	      ("S-ROOF-BEAM-NEW" 10 "CENTER2" 1)
	      ("S-ROOF-FRAM-EXST" 4 "CONTINUOUS" 1)
	      ("S-ROOF-FRAM-NEW" 3 "CONTINUOUS" 1)
	      ("S-SECTY-FIXT" 3 "CONTINUOUS" 1)
	      ("S-SECTY-NOTE" 31 "CONTINUOUS" 1)
	      ("S-SLAB-LEVL" 4 "CONTINUOUS" 1)
	      ("S-WALL-FRAM-EXST" 4 "CONTINUOUS" 1)
	      ("S-WALL-FRAM-NEW" 3 "CONTINUOUS" 1)
	      ("SYMB" 3 "CONTINUOUS" 1)
	      ("TEXT" 31 "CONTINUOUS" 1)
	)
)
Message 7 of 26

Anonymous
Not applicable

Thanks,

I'm going to break this down & see if i can understand it. i appreciate the help

Message 8 of 26

hak_vz
Advisor
Advisor

@Anonymouswrote:

it might be but i do not understand all of the code. It looks like you are creating an entity with entmake & creating a list with some cons cells. What turns the layer color into 255,209,0 & what applies that to K-DEMO? Would i have to duplicate this code for the othe 3 layers that i need to have the true colors? I need to create these layers:

 

LAYER:                       COLOR          LINETYPE

K-DEMO                    255,209,0     HIDDEN 4

K-EQPM                     0,33,235      CONTINUOUS

K-EQPM-OPTIONAL   51,204,9      CONTINUOUS

K-EQPM-RELO           244,47,21    CONTINUOUS

 

 


No. I+ve created a function that looks in layers table to see if layer with a name exist. If it don't it creates new layer .

 

 

In your code insert my function and create how many layers you want by calling function

 

 

 


(create_layer "K-DEMO" "HIDDEN4" 255 209 0)
(create_layer "K-EQPM"  "CONTINUOUS" 0 33 235)
(create_layer "K-EQPM-OPTIONAL"  "CONTINUOUS" 51 204 9)     
(create_layer "K-EQPM-RELO" "continuous" 244 47 21)     

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 9 of 26

hak_vz
Advisor
Advisor

Just put my code to the top or bottom of the list in your code.

Copy code for creating those layers and

In your list delete rows that are there to create layers with truecolor.

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 10 of 26

Anonymous
Not applicable

Thanks for the help. i will print your code out  & try to understand what you did. i appreciate the help

0 Likes
Message 11 of 26

Anonymous
Not applicable

Looks like this only works if the layer is not already in the drawing. Also i discovered that if the linetype is not already in my acad.lin file it also does not work. I have had this issue before.

0 Likes
Message 12 of 26

ronjonp
Advisor
Advisor

Try this instead. Will attempt to load the linetype if found in the acad*.lin file and if the layer exists, it will update the properties.

(defun _addlayer (name color ltype plot / _loadlinetype _rgb d e)
  ;; RJP - 04.03.2018
  ;; Creates or updates a layer
  (defun _rgb (l) (+ (lsh (fix (car l)) 16) (lsh (fix (cadr l)) 8) (fix (caddr l))))
  (defun _loadlinetype (linetype / lt out)
    (cond ((tblobjname "ltype" linetype) t)
	  ((setq lt (vla-get-linetypes (vla-get-activedocument (vlax-get-acad-object))))
	   (setq out (vl-catch-all-apply
		       'vla-load
		       (list lt
			     linetype
			     (findfile (if (= 0 (getvar 'measurement))
					 "acad.lin"
					 "acadiso.lin"
				       )
			     )
		       )
		     )
	   )
	   (not (vl-catch-all-error-p out))
	  )
    )
  )
  (setq	d (apply 'append
		 (list (if (setq e (tblobjname "layer" name))
			 (entget e '("*"))
			 (list '(0 . "LAYER")
			       '(100 . "AcDbSymbolTableRecord")
			       '(100 . "AcDbLayerTableRecord")
			       '(70 . 0)
			 )
		       )
		       (list (cons 2 name)
			     (if (listp color)
			       (cons 420 (_rgb color))
			       (cons 62 color)
			     )
			     (cons 6
				   (if (_loadlinetype ltype)
				     ltype
				     "continuous"
				   )
			     )
			     (cons 290 plot)
		       )
		       ;;1 = plottable 0 = not=plottable
		 )
	  )
  )
  (if e
    (entmod d)
    (entmakex d)
  )
)
(vl-load-com)
;; (_addlayer "NewLayerName3" '(89 88 88) "Hidden2" 1)
;; (_addlayer "NewLayerName3" 7 "Foo" 0)
Message 13 of 26

Anonymous
Not applicable

yeh thanks. That's a problem that i have had. I didn't realize it until later that if you don't have the linetype defined in the acad.lin file it defaults to continuous

0 Likes
Message 14 of 26

hak_vz
Advisor
Advisor

@Anonymouswrote:

Looks like this only works if the layer is not already in the drawing. Also i discovered that if the linetype is not already in my acad.lin file it also does not work. I have had this issue before.


Yes. It only works if layer isn't in a drawing, since you can not create two layers with same name  - first row in a script (tblsearch "layer" name).

 So you have to delete rows in your script that create layers with true color I sayed.

 

About linetype.  Hidden4 is not standard definition (maybe I'm wrong). Copy its definition in acad line, or put autolisp code that I provided on the top of your list.

 

 

(setvar "expert" 3)
(command "-linetype" "load" "*" "acad.lin" "")  ; or any other linetype definition here

(defun truecolor (r g b)
 (+ (lsh (fix r) 16)
    (lsh (fix g) 8)
    (fix b)
 )
)

(defun create_layer (name linetype r g b)
  (setq lyr (tblsearch "layer" name) col (truecolor r g b) )
  (if (not lyr)
    (entmake
      (list (cons 0 "layer")
      (cons 100 "acdbsymboltablerecord")
      (cons 100 "acdblayertablerecord")
      (cons 2 name)
      (cons 6 linetype)
      (cons 62 198)
      (cons 420 col)
      (cons 70 0)))
    )
  (princ)
)

(create_layer "K-DEMO" "HIDDEN4" 255 209 0)
(create_layer "K-EQPM"  "CONTINUOUS" 0 33 235)
(create_layer "K-EQPM-OPTIONAL"  "CONTINUOUS" 51 204 9)     
(create_layer "K-EQPM-RELO" "continuous" 244 47 21) 



- Your script here



This was all you had to do.

I would create empty drawing with all layers , text sizes and so on created.

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 15 of 26

Anonymous
Not applicable

Thanks. We have a template that has everything in it but sometimes things get purged or something so this routine creates everything again. I might make this a separate routine & experiment with it. I have since convinced my coworkers to just go with index colors since that already works & it is much more simple to work with in lisp. There are still situations where i can use the true color so i would like to get something to work. For instance we do some elevations where we want to use true colors & it would be good to have something to set up everything if things get lost.

0 Likes
Message 16 of 26

hak_vz
Advisor
Advisor

I agree. I also prefer indexed colors.

In this routine that creates layer list I would also include lineweights.

Now you have all lineweights set to "default".

 

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 17 of 26

Anonymous
Not applicable

We do have some elevations that we do in color which we use the true color. We set the lineweight in our ctb file according to the color. i do have to figure out how to add some linetypes to the acad.lin file because it its a blank drawing & the line type is not in the drawing it uses the default which is continuous.

0 Likes
Message 18 of 26

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... the line type is not in the drawing it uses the default which is continuous.


In (entmake)ing a Layer [at least in Acad2016 I have here], it doesn't even do that, but simply does not create the Layer at all.  It does  at least create it, and default to Continuous if it doesn't find the specified linetype, when using (command "_.layer" "_make" ....) [or "_new"].

 

BUT another advantage of the (command)-function way is that if  the specified linetype is in acad.lin, it does not  even need to be loaded into the drawing first -- it will find it, which (entmake) isn't smart enough to do.  [That's why I said "if it doesn't find the specified linetype" above, rather than "if the linetype is not loaded."]

 

However, if you have a very large number of Layers, the (command) approach could take noticeably longer than the (entmake) approach.  That can be lessened by not doing each one separately, but applying options to comma-delimited multiple-Layer-name strings, for example in your sampling [other than the one TrueColor Layer]:

(command "_.layer"

  "_new" "K-BEV,K-BEV-MISC,K-CENT-CKEP,K-CENT-XXEX,K-CENT-XXXP,K-CHAS-CKEP"

  "_color" 4 "K-CENT-CKEP,K-CENT-XXEX,K-CENT-XXXP,K-CHAS-CKEP"

  "_color" 11 "K-BEV-MISC"

  ""

)

 

And you never have to assign  Continuous as a linetype in the (command) approach as you do with (entmake) -- only non-continuous types.

 

Another advantage is that it won't matter if a Layer is already in the drawing.

Kent Cooper, AIA
0 Likes
Message 19 of 26

ronjonp
Advisor
Advisor

This CODE here should do what you want ( RGB or index colors ).

 

;; Truecolor example
(_addlayer "NewLayerName3" '(89 88 88) "Hidden2" 1)
;; Index example .. will default to continuous linetype since 'foo' is not defined in the acad.lin and will not plot ( 0 at the end )
(_addlayer "NewLayerName3" 7 "Foo" 0)
;; Example to iterate a list
(foreach layer (list ("NewLayerName3" '(89 88 88) "Hidden2" 1)
		     ("NewLayerName4" 7 "Foo" 0)
		     ("NewLayerName5" '(0 0 255) "Dashed" 1)
	       )
  (_addlayer (car layer) (cadr layer) (caddr layer) (last layer))
)

Easy peasy 🙂

0 Likes
Message 20 of 26

hak_vz
Advisor
Advisor

OK. Before we jump into editing acad.lin

 

 

At the top of your layer generation script add next line

 

(command "-linetype" "load" "*" "acad.lin" "")

 

Or if you want to just load some lintype

 

(command "-linetype" "load" "dashed" "acad.lin" "")

(command "-linetype" "load" "border" "acad.lin" "")

 

 

Then open a new empty drawing and check if all layers are generated correctly

in regard linetype definition. When you open new drawing just few definitions are

loaded but we want to be sure that all linetype definitions are preloaded.

 

If some linetype definition is missing I'll explain how to add additional linetype

definitions to acad.lin

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.