也许这会有所帮助(代码编写得很快):
- (vl-load-com)
- (defun BB:CSV->Layers (path / f *error* _extract _trim acDoc l layerTable
- layerName layerItem layerDescription layerColor
- layerLinetype layerLineweight layerPlottable
- layerFreeze
- )
- ;; Exampe: (BB:CSV->Layers "Z:\\my_layers_folder\\my_layers.csv")
- (if (and (findfile path)
- (setq f (open path "r"))
- )
- (progn
- ;; Error handler
- (defun *error* (msg)
- (vla-endundomark acDoc)
- (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
- (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
- )
- (read-line f) ; <- Skip first line (headers)
- (setq layerTable (vla-get-layers acDoc))
- ;; Linetype check
- ;; <- Add linetype import code here, to avoid errors
- (while (/= nil (setq l (read-line f)))
- (progn
- ;; Layer check
- (setq layerItem
- (vla-add layerTable (setq layerName (_extract l)))
- )
- ;; 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)
- )
- )
- )
- (setq f (close f))
- (*error* nil)
- )
- )
- )
基本上,这允许您指定任何。CSV文件(格式相同),并快速导入*这些*层。您可以为每个规程设置一个宏(假设它们使用不同的层),或者为每个客户端设置一个宏。。。无论什么这实际上取决于你如何工作,以及你的需求是什么。
如果这有帮助的话,我可以很容易地将例程修改为“硬编码”,如果这是唯一的。您需要的CSV文件。
希望这有帮助! |