Exporting dimensions AND prefix to csv

Exporting dimensions AND prefix to csv

Anonymous
Not applicable
3,304 Views
11 Replies
Message 1 of 12

Exporting dimensions AND prefix to csv

Anonymous
Not applicable

Good Evening!

 

I have a lisp script that exports dimension values to a csv file.

I have modified it to only export selected dimensions which is exactly what I want.

However;

I would also like to export any prefix the dimension has and include it with the exported dimension:

 

EG:    a dimension of 36" that has a prefix of R should be something like   R - 36,     a dimension with no prefix would just be 36

Attached is my current lisp script:

 

; Save the Dimension's values to a CSV file
; mfuccaro@hotmail.com
; 2008 May
; Enhancements by CAD Studio, 2012
; Modified by WhoolieShop to include prefix's and only work on current selection.
;
(setq _dimexpdelimiter ",") ; set to ";" for CSY/DEU...

(defun C:DimExp ( / s tx fn i d dl m file)

(setq s (ssget  (list '(0 . "DIMENSION")))
	tx nil
	fn (strcat (getvar "dwgprefix") "DimExp.csv"))
(repeat (setq i (sslength s))
 (setq d (ssname s (setq i (1- i)))
	dl (entget d)
	m (cdr (assoc 42 dl)))
 (if (not (member m tx)) (setq tx (cons m tx)))
)
(setq s nil)
(if tx (progn
 (setq file (open fn "a")) ; append
 (write-line "" file)
 (princ (strcat (getvar "dwgname") _dimexpdelimiter) file)
 (foreach x tx
  (princ x file)
  (princ _dimexpdelimiter file)
 )
 (if file (close file))
 (princ (strcat "\n" (itoa (length tx)) " dimensions written to " fn)) 
))
(princ)
)

Thanks in advance!

0 Likes
Accepted solutions (1)
3,305 Views
11 Replies
Replies (11)
Message 2 of 12

dlanorh
Advisor
Advisor

@Anonymous wrote:

Good Evening!

 

I have a lisp script that exports dimension values to a csv file.

I have modified it to only export selected dimensions which is exactly what I want.

However;

I would also like to export any prefix the dimension has and include it with the exported dimension:

 

EG:    a dimension of 36" that has a prefix of R should be something like   R - 36,     a dimension with no prefix would just be 36

Attached is my current lisp script:

 

; Save the Dimension's values to a CSV file
; mfuccaro@hotmail.com
; 2008 May
; Enhancements by CAD Studio, 2012
; Modified by WhoolieShop to include prefix's and only work on current selection.
;
(setq _dimexpdelimiter ",") ; set to ";" for CSY/DEU...

(defun C:DimExp ( / s tx fn i d dl m file)

(setq s (ssget  (list '(0 . "DIMENSION")))
	tx nil
	fn (strcat (getvar "dwgprefix") "DimExp.csv"))
(repeat (setq i (sslength s))
 (setq d (ssname s (setq i (1- i)))
	dl (entget d)
m (cdr (assoc 1 dl))) (if (not (member m tx)) (setq tx (cons m tx))) ) (setq s nil) (if tx (progn (setq file (open fn "a")) ; append (write-line "" file) (princ (strcat (getvar "dwgname") _dimexpdelimiter) file) (foreach x tx (princ x file) (princ _dimexpdelimiter file) ) (if file (close file)) (princ (strcat "\n" (itoa (length tx)) " dimensions written to " fn)) )) (princ) )

Thanks in advance!


Try modifying the number above as shown.  42 will give you the actual dimension. 1 will give you what the dimension shows (what was entered by the user.

 

https://www.autodesk.com/techpubs/autocad/acad2000/dxf/common_dimension_group_codes_dxf_06.htm

I am not one of the robots you're looking for

0 Likes
Message 3 of 12

Anonymous
Not applicable

Hmmmm

okay that narrowed down my selection to two dimensions, which are ones that had overridden text.

The regular dimensions did not get parsed.

 

LT018005_Jeff_Taylor.dwg31/2"x72"SC 

 

The SC "special cuts" are pretty rare in the drawing.   I'll poke around a bit more thanks to that site you linked me to and see if i can extract what I need.

 

***NOTE***    changing it to option 3 which is

 

Dimension style name

 

Did extract Precut, and PrecutCorner  but only two lines, I would need the Style for EACH and dimension listed individually even if there are duplicates....

How would i go about using say the dimension measurement 42 AND option 3 for the dimension style?   I could just do 3 separate styles and sort them that way to tell the difference between left and right corners.

 

*EDIT #2*

Actually I really don't even need this to export to a CSV, if I could select all of a specific dim type, then sum all of their lengths and optionally get a count of the number that would completely solve my problem without having to even fool with exporting them to CSV, thats exactly what im going to end up doing anyway (adding them up to get a total length of material)

0 Likes
Message 4 of 12

dbhunia
Advisor
Advisor

 

 


@Anonymous wrote:

Hmmmm

....

 

*EDIT #2*

Actually I really don't even need this to export to a CSV, if I could select all of a specific dim type, then sum all of their lengths and optionally get a count of the number that would completely solve my problem without having to even fool with exporting them to CSV, thats exactly what im going to end up doing anyway (adding them up to get a total length of material)


Can you elaborate the marked points with an attached example drawing.......


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 5 of 12

dlanorh
Advisor
Advisor

Try this :

 

; Save the Dimension's values to a CSV file
; mfuccaro@hotmail.com
; 2008 May
; Enhancements by CAD Studio, 2012
; Modified by WhoolieShop to include prefix's and only work on current selection.
;
(setq _dimexpdelimiter ",") ; set to ";" for CSY/DEU...

(defun C:DimExp ( / s tx fn i d dl m file)
  (vl-load-com)
  (setq s (ssget  (list '(0 . "DIMENSION")))
        tx nil
        fn (strcat (getvar "dwgprefix") "DimExp.csv")
  )
  (repeat (setq i (sslength s))
    (setq d (vlax-ename->vla-object (ssname s (setq i (1- i)))))
    (if (= (strlen (vlax-get-property d 'textprefix)) 0)
      (setq m (vlax-get-property d 'measurement))
      (setq m (strcat (vlax-get-property d 'textprefix) (rtos (vlax-get-property d 'measurement) (getvar 'lunits) (getvar 'luprec))))
    )  
    (if (not (member m tx)) (setq tx (cons m tx)))
  )
  (setq s nil)
  (if tx 
    (progn
      (setq file (open fn "a")) ; append
      (write-line "" file)
      (princ (strcat (getvar "dwgname") _dimexpdelimiter) file)
      (foreach x tx
        (princ x file)
        (princ _dimexpdelimiter file)
      )
      (if file (close file))
      (princ (strcat "\n" (itoa (length tx)) " dimensions written to " fn)) 
    )
  )
  (princ)
)

 

This is easier to accomplish using vlisp. The problem is the measurement is a real, and the dim prefix is a string; and the only option is to convert the measurement to a string since you can't convert a string of letters to a meaningful number.

 

The SC "special cuts" are pretty rare in the drawing.   I'll poke around a bit more thanks to that site you linked me to and see if i can extract what I need.

 

***NOTE***    changing it to option 3 which is
 	

Dimension style name

 

Did extract Precut, and PrecutCorner  but only two lines, I would need the Style for EACH and dimension listed individually even if there are duplicates....

How would i go about using say the dimension measurement 42 AND option 3 for the dimension style?   I could just do 3 separate styles and sort them that way to tell the difference between left and right corners.

 

 

??!!

 

What exactly are you trying to do?

I am not one of the robots you're looking for

0 Likes
Message 6 of 12

Anonymous
Not applicable

I have walls that are x length.  

each wall has a given height, and variable openings in it.  

 

The wall is comprised of rows which are made of log.  The logs are variable length but rarely span the entire length of the wall.  (15’-6” max) per log.  

 

I have to manually break up the logs on each row ensuring there are now double breaks (two or more rows that have logs that break in exactly the same place). 

 

I typically manually put in all the log dimensions for each wall, once the wall is broken up into its individual parts including window and door openings I need to figure out the total amount of left corners, right corners, regular logs and special cuts needed for the entire structure. 

 

I found this this last night:

https://sites.google.com/site/cadkits/home/adddim

 

Which allows me to make a selection and the script/lisp gives me a sum of the selected dimensions for a total.  

 

It does not have to export the values values to excel, this is just the old way I was doing it having the total on screen is completely acceptable and actually less work than exporting and manually summing the totals. 

 

What would ne nice is if I could select all and have the dimensions summed based upon what dim style they have.  As each component in the drawing has a different dim style.  (One for left corners, one for right, one for no corner, and one for special cuts). 

 

If the script took the entire selection snd gave me a total distance of selected sims grouped by dim style it would be perfect. 

0 Likes
Message 7 of 12

dlanorh
Advisor
Advisor
OK. You need a lisp to sum dimensions by dimstyle. What are the dimstyles names and which style relates to which type of dimension (only if it's not blindingly obvious).
Then it's a matter of selecting all the dims, looping through the selection set, finding the dimstyle and dimension and adding it to the current total for that dimstyle. Does that sound correct?

I am not one of the robots you're looking for

0 Likes
Message 8 of 12

Anonymous
Not applicable

Yes that’s very close, if the dim style names are needed they would be:

 

PrecutRC

PrecutLC

Precut

PrecutSC

 

or it could just use any dim style name and group them; as long as it outputs what style as it is totalling that would be totally fine.  

 

For example if there was a dim style named standard or mydimstyle, it would be fine if it just looked through those as well and outputted the total even though I don’t need the total of any other than the specific ones I listed. 

0 Likes
Message 9 of 12

dlanorh
Advisor
Advisor

Try this. I can't test at the moment. Does this do what you require or does it need refining? Display should be by an alert box at the end.

;Ron Harman
;Dimension Total By Dimstyle
(defun C:DTBD ( / c_doc ss d1_tot d2_tot d3_tot d4_tot dim_style dim_dim)
  (vl-load-com)
  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        ss (ssget  '((0 . "DIMENSION")))
        d1_tot 0
        d2_tot 0
        d3_tot 0
        d4_tot 0
        units (getvar 'lunits)
        prec (getvar 'luprec) 
  )
  (vlax-for obj (vla-get-activeselectionset c_doc)
    (setq dim_style (strcase (vlax-get-property obj 'stylename))
          dim_dim (vlax-get-property obj 'measurement)
    )
    (cond ( (eq dim_style "PRECUTRC")
            (setq d1_tot (+ d1_tot dim_dim))
          )  
          ( (eq dim_style "PRECUTLC")
            (setq d2_tot (+ d2_tot dim_dim))
          ) 
          ( (eq dim_style "PRECUT")
            (setq d3_tot (+ d3_tot dim_dim))
          ) 
          ( (eq dim_style "PRECUTSC")
            (setq d4_tot (+ d4_tot dim_dim))
          )
    );end_cond
  );end_for
  (alert  (strcat 
            "Dimension Style Totals : "
            "\nPrecutRC : " (rtos d1_tot units prec)
            "\nPrecutLC : "  (rtos d2_tot units prec) 
            "\nPrecut : "  (rtos d3_tot units prec) 
            "\nPrecutSC : "  (rtos d4_tot units prec)
          )
  );end_alert
  (princ)
);end_defun

I am not one of the robots you're looking for

Message 10 of 12

Anonymous
Not applicable

Yes, that works great thanks so much.

 

Screenshot:

http://prntscr.com/ljbi84

 

Would it be possible to print it to the autocad command line as well / instead?   Can't copy/paste out of a alert box!

 

0 Likes
Message 11 of 12

dlanorh
Advisor
Advisor
Accepted solution

Try this

;Ron Harman
;Dimension Total By Dimstyle
(defun C:DTBD ( / c_doc ss d1_tot d2_tot d3_tot d4_tot dim_style dim_dim results)
  (vl-load-com)
  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        ss (ssget  '((0 . "DIMENSION")))
        d1_tot 0
        d2_tot 0
        d3_tot 0
        d4_tot 0
        units (getvar 'lunits)
        prec (getvar 'luprec) 
  )
  (vlax-for obj (vla-get-activeselectionset c_doc)
    (setq dim_style (strcase (vlax-get-property obj 'stylename))
          dim_dim (vlax-get-property obj 'measurement)
    );end_setq
    (cond ( (eq dim_style "PRECUTRC")
            (setq d1_tot (+ d1_tot dim_dim))
          )  
          ( (eq dim_style "PRECUTLC")
            (setq d2_tot (+ d2_tot dim_dim))
          ) 
          ( (eq dim_style "PRECUT")
            (setq d3_tot (+ d3_tot dim_dim))
          ) 
          ( (eq dim_style "PRECUTSC")
            (setq d4_tot (+ d4_tot dim_dim))
          )
    );end_cond
  );end_for
  (setq results
    (strcat 
      "Dimension Style Totals :"
      " PrecutRC : " (rtos d1_tot units prec)
      " PrecutLC : " (rtos d2_tot units prec) 
      " Precut   : " (rtos d3_tot units prec) 
      " PrecutSC : " (rtos d4_tot units prec)
    );end_strcat
  )
  (princ results)
  
  (while (vl-string-search " P" results)
    (setq results (vl-string-subst "\nP" " P" results))
  );end_while

  (alert results)
  (princ)
);end_defun

If you don't want the alert popup, remove the blue lines.

 

I am not one of the robots you're looking for

0 Likes
Message 12 of 12

Anonymous
Not applicable

Thanks a ton that should be perfect. 

0 Likes