need help to modify the text replacement lisp file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Below are the lisp file that i get from Open Ai. But its didn't work. My focus is to select text from drawing and open an excel xls file then search and matching the text in column A and then replace the text from the same row in column B.
(defun c:RPTXT (/ textObj excelFile excelData ss excelPath wb ws rng row col cell text)
; Get the selection set of text objects
(setq ss (ssget '((0 . "TEXT"))))
; Prompt the user to select an Excel file
(setq excelPath (getfiled "Select Excel File" "" "xls" 0))
; Open the selected Excel file
(setq excelFile (vlax-create-object "Excel.Application"))
(vlax-invoke-method excelFile 'Visible :vlax-false)
(setq wb (vlax-invoke-method excelFile 'Workbooks 'Open excelPath))
(setq ws (vlax-invoke-method wb 'Worksheets 'Item 1))
; Loop over the selected text objects
(vlax-for obj ss
(setq textObj (vlax-ename->vla-object obj))
(setq text (vla-get-textstring textObj))
(setq excelData (vlax-invoke-method ws 'UsedRange))
(vlax-for cell excelData
(setq row (vlax-get-property cell 'Row))
(setq col (vlax-get-property cell 'Column))
(when (= col 1)
(setq value (vlax-get-property cell 'Value))
(if (equal text value)
(vla-put-objectname textObj (vlax-get-property (vlax-invoke-method excelData 'Item row 2) 'Value))
)
)
)
)
; Save and close the Excel file
(vlax-invoke-method wb 'Save)
(vlax-invoke-method wb 'Close :vlax-false)
(vlax-release-object ws)
(vlax-release-object wb)
(vlax-release-object excelFile)
; Refresh the AutoCAD drawing to show changes
(command "REGEN")
)