嗨Cadmando-2
很抱歉,我花了一段时间才回复你-我看到你在这里和AUGI都发了帖子,但我们出色的IT部门在工作时将这两个网站定义为社交媒体,当我发布代码并阻止发布时。
在dlanorh的宝贵帮助下,我几乎完成了编写一个与您类似的程序,该程序将属性从Autocad 2016导出到Revit 15(请参阅我今天早些时候的文章)。
我在下面添加了一些代码,希望能给你一个如何操作的指针-我将发布我完成的程序,你应该能够根据自己的应用程序进行调整,但基本上程序是这样的-
1、创建属性提取文件
2.使用lisp程序中的属性提取功能将属性信息(图纸编号、图纸标题等)导出到逗号分隔的文本文件(.csv)
3.使用Read line函数读取文本文件的每一行,并使用逗号将该行“剪切”为lisp文件中的变量。
4.将变量推入excel文件中正确工作表上的正确单元格中。。。。
- (defun c:excelcontrol ()
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;This sets up the autocad environment to run Excel;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;load all the VL commands, then the set the library to Excel
- (vl-load-com)
- (setq tlbfile (findfile "C:\\Program Files\\Microsoft Office 15\\root\\Office15\\Excel.exe"))
- (vlax-import-type-library :tlb-filename tlbfile :methods-prefix "msxl-" :properties-prefix "msxl-" :constants-prefix "msxl-")
- ;;;Open the excel spreadsheet and find the current worksheet
- (setq xfile "c:\\1715-143.xls")
- (cond
- ((setq fn (findfile xfile))
- (cond
- ((setq appsession (vlax-get-or-create-object "Excel.Application"))
- (vlax-invoke-method (vlax-get-property appsession 'workbooks) 'open fn)
- (vla-put-visible appsession 0)
- )
- )
- )
- (t (alert (strcat "nCannot locate source file: " xfile)))
- )
- (setq xlapp appsession)
- (setq rng (msxl-get-activesheet xlapp))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;This is how you set the cell number;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;Setq the cell reference to put the drawing number into (cell A10)
- (setq Data1_row 10)
- (setq Data1_column 1)
- (setq cell_detail_1 (vlax-variant-value (msxl-get-item (msxl-get-cells rng) (vlax-make-variant Data1_row) (vlax-make-variant Data1_column))))
- ;;;Setq the cell reference to put the drawing title into into (cell H10)
- (setq Data2_row 10)
- (setq Data2_column
- (setq cell_detail_2 (vlax-variant-value (msxl-get-item (msxl-get-cells rng) (vlax-make-variant Data2_row) (vlax-make-variant Data2_column))))
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;This is how you put the information in the spreadsheet;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;Get the drawing number and upload it into the excel spreadsheet
- (msxl-put-value2 cell_detail_1 drawing_number)
- ;;;Get the drawing and upload it into the excel spreadsheet
- (msxl-put-value2 cell_detail_2 drawing_title)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;This saves and closes the spreadsheet;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;;Save the modified workbook
- (setq workbook (vlax-get-property xlapp "ActiveWorkbook"))
- (vlax-invoke-method workbook "Save")
- ;;;Close excel, clear the memory and exit quietly
- (vlax-invoke-method xlapp "Quit")
- (vlax-release-object xlapp)
- (gc)
- (princ)
- )
|