本帖最后由 freedom_ice 于 2023-4-10 11:25 编辑
在论坛里找到过批量修改字体之类的,但是没有找到批量写入实体的,尝试了很久,总是想着用vla-activate来实现,但是不管怎么激活,写入实体总是在第一个打开的CAD里面。今天发现用Vlisp,添加实体的时候指定文档即可解决问题。
分享给大家。代码来自于论坛及帮助文件。
- ( vl-load-com )
- (defun c:tt ( / sh folder folderobject result)
- ( setq AcadObject ( vlax-get-acad-object )
- AcadDocument ( vla-get-ActiveDocument AcadObject )
- AcadDocuments ( vla-get-documents AcadObject )
- )
-
- (setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ))
- (setq folder (vlax-invoke-method sh 'BrowseForFolder 0 "请选择文件夹" 0 ))
- (vlax-release-object sh)
- (setq folderobject (vlax-get-property folder 'Self))
- (setq result (vlax-get-property FolderObject 'Path))
- (setq Files_Folder (vl-directory-files result "*.dwg"))
- (foreach file Files_Folder
- (setq block_file (strcat result "\\" file))
-
- ( setq doc_now ( vla-open AcadDocuments block_file));打开的文档
-
- ( setq mSpace ( vla-get-ModelSpace doc_now ) )
- ( setq myline ( vla-addline mspace (vlax-3d-point '( 0 0 0 ) )(vlax-3d-point '( 500 100 0 ))))
- ( vla-Save doc_now )
- ( vlax-for doc AcadDocuments
- (if (/= (vla-get-Name doc) (vla-get-Name AcadDocument))
- (vla-Close doc :vlax-false)
- )
- )
- ( vla-activate AcadDocument )
- )
- (princ)
- )
|