Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Dimensions from Cad to a pre-existing Excel file?

Anonymous

Dimensions from Cad to a pre-existing Excel file?

Anonymous
No aplicable

If I can get as close as possible that would be awesome!

Is there a lisp and/or way to transfer dimension text to a specific cell in a pre-existing Excel template instead of it creating a new book each time?

 Thanks!

0 Me gusta
Responder
487 Vistas
11 Respuestas
Respuestas (11)

leeminardi
Mentor
Mentor

Just to be clear, you want to be able to select a single dimension line in AutoCAD and have the dimension value copied to a specific cell of an Excel spreadsheet?

 

BTW, what is the difference between an existing Excel file and a "pre-existing" file. Did the latter exist before it existed? What does that mean? 

lee.minardi
0 Me gusta

Anonymous
No aplicable
That would be interesting, but no, I meant existing, and yes that is the
gist of it.
0 Me gusta

leeminardi
Mentor
Mentor

Would the following be acceptable?

1. The user selects a dimension line in AutoCAD, gives a command and a text file is automatically created.  

2.  A VBA macro is run in an open Excel file and the text file is referenced and the dim value is placed in the selected cell.

 

This processed could be enhanced such that the user is prompted for a cell address when giving the command in AutoCAD and then referenced when the macro is run in Excel. 

lee.minardi
0 Me gusta

Anonymous
No aplicable
That sounds great! Just to be clear, however, this can be used for multiple
dimensions at one correct?
0 Me gusta

leeminardi
Mentor
Mentor

Please be more specific about how to handle multiple dimensions.  For example:

Pla A

1. User selects several dimensions, gives command.

2. In Excel all the dimension values are place in one cell.

 

or 

Plan B

1. User selects several dimensions, gives command.

2. In Excel the first dimension value is placed in the selected  cell and other values  successively in cells below it.

 

or 

Plan C

1. User gives command and then is prompted to select a dimension line then asked for a cell number, the process is repeated until the user indicates he/she is done.

2. In Excel the dimensions are placed in their respective cells.

 

or something else?

lee.minardi
0 Me gusta

Anonymous
No aplicable
Plan B would be perfect thank you!
0 Me gusta

leeminardi
Mentor
Mentor

The following vlisp program creates a CSV file of the values of selected dimension lines.  It can be directly opened by Excel and then copy and pasted to wherever you wish.

(defun c:getdims (/ fn)
					; create a csv file of selected dimension lines.
					; LRM 1/16/2019
					;  
  (setq f (getfiled "Create Output File" "" "csv" 1))
  (setq fn (open f "w"))
  (if (setq ss (ssget '((0 . "DIMENSION"))))
    (progn
      (setq i 0)
      (while (setq en (ssname ss i))
	(setq ed (entget en))
	(setq dv (cdr (assoc 42 ed)))
	(if (= (cdr (assoc 70 ed)) 34)	; check if angular dim
	  (setq dv (/ (* dv 180) 3.xxx-xxxxxxxx))
	)
	(write-line (rtos dv) fn)

	(setq i	(1+ i)
	)				; end setq i
      )					;end while
    )					; end progn
  )					;end if
  (close fn)
  (princ "\n File ") (princ f) (princ " created.")
  (princ)
)

 

lee.minardi
0 Me gusta

Anonymous
No aplicable
That's awesome! Thank you so much!
0 Me gusta

leeminardi
Mentor
Mentor

You are welcome.

Somehow the line in the code above :

 

  (setq dv (/ (* dv 180) 3.xxx-xxxxxxxx))

was not what I copied into my post.  That line should read:

 (setq dv (/ (* dv 180) 3.xxx-xxxxxxxx))

It converts the angle value from radians to degrees.  The code in the attached program GetDims.lsp is correct.

 

lee.minardi
0 Me gusta

Anonymous
No aplicable

@leeminardi, if you post a number that's a certain amount of digits long, the forums will automatically replace it with xxxxx as it is the length of the Autodesk activation key (or maybe license number, I can't remember). it's to stop people posting registration information but it works on any number with that many digits.

0 Me gusta

leeminardi
Mentor
Mentor

Thanks @Anonymous, I did not know that the forum software did that.  It would have driven me nuts to figure out what was going on.  Thanks for saving my sanity!

lee.minardi
0 Me gusta