- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All -
I have a Layer Import routine that I borrowed from the brilliant Lee Mac -- where you import Layer definitions into your drawing from a CSV file. It works beautifully - EXCEPT that if any of the layer properties are modified (color, linetype, etc.) after the layer is imported from the CSV, and you re-import the layers into your drawing again from the CSV, it resets them back to their original properties as defined in the CSV.
I would like the command to function such that if it finds that the layer name already exists in the drawing, then it skips over importing it.
I thought the code I borrowed from Lee Mac was doing that.... the code is pasted below with the section I thought would have been controlling the feature I was looking for.
Any advice or direction would be much appreciated.
Thanks!
MRG
(defun RM:CSV->Layers (path / f *error* extract trim activeDoc l
layerTable layerName layerItem layerDescription
layerColor layerLinetype layerLineweight
layerPlottable layerFreeze)
;; © RenderMan 2011, CADTutor.net
;; Exampe: (RM:CSV->Layers "Z:\\my_layers_folder\\my_layers.csv")
(vl-load-com)
(if (and (findfile path)
(setq f (open path "r")))
(progn
;; Error handler
(defun *error* (msg)
(cond
((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat "\n** Error: " msg " ** ")))) ; Fatal error, display it
(if f
(close f))
(princ))
;; Line extraction sub-function
(defun extract (l /)
(substr l 1 (vl-string-search "," l)))
;; Line trim sub-function
(defun trim (v /)
(vl-string-subst "" (strcat v ",") l))
;; Main code
(vla-startundomark
(cond (activeDoc)
((setq activeDoc
(vla-get-activedocument
(vlax-get-acad-object))))))
(read-line f) ; <- Skip first line (headers)
(setq layerTable (vla-get-layers activeDoc))
;; Linetype check
;; <- Add linetype import code here, to avoid errors
(while (/= nil (setq l (read-line f)))
(progn
;; Layer check
(if (not (tblsearch "layer" (setq layerName (extract l))))
(setq layerItem (vla-add layerTable layerName))
(setq layerItem (vla-item layerTable layerName)))
;; Layer settings
(setq l (trim layerName))
(vla-put-description
layerItem
(setq layerDescription (extract l)))
(setq l (trim layerDescription))
(if (/= 7 (setq layerColor (extract l)))
(vla-put-color layerItem layerColor))
(setq l (trim layerColor))
(vla-put-linetype layerItem (setq layerLinetype (extract l)))
(setq l (trim layerLinetype))
(if (= "BYLAYER" (strcase (setq layerLineweight (extract l))))
(vla-put-lineweight layerItem aclnwtbylayer))
(setq l (trim layerLineweight))
(if (/= "YES" (strcase (setq layerPlottable (extract l))))
(vla-put-plottable layerItem :vlax-false))
(setq l (trim layerPlottable))
(if (/= "NO" (strcase (setq layerFreeze (extract l))))
(vla-put-freeze layerItem :vlax-true))))
(close f)
(vla-endundomark activeDoc)))
(princ))
Solved! Go to Solution.