MUTHUKUMAR1983 Posted May 24 Share Posted May 24 (defun c:ExportAngleToExcel (/ excel-app excel-wb excel-ws angle p1 p2 row-num) ;; Set the existing Excel file path (setq file-path "C:\Path\To\Your\File.xlsx") ;; Create an instance of Excel application (setq excel-app (vl-catch-all-apply 'vlax-get-or-create-object '("Excel.Application"))) ;; Open the existing workbook (setq excel-wb (vl-catch-all-apply 'vlax-invoke-method excel-app 'Workbooks 'Open file-path)) (setq excel-ws (vl-catch-all-apply 'vlax-get-property excel-wb 'ActiveSheet)) ;; Find the last used row in the Excel sheet (setq row-num (+ (vl-catch-all-apply 'vlax-get-property excel-ws 'UsedRange.Row) (vl-catch-all-apply 'vlax-get-property excel-ws 'UsedRange.Rows) 1)) ;; Loop to get multiple angles (repeat 5 ; Change the number according to your requirement ;; Prompt the user to select the first point (setq p1 (getpoint "\nSelect first point: ")) ;; Prompt the user to select the second point (setq p2 (getpoint p1 "\nSelect second point: ")) ;; Calculate the angle between the two points (setq angle (rtos (angtos (angle p1 p2)) 2)) ;; Write the angle value to Excel (vl-catch-all-apply 'vlax-put-property (vl-catch-all-apply 'vlax-get-property excel-ws 'Cells row-num 1) 'Value (strcat "Angle " (itoa (1+ row-num)))) (vl-catch-all-apply 'vlax-put-property (vl-catch-all-apply 'vlax-get-property excel-ws 'Cells row-num 2) 'Value angle) ;; Increment the row number (setq row-num (1+ row-num)) ) ;; Activate Excel application to make it visible (vl-catch-all-apply 'vlax-invoke-method excel-app 'Activate) ;; Save and close the Excel workbook (vl-catch-all-apply 'vlax-invoke-method excel-wb 'Save) ;; Close the Excel workbook without saving changes (vl-catch-all-apply 'vlax-invoke-method excel-wb 'Close :vlax-false) ;; Quit Excel application (vl-catch-all-apply 'vlax-invoke-method excel-app 'Quit) ;; Release COM objects (vlax-release-object excel-ws) (vlax-release-object excel-wb) (vlax-release-object excel-app) ;; Clear any unreferenced symbols (gc) (princ) ) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 24 Share Posted May 24 Try to change the path as follows: This one C:\\Path\\To\\Your\\File.xlsx" or this one C:/Path/To/Your/File.xlsx" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.