×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Have Excel count text entries in CAD??

Have Excel count text entries in CAD??

Have Excel count text entries in CAD??

(OP)
I am trying to figure out what I need to do in order to have MS Excel count text entries in my CAD DWG's.  I'll try to make that a little more clear.

Say I have text in a drawing such as, 24 threes, 12 c's, 34 twos and so on...  Is there a way to have Excel or CAD count these entries and export the values into Excel so I don't have to go through and do this manually (I'm not lazy, I just have a lot of this to do!)

Any Ideas???

RE: Have Excel count text entries in CAD??

Hi...

With this routine you can send all the texts to Excel. Now only you should modify it to adapt it to what you want.

Any modification you warn me:

(vl-load-com)

(defun libreria-excel (/ tlb)
  (cond
    ((setq
       tlb
    (findfile
      "c:\\Archivos de programa\\Microsoft Office\\Office\\Excel8.olb"
    )
     )
     tlb
    )
    ((setq
       tlb
    (findfile
      "c:\\Archivos de programa\\Microsoft Office\\Office\\Excel9.olb"
    )
     )
     tlb
    )
    ((setq tlb
        (findfile
          "c:\\Archivos de programa\\Microsoft Office\\Office\\Excel10.olb"
        )
     )
     tlb
    )
    ((setq
       tlb
    (findfile
      "c:\\Archivos de programa\\Microsoft Office\\Office\\Excel.exe"
    )
     )
     tlb
    )
    ((setq tlb
        (findfile
          "c:\\Archivos de programa\\Microsoft Office\\Office10\\Excel.exe"
        )
     )
     tlb
    )
  )
) ;_defun

(defun carga-libreria-excel (/ archivotlb tlbver out)
  (cond
    ((null msxl-xl24HourClock)
     (if (setq archivotlb (libreria-excel))
       (progn
     (setq tlbver (substr (vl-filename-base archivotlb) 6))
     (cond
       ((= tlbver "9")
        (princ "\nInicializando Microsoft Excel 2000...")
       )
       ((= tlbver "8")
        (princ "\nInicializando Microsoft Excel 97...")
       )
       ((= (vl-filename-base archivotlb) "Excel.exe")
        (princ "\nInicializando Microsoft Excel XP...")
       )
     )
     (vlax-import-type-library
       :tlb-filename      archivotlb     :methods-prefix
       "msxl-"          :properties-prefix "msxl-"
       :constants-prefix  "msxl-"
      )
     (if msxl-xl24HourClock
       (setq out T)
     )
       )
     )
    )
    (T (setq out T))
  )
  out
) ;_defun

(defun ad-nuevo-libro (dmode / appsession)
  (princ "\nCreando una nueva hoja de cálculo Excel...")
  (cond
    ((setq appsession (vlax-create-object "Excel.Application"))
     (vlax-invoke-method
       (vlax-get-property appsession 'WorkBooks)
       'Add
     )
     (vla-put-visible appsession 1)
    )
  )
  appsession
) ;_defun

(defun textos-a-excel (/ sel-textos n num-txt contenido)
  (setq sel-textos (ssget "_x" '((0 . "TEXT"))))
  (if (/= sel-textos nil)
    (progn
      (setq n 0)
      (setq num-txt (sslength sel-textos))
      (repeat num-txt
    (setq contenido
           (list (cdr (assoc 1 (entget (ssname sel-textos n))))
           )
    )
    (poner-valor-celda-excel-col contenido (+ n 1) 1)
    (setq n (1+ n))
      )
    ) ;_progn
  ) ;_if
) ;_defun

(defun celda-excel (rng relrow relcol)
  (vlax-variant-value
    (msxl-get-item
      (msxl-get-cells rng)
      (vlax-make-variant relrow)
      (vlax-make-variant relcol)
    )
  )
) ;_defun

(defun poner-valor-celda-excel-col (lst startrow startcol)
  (foreach itm lst
    (msxl-put-value
      (celda-excel range startrow startcol)
      itm
    )
    (setq startrow (1+ startrow))
  ) ;_repeat
) ;_defun

(defun c:abrir-excel ()
  (cond
    ((carga-libreria-excel)
     (cond
       ((cond
      ((setq xlapp (ad-nuevo-libro "SHOW"))
       (setq ash (msxl-Get-ActiveSheet xlapp))
       (setq range (msxl-Get-ActiveCell xlapp))
       (textos-a-excel)
      )
      (T (princ "\nFalló la aplicación."))
    )
       )
     )
    )
    (T
     (alert "No se inicializó la biblioteca para Excel 97...")
    )
  )
  (princ)
);_defun

(prompt "\n*** nuevo comando ABRIR-EXCEL definido ***")
(prin1)

RE: Have Excel count text entries in CAD??

(OP)
Thanks for the reply!

I regret to say that I am not a CAD master quite yet.  When I'm in CAD, what do I type in the command line to get to the proper place to enter the script (I've never had to do anything like this before.)?  Does it matter if the script is in English or Spanish?  I've been entering it in the CAD visual basic screen in a code window, but I just can't get it to work. Any more help would really be appreciated!

RE: Have Excel count text entries in CAD??

Hi...

Being in AutoCAD, you execute the command VLISP. When the window of the editor of Visual LISP opens up you believe a new document. Now copy the code that I put and you hit it in the new ducumento. Then you keep it with some name and later from AutoCAD it executes the command APPLOAD and it loads the file that you are kept, for defect the file will have the extension *. lsp. Once loaded the file executes the command ABRIR-EXCEL

NOTE: The routine will export all the texts of the drawing. I didn't understand which it is the filter that you want, if you explain to me better which are the texts that you want to send to Excel I will be able to create the filter.

Un saludo de SpeedCAD... :)
CHILE

RE: Have Excel count text entries in CAD??

(OP)
Hi,

Sorry I haven't replied in a while.  I was out of town working, but to answer your question...

Exactly what I am needing this for is:

I have different names in a drawing such as "vm5-10" and "um5" for example.  I need autocad to count one, two, three, four..."vm5-10" and put that in excel.  Sometimes there will be a "(2) vm5-10", which means a quantity of two and I need autocad to count those twice.

At the end, I would like to have a list in excel that lists each unit and their quantities...Is there any way to do that?

I hope that makes more sense for you and i really hope you can suggest something. I appreciate you taking the time to try and help me

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources