Author Topic: Dataextraction Using Autolisp....?  (Read 4088 times)

0 Members and 1 Guest are viewing this topic.

Vince

  • Newt
  • Posts: 55
Dataextraction Using Autolisp....?
« on: July 20, 2012, 08:16:48 AM »
Hello Swamp Members,

I am trying to automate the creation of a AutoCAD table, using Autolisp, for specific blocks containing 3 attributes on my drawing files. I would like the table to contain those 3 attributes plus the X, Y, Z coordinates of the insertion point for those blocks. I can accomplish this manually using the Dataextraction command and stepping through the options one screen at a time to eventually create the table.  I even tried to create a template file (.dxe) and used the -Dataextraction command but have been unsuccessful in automating the process (via autolisp) so that our engineers (who are not good CAD operators) can seemlessly create the tables automatically.

Can the creation of the table be automated....??  Is there any examples I can use to help me solve this problem....??

Any assistance would be appreciated....!


Regards,
Vince

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Dataextraction Using Autolisp....?
« Reply #1 on: July 20, 2012, 02:27:00 PM »
Interesting.  never thought of automating it but the OTB is kind of clunky.   

Sorry I can not offer any assitance but I can offer white noise.   :roll:
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

BlackBox

  • King Gator
  • Posts: 3770
Re: Dataextraction Using Autolisp....?
« Reply #2 on: July 20, 2012, 02:50:15 PM »
I don't have time to write a full routine specific to this task (more information is needed anyway), but you're welcome to pilfer this code used to extract the point number, elevation, and description from survey points and write this data to a temporary file, which is opened in Excel and can then be saved (or not).

I don't have much need for tables, but if you format the generated file to your liking and save to your project, a simple paste special as AutoCAD entity should do the trick, and link the AutoCAD Table to your Excel.

HTH

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:TopoToAscii (/ *error* ss n path acApp acDoc oShell tag pt# elev desc pt)
  3.  
  4.   (defun *error* (msg)
  5.     (if oShell
  6.       (vlax-release-object oShell)
  7.     )
  8.     (if file
  9.       (close file)
  10.     )
  11.     (cond ((not msg))                                                   ; Normal exit
  12.           ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
  13.           ((princ (strcat "\n** Error: " msg " ** ")))
  14.     )                                                                   ; Fatal error, display it
  15.     (princ)
  16.   )
  17.  
  18.   (if (and (setq ss (ssget "_x" (list '(0 . "INSERT") (cons 2 "YourBlockName"))))
  19.            (setq n (sslength ss))
  20.            (setq path
  21.                   (strcat (vl-filename-directory (vl-filename-mktemp))
  22.                           "\\"
  23.                           (getvar 'dwgname)
  24.                           ".csv"
  25.                   )
  26.            )
  27.            (setq acApp (vlax-get-acad-object))
  28.            (setq acDoc (vla-get-activedocument acApp))
  29.            (setq oShell
  30.                   (vla-getinterfaceobject acApp "Shell.Application")
  31.            )
  32.       )
  33.     (progn
  34.       (setq file (open path "w"))
  35.       (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
  36.         (foreach attrib (vlax-invoke x 'GetAttributes)
  37.           (cond ((= "POINT_NUMBER" (setq tag (vla-get-tagstring attrib)))
  38.                  (setq pt# (vla-get-textstring attrib))
  39.                 )
  40.                 ((= "ELEVATION" tag)
  41.                  (setq elev (vla-get-textstring attrib))
  42.                 )
  43.                 ((= "DESCRIPTION" tag)
  44.                  (setq desc (vla-get-textstring attrib))
  45.                 )
  46.           )
  47.         )
  48.         (write-line
  49.           (strcat
  50.             pt#
  51.             ","
  52.             (rtos (cadr (setq pt (vlax-get x 'insertionpoint))))
  53.             ","
  54.             (rtos (car pt))
  55.             ","
  56.             elev
  57.             ","
  58.             desc
  59.           )
  60.           file
  61.         )
  62.       )
  63.       (setq file (close file))
  64.       (vla-delete ss)
  65.       (prompt (strcat "\n** " (itoa n) " blocks processed ** "))
  66.       (vlax-invoke oShell 'open path)
  67.       (*error* nil)
  68.     )
  69.     (cond (acDoc
  70.            (*error* "Unable to create \"Shell.Application Object\"")
  71.           )
  72.           (n (*error* "Unable to create temporary file"))
  73.           ((*error* "No survey points found"))
  74.     )
  75.   )
  76. )
  77.  
  78.  
"How we think determines what we do, and what we do determines what we get."

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Dataextraction Using Autolisp....?
« Reply #3 on: July 21, 2012, 03:00:49 AM »
Once you've created one of the DXE files, you could always open it in lisp, have your routine create a duplicate while changing the old DWG filepath to the new one, close the file. Then run the -DataExtraction with the modified DXE - it "should" pick up the settings you made manually in that plethora of dialog boxes, but use the new DWG(s) as sources.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.