HELP FOR ADD TEXT FROM EXCEL

HELP FOR ADD TEXT FROM EXCEL

Anonymous
Not applicable
1,122 Views
5 Replies
Message 1 of 6

HELP FOR ADD TEXT FROM EXCEL

Anonymous
Not applicable

Respected all member,

                                         please help me for add text from excel, i attach drawing Before and after with excel

0 Likes
1,123 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

You can use this function to populate fields by reading the information you need from the excel file and setting it as a variable in lisp. 

In autocad put the variable and have it read that lisp variable. 

(defun getCellsFunction(fileName sheetName cellName / myXL myBook mySheet myRange cellValue)
    (setq myXL(vlax-get-or-create-object "Excel.Application"))
    (vla-put-visible myXL :vlax-false)
    (vlax-put-property myXL 'DisplayAlerts :vlax-false)
    (setq myBook (vl-catch-all-apply 'vla-open (list (vlax-get-property myXL "WorkBooks") fileName)))
    (setq mySheet (vl-catch-all-apply 'vlax-get-property (list (vlax-get-property myBook "Sheets") "Item" sheetName)))
    (vlax-invoke-method mySheet "Activate")
    (setq myRange (vlax-get-property (vlax-get-property mySheet 'Cells) "Range" cellName))
    (setq cellValue(vlax-variant-value (vlax-get-property myRange 'Value2)))
    (vl-catch-all-apply 'vlax-invoke-method (list myBook "Close"))
    (vl-catch-all-apply 'vlax-invoke-method (list myXL "Quit"))
    (if (not (vlax-object-released-p myRange))(progn(vlax-release-object myRange)(setq myRange nil)))
    (if (not (vlax-object-released-p mySheet))(progn(vlax-release-object mySheet)(setq mySheet nil)))
    (if (not (vlax-object-released-p myBook))(progn(vlax-release-object myBook)(setq myBook nil)))
    (if (not (vlax-object-released-p myXL))(progn(vlax-release-object myXL)(setq myXL nil)))    
    (if(= 'safearray (type cellValue))
      (progn
        (setq tempCellValue(vlax-safearray->list cellValue))
        (setq cellValue(list))
        (if(= (length tempCellValue) 1)
          (progn
            (foreach a tempCellValue
              (if(= (type a) 'LIST)
                (progn
                  (foreach b a
                    (if(= (type b) 'LIST)
                      (setq cellValue(append cellValue (list (vlax-variant-value (car b)))))
                      (setq cellValue(append cellValue (list (vlax-variant-value b))))
                    )
                  )
                )
                (setq cellValue(append cellValue (list (vlax-variant-value a))))
              )
            )
          )
          (progn
            (foreach a tempCellValue
              (setq tmpList(list))
              (foreach b a
                (setq tmp(vlax-variant-value b))
                (setq tmpList(append tmpList (list tmp)))
              )
              (setq cellValue(append cellValue tmpList))
            )
          )
        )
      )
    )
    cellValue
  )


(getCellsFunction "PUT FILE PATH HERE" "ENTER EXCEL SHEET NAME HERE (SHEET 1)" "ENTER CELL(S) HERE (A1:B10)")

Set the variable like this. 

(setq test_number (getCellsFunction "PUT FILE PATH HERE" "ENTER EXCEL SHEET NAME HERE (SHEET 1)" "ENTER CELL(S) HERE (A1:B10)")

 

Im not that great at this stuff so some one correct me if this isnt a good solution. 

This is what I am using to auto-populate all kinds of information for our projects i just put them in the template and find the excel file based on the dwg name....... 

Good luck

0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks for reply

 

I tried this code but not working 

 

this error show :-  error: bad argument type: VLA-OBJECT #<%catch-all-apply-error%>

0 Likes
Message 4 of 6

Sea-Haven
Mentor
Mentor

Did you change this, file path may need \\ between directories.

(getCellsFunction "PUT FILE PATH HERE" "ENTER EXCEL SHEET NAME HERE (SHEET 1)" "ENTER CELL(S) HERE (A1:B10)")

 

Post what you used.

0 Likes
Message 5 of 6

Anonymous
Not applicable

Did the same but not working

0 Likes
Message 6 of 6

Anonymous
Not applicable

Sir i have existing text coordinates

 

Please see the attached Add Text Excel_rev2.csv file

0 Likes