program to map layes color

program to map layes color

Shay.Gaghe
Advocate Advocate
785 Views
1 Reply
Message 1 of 2

program to map layes color

Shay.Gaghe
Advocate
Advocate

Hi

Im writing a program that manipulate layers by a given text file
The text file might look something like :

window,11
wall,144

 

(defun c:samifox ( / actDoc fn-data-file fp-data-file data-list )
  (vl-load-com)
  
  (setq actDoc (vla-get-activedocument (vlax-get-acad-object));; get acad refernce
        fn-data-file (findfile "map.txt"));; look for file
  (cond
    ((null fn-data-file);;if file return nil
     (princ "\nData file map.txt not found"))
    ((not (setq fp-data-file (open fn-data-file "r")))
     (princ "\nUnable to read from map.txt"))
    (t
     (while (setq data (read-line fp-data-file))
       (if (setq pos (vl-string-position (ascii ",") data))
         (setq data-list (cons (cons (substr data 1 pos) (substr data (+ 2 pos))) data-list))
       )
     )
    )
  )
  ; data integrity test
  (cond
    ((not (vl-consp data-list))
     (princ "\nNo usable layer data was found"))
    (t (mapcar 'setLayColor   (car data-list)  (cdr data-list)))
  )
  (princ)
)

(setq setLayColor(lay col / l)
      (if (tblsearch "layer" lay)
	(if (setq l (tblobjname "LAYER" lay))
	  (progn (setq l (vlax-ename->vla-object l)) (vlax-put-property l 'Color col))
	)
      )
       (princ)
  )

; error: bad argument type: listp "A-DOOR-WINDOW"

 

why do i get this error?

 

Thanks

Shay

 

 

Using Autocad 2018, Autocad Architecture.
Please accept as solution if i solved your problem
0 Likes
786 Views
1 Reply
Reply (1)
Message 2 of 2

cadffm
Consultant
Consultant

I think you postet another code.. I can not believe you will get THIS message with the posted code (but others),
so i can not explain the error-message.

 

 

 

(defun c:samifox()
  (samifox "map.txt")
)

(defun samifox ( fn-data-file / actDoc fn-data-file fp-data-file data-list )
  (vl-load-com)
  
  (setq actDoc (vla-get-activedocument (vlax-get-acad-object));; get acad refernce
        fn-data-file (findfile fn-data-file));; look for file
  (cond
    ((null fn-data-file);;if file return nil
     (princ "\nData file map.txt not found"))
    ((not (setq fp-data-file (open fn-data-file "r")))
     (princ "\nUnable to read from map.txt"))
    (t
     (while (setq data (read-line fp-data-file))
       (if (setq pos (vl-string-position (ascii ",") data))
         (setq data-list (cons (cons (substr data 1 pos) (substr data (+ 2 pos))) data-list))
         (if (/= "" data) (princ (strcat "\nInvalid mapping entry \"" data "\" in \"" fn-data-file "\"  ")))
       )
     )
    )
  )
;;; LISTs of layernames and list of colors for function setLayColor
  (mapcar '(lambda(l c) (setLayColor l c))   (mapcar 'car data-list)  (mapcar 'cdr data-list))
  (princ)
)

;;; DEFUN
(defun setLayColor (lay col / l)
      (if (tblsearch "layer" lay)
	(if (setq l (tblobjname "LAYER" lay))
	  (progn (setq l (vlax-ename->vla-object l)) (vlax-put-property l 'Color col))
	)
      )
       (princ)
)

 

Sebastian

0 Likes