Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Please help to export value of Multi Dim to Excel

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
minh.dxuan
1033 Views, 8 Replies

Please help to export value of Multi Dim to Excel

Hi all, now my work needs to get the value of multi dimensions in attached drawing and input in Excel file. I need your help to export them as the below information:
1. The value of dim is mm but the value after export is meter.

2. The exporting value must have 03 numbers after decimal point (e.g: If value of dim = 1,0514 mm => exporting value will be 1.051).

3. Please refer the attached lisp named "D2E" (export drawing text to Excel that hosneyalaa made for me - https://forums.autodesk.com/t5/user/viewprofilepage/user-id/6591997).

4. Please refer the attached lisps that extracts dim value to field in drawing with mm and meter units that named "mmD2F" and "mD2F".

Thank you soo much and best regards.

8 REPLIES 8
Message 2 of 9
minh.dxuan
in reply to: minh.dxuan

This is reference to extract dim to field with unit is meter.

 

Best regards.

Message 3 of 9
ВeekeeCZ
in reply to: minh.dxuan

@minh.dxuan,

learn yourself how to do that.

 

This is a snippet from your code:

(vla-put-textString obj
       (if (= 1 (length Ids))
         (strcat "%<\\AcObjProp Object(%<\\_ObjId " (car Ids) ">%).Measurement \\f \"%lu6\%ct8[0.001]\">%")
         (strcat "%<\\AcExpr"
           (lst->str Ids " %<\\AcObjProp Object(%<\\_ObjId " ">%).Measurement >% +")
           ">%).Measurement >% \\f \"%lu6\%ct8[0.001]\">%"
         )
       )
     )

See, there is some FIELD formatting in your code.

 

So, run the FIELD command, specify the desired formatting, and change the code accordingly. The following screenshot is just for illustration:

Z9E3zK5E_0-1603699860024.png

 

 

 

 

Message 4 of 9
hosneyalaa
in reply to: minh.dxuan

hi @minh.dxuan 

 

test this

 

;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/export-value-of-text-to-excel-sometimes-error/td-p/9764877
(defun C:testD2E(/ FN FW I J LST L_TXT SLST STR)


  
;;--------------=={ SelectionSet -> Entities }==--------------;;
;;                                                            ;;
;;  Converts a SelectionSet to a list of Entities             ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  ss - Valid SelectionSet (Pickset)                         ;;
;;------------------------------------------------------------;;
;;  Returns:  List of Entity names, else nil                  ;;
;;------------------------------------------------------------;;

(defun LM:ss->ent ( ss / i l )
    (if ss
        (repeat (setq i (sslength ss))
            (setq l (cons (ssname ss (setq i (1- i))) l))
        )
    )
)

  
(princ "\nChoose Dimension can xuat ra file...")
  (IF (AND
         (setq lst (mapcar 'entget (LM:ss->ent (ssget '((0 . "DIMENSION"))))))
   (setq	fn (getfiled "Chon file de save" "" "text" 1))
   (setq	fw (open fn "w") i 0 j 0)
)
  (PROGN
(foreach n lst
;;;  (setq n (nth 4 lst))
(princ
 (cond
  ((wcmatch (cdadr n) "*TEXT")(strcat (setq str (vlax-get (vlax-ename->vla-object (CDR(ASSOC -1 N))) 'Textstring)) ";Text" (itoa (setq i (1+ i))) "\n"))  
  ((= (cdadr n) "DIMENSION")
   
           (setq l_txt (strcat (rtos (/ (vlax-get (vlax-ename->vla-object (CDR(ASSOC -1 N))) 'measurement) 1000) (getvar 'lunits) 3)));_end_setq
        
           (setq slst (vl-string->list l_txt));_end_setq
      

      (cond ( (not (vl-position 46 slst)) (setq l_txt (strcat l_txt ".000")))
            ( (= (vl-position 46 slst) (1- (strlen l_txt))) (setq l_txt (strcat l_txt "000")))
            ( (= (vl-position 46 slst) (- (strlen l_txt) 2)) (setq l_txt (strcat l_txt "00")))
	    ( (= (vl-position 46 slst) (- (strlen l_txt) 3)) (setq l_txt (strcat l_txt "0")))
      );end_cond



   
   (strcat l_txt  ";Dim" (itoa (setq j (1+ j))) "\n")
   )
  
 )
  fw
 )
 )
(close fw)
  ;;;(startapp "explorer" fn)
(startapp "notepad" fn)
))
  )


          

 

 

التقاط.PNG

Message 5 of 9
minh.dxuan
in reply to: hosneyalaa

Hi @hosneyalaa , thank you so much for your help. Could you please revise your lisp to extract to Excel file and the exporting file is automatically opened like the attached file named "D2E" - Drawing to Excel (this file before you make for me to export text from AutoCAD to Excel). This one is more convenient to copy the data after exporting.

Thanks and best regards.Untitled.png

 

Message 6 of 9
minh.dxuan
in reply to: ВeekeeCZ

Hi @ВeekeeCZ .
Thank you for your help. I think it's very good to enlarge the acknowledge with your code. But I am very sad that I am as white paper with lisp code and at the moment I can not program the lisp by myself. I hope I will be able soon.

Many thanks and have a nice day.

Message 7 of 9
hosneyalaa
in reply to: minh.dxuan

;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/export-value-of-text-to-excel-sometimes-error/td-p/9764877
(defun C:testD2E(/ FN FW I J LST L_TXT SLST STR)


  
;;--------------=={ SelectionSet -> Entities }==--------------;;
;;                                                            ;;
;;  Converts a SelectionSet to a list of Entities             ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  ss - Valid SelectionSet (Pickset)                         ;;
;;------------------------------------------------------------;;
;;  Returns:  List of Entity names, else nil                  ;;
;;------------------------------------------------------------;;

(defun LM:ss->ent ( ss / i l )
    (if ss
        (repeat (setq i (sslength ss))
            (setq l (cons (ssname ss (setq i (1- i))) l))
        )
    )
)

  
(princ "\nChoose Dimension can xuat ra file...")
  (IF (AND
         (setq lst (mapcar 'entget (LM:ss->ent (ssget '((0 . "DIMENSION"))))))
   (setq	fn (getfiled "Chon file de save" "" "csv" 1))
   (setq	fw (open fn "w") i 0 j 0)
)
  (PROGN
(foreach n lst
;;;  (setq n (nth 4 lst))
(princ
 (cond
  ((wcmatch (cdadr n) "*TEXT")(strcat (setq str (vlax-get (vlax-ename->vla-object (CDR(ASSOC -1 N))) 'Textstring)) ";Text" (itoa (setq i (1+ i))) "\n"))  
  ((= (cdadr n) "DIMENSION")
   
           (setq l_txt (strcat (rtos (/ (vlax-get (vlax-ename->vla-object (CDR(ASSOC -1 N))) 'measurement) 1000) (getvar 'lunits) 3)));_end_setq
        
           (setq slst (vl-string->list l_txt));_end_setq
      

      (cond ( (not (vl-position 46 slst)) (setq l_txt (strcat l_txt ".000")))
            ( (= (vl-position 46 slst) (1- (strlen l_txt))) (setq l_txt (strcat l_txt "000")))
            ( (= (vl-position 46 slst) (- (strlen l_txt) 2)) (setq l_txt (strcat l_txt "00")))
	    ( (= (vl-position 46 slst) (- (strlen l_txt) 3)) (setq l_txt (strcat l_txt "0")))
      );end_cond



   
   (strcat l_txt  ";Dim" (itoa (setq j (1+ j))) "\n")
   )
  
 )
  fw
 )
 )
(close fw)
  (startapp "explorer" fn)
     ;;;(startapp "notepad" fn)
))
  )

 

 

 

Capture.JPGCapture.JPG1.JPG

Message 8 of 9
minh.dxuan
in reply to: hosneyalaa

Hi @hosneyalaa , your lisp runs extremely well and I would like to thank you for your many helps.

Best regards and best wishes to you.

Message 9 of 9
hosneyalaa
in reply to: minh.dxuan

You're welcome anytime.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report