Jump to content

Data extraction lisp file needed -2009


kindy52

Recommended Posts

I did notice that you didn't combine lengths if more than one line existed on a layer. I hope you don't mind, I gave it a shot myself.

Not at all, as long as the best lisp gets used at the end of the day :wink:

I didn't know kindy wanted to combine the layers.

 

aside: what's the program you use to record animation and is it free? 8)

 

aside2: how did you get the csv up so quickly in the animation? EDIT: wait, I think your lisp loads notepad and you just alt-tab'ed?

 

aside3: I've always wondered, why do you like using #'s in all your variables?

Link to comment
Share on other sites

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

  • SteveK

    11

  • alanjt

    7

  • kindy52

    6

  • danielk

    1

Top Posters In This Topic

Posted Images

Not at all, as long as the best lisp gets used at the end of the day :wink:

I didn't know kindy wanted to combine the layers.

 

aside: what's the program you use to record animation and is it free? 8)

 

aside2: how did you get the csv up so quickly in the animation? EDIT: wait, I think your lisp loads notepad and you just alt-tab'ed?

 

aside3: I've always wondered, why do you like using #'s in all your variables?

 

Well, I don't want to offend, I just like to play. :) I really like your work.

 

Yeah, I was thinking about how to combine duplicates on my drive home. Then I thought about entmod and I went with a dotted pair.

 

I use Camtasia to record videos, my home PC is a POS, so sometimes running Camtasia and Civil 3d 2009 can bog down my machine (that's why some of my videos are clunky).

 

I used (startapp "Notepad" #File), it will open the file using Notepad, I just liek to do this so the user can quickly get to the file. I didn't want to worry with just opening the file, since we don't know what other software they have loaded, but everyone has Notepad. No alt-tab, BTW.

 

It's just part of my naming scheme, I like to be organized.

My used prefixes:

AT: = my subroutines

_ = routine specific subroutines

# = local variable

*CommandName:VariableName* = global variables

 

I also like to use self-explanatory variables, I'm not much on trying to decipher what llst, I'd rather look at #LayerList.

 

As you can see, I can get a little verbose. :)

Link to comment
Share on other sites

  • 4 years later...
Don't sweat it dude. :) I did notice that you didn't combine lengths if more than one line existed on a layer. I hope you don't mind, I gave it a shot myself.

 

[ATTACH]15370[/ATTACH]

 

;;; TakeOff (Export Line lengths to csv based on layer)
;;; Alan J. Thompson, 11.05.09
(defun c:TakeOff (/ *error* #SS #Item #List #Open #File)
 (vl-load-com)
 (defun *error* (#Message)
   (and #Open (close #Open))
   (and #File (startapp "Notepad" #File))
   (and #Message
        (not (wcmatch (strcase #Message) "*BREAK*,*CANCEL*,*QUIT*"))
        (princ (strcat "\nError: " #Message))
   ) ;_ and
 ) ;_ defun
 (cond
   ((setq #SS (ssget '((0 . "LINE"))))
    (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
    (vlax-for x (setq #SS (vla-get-activeselectionset *AcadDoc*))
      (setq #Item (cons (vla-get-layer x) (vla-get-length x)))
      (if (assoc (car #Item) #List)
        (setq #List (subst (cons (car #Item) (+ (cdr (assoc (car #Item) #List)) (cdr #Item)))
                           (assoc (car #Item) #List)
                           #List
                    ) ;_ subst
        ) ;_ setq
        (setq #List (cons #Item #List))
      ) ;_ if
    ) ;_ vlax-for
    (vl-catch-all-apply 'vla-delete (list #SS))
    (setq #Open (open (setq #File (strcat (getvar 'dwgprefix) "TakeOff.csv")) "W"))
    (foreach x (cons "Layer,Length"
                     (mapcar '(lambda (i) (strcat (car i) "," (vl-princ-to-string (cdr i))))
                             (vl-sort #List '(lambda (x y) (< (car x) (car y))))
                     ) ;_ mapcar
               ) ;_ cons
      (write-line x #Open)
    ) ;_ foreach
   )
 ) ;_ cond
 (*error* nil)
 (princ)
) ;_ defun

 

[ATTACH]15371[/ATTACH]

 

Looks like a great lisp , but isn't working for me on 2014? any reason?

Thanks

Link to comment
Share on other sites

  • 3 weeks later...

Hi guys, great routines.

 

Steve, I have just begun to play around with your routine... my plan is to modify it to output a list of all text selected in a DWG. So far I have tweaked it to work... but I would like to add a feature to enable it to count/combine all entries in the CSV that are the same. Is this possible? I haven't begun to dig too deep into the coding yet. But have made only very minor changes to your code to enable the selection of text (rather than lines), and to also read the value of the text (rather than line length).

 

Code:

;Original code by SteveK - http://www.cadtutor.net/forum/showthread.php?41661-Data-extraction-lisp-file-needed-2009/page2

(princ "\nLisp Loaded. Type \"PTO\" to run..")
(defun c:PTO (/ fl lst)
 (vl-load-com)
 (if (and (setq lst (lndet))
      (setq fl (strcat (getvar "DWGPREFIX") "TakeOff.csv"))
      (setq fl (open fl "w")))
   (progn
     (write-line "Layer,Line Length" fl)
     (foreach ln lst
   (ListToCSV
     fl ; Will erase existing file if exists
     ln
     nil ; Individual Header Line
     );_ ListToCSV
   );_ foreach
     (close fl)
     (princ (strcat "\nAll Done. " (itoa (length lst)) " Lines processed."))
     );_ progn
   (princ "\nNo Peg Block found or File selected/opened")
   );_ if
 (princ)
 )

(defun lndet (/ ss i en lst)
 ; Selection Set
 (if (setq ss (ssget '((0 . "text"))))
   (progn
     
     ; Loop to get each bit of data from each line
     (setq i -1)
     (while (setq en (ssname ss (setq i (1+ i))))
   ; Add details of each line to a list
   (setq lst (cons
           (list
             ; Get the Layer of the Line
             (cdr (assoc 8 (entget en)))
             ; Get the distance of the Line
             
            (cdr (assoc 1 (entget en)))
           
             )
           lst)
         );_ end setq
   );_ end while
     )(princ "\nNo Lines Found.")
   );_ end if

 ; Output List or Nil
 lst
 )

;;; By Mark - http://www.theswamp.org/index.php?topic=6356.msg77762#msg77762
(defun ListToCSV (fo lst header / cnt)
 ;;; takes a list [lst], open file handle [fo] and header [header] 
 ;;; (optional) a string and writes the list to the file in comma
 ;;; delimited format.

 ;;; example
 ;;; (setq fo (open "c:/cd_file.csv" "w"))
 ;;; (setq pt_list (list "23" 100.25 200.2))
 ;;; (ListToCSV fo pt_list "Point,Northing,Easting")
 ;;; (close fo)

 (defun Item2Str (lst)
   ;;; convert INT or REAL to string
   (mapcar
     '(lambda (item)
    (cond
      ((= (type item) 'INT)
       (itoa item))
      ((= (type item) 'REAL)
       (rtos item 2 4)); you will probably want to change this
      (T
       ;Check for comma's in string - SK added
       (vl-string-subst "." "," item))
      )
    )
     lst
     )
   )

 (if header 
   (write-line header fo)
   )

 ;; make sure we have nothing but strings in the list
 (setq lst (Item2Str lst)
   cnt 1)

 ;; write it!!
 (write-line
   (apply 'strcat
      (mapcar
        '(lambda (item)
       (if (= (length lst) cnt)
         (strcat item)
         (progn
           (setq cnt (1+ cnt))
           (strcat item ",")
           )
         )
       )
        lst
        )
      )
   fo
   )
 (princ)
 )

 

I have also attached a CSV, which should hopefully show you what I mean.

 

Thanks a lot for any help.

 

TakeOff.csv

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...