Jump to content

Export dimensions from AutoCAD to a .txt file


Ampere

Recommended Posts

Hey, I'm new to this forum =) Hoping for some guidance.

 

Is there a way to export dimensions from autoCAD to a txt file?Måttsättning.jpg

I need the program to get the red dimensions and list them in a txt file.

 

Please be kind, and keep in mind that im completly new to LISP and have very little programing skills outside that but a open mind and willing to learn =)

Link to comment
Share on other sites

Hello Ampere,

 

This will get you started...

 

(defun C:GetDimLengths ( / AllDimensions CheckDimension n dimlist dimcontent filename fil )	; Define the command name, localize the variables.
(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension"))))					; Sets AllDimensions as a selection set of all Dimensions the the drawing.
(setq n 0)											; Set loop counter 0.
(setq dimlist '())										; Set dimensionslist cleared.
(repeat (sslength AllDimensions)							; Repeat for all in selectionset AllDimensions
	(setq CheckDimension (entget (ssname AllDimensions n)))				; Gets the entity
	(setq dimcontent (cdr (assoc 42 CheckDimension)))				; Reads the measured distance
	(setq dimlist (cons dimcontent dimlist))					; Adds this distance to a totallist
	(setq n (+ 1 n))								; Up the counter for next dimension
)											; End repeat
(if (setq filename (getfiled "\nFile Location..." "DimensionExport" "txt" 11))		; Make a new textfile with default name
	(progn										; When created do this.
		(setq fil (open filename "w"))						; Open the new file
		(foreach x dimlist							; For all dimensions in the totallist
			(princ (strcat (rtos x 2) "\n") fil)				; Print them in them in the textfile
		)									; Close 'foreach'
		(close fil)								; Close filewriter
		(startapp "notepad" filename)						; Open created file with notepad
		(graphscr)								; Return to screen
	)										; Close 'do this'
)											; End if
(princ)												; Silent exit
)												; End function

 

- How is the 'red' controlled? ByLayer or set in the propperties?

- Needs the list to be sorted?

Link to comment
Share on other sites

Thanks for the quick reply =D and great with all the comments.

The red text is so far only changed in properties but if its easier to extract the values from a layer i can rework the CAD file =)

Will try it out tomorrow.8):notworthy:

Link to comment
Share on other sites

change:

(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension"))))					; Sets AllDimensions as a selection set of all Dimensions the the drawing.

 

To this, to select all dimensions, where property is set to REd.

(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 62 1))))					; Sets AllDimensions as a selection set of all Dimensions the the drawing.

 

 

or to this, to select all dimensions, when a layername is known

(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 8 "YOURLAYERNAMEHERE"))))					; Sets AllDimensions as a selection set of all Dimensions the the drawing.

Link to comment
Share on other sites

If you want to pick a dimension and get its layer two methods

 

(setq obj (vlax-ename->vla-object (car (entsel "\nPick Dimension"))))
(setq lay (vla-get-layer obj))
(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 8 lay))))

 

(setq obj (entget (car (entsel "\nPick Dimension "))))
(setq lay (cdr (assoc 8 obj)))
(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 8 lay))))

Link to comment
Share on other sites

If you want to pick a dimension and get its layer two methods

 

(setq obj (vlax-ename->vla-object (car (entsel "\nPick Dimension"))))
(setq lay (vla-get-layer obj))
(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 8 lay))))

 

(setq obj (entget (car (entsel "\nPick Dimension "))))
(setq lay (cdr (assoc 8 obj)))
(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension")(cons 8 lay))))

 

Help me, case Select by Window many dimensions.

Thank you.

Link to comment
Share on other sites

Dear Aftertouch.

Change the _X to _L

 

(defun C:GetDimLengths ( / AllDimensions CheckDimension n dimlist dimcontent filename fil )	; Define the command name, localize the variables.
;(setq AllDimensions (ssget "_X" (list (cons 0 "Dimension"))))					; Sets AllDimensions as a selection set of all Dimensions the the drawing.
(setq obj (vlax-ename->vla-object (car (entsel "\nPick Dimension"))))
(setq lay (vla-get-layer obj))
[color="red"][i](setq AllDimensions (ssget "_L" (list (cons 0 "Dimension")(cons 8 lay))))[/i]
[/color](setq n 0)											; Set loop counter 0.
(setq dimlist '())										; Set dimensionslist cleared.
(repeat (sslength AllDimensions)							; Repeat for all in selectionset AllDimensions
	(setq CheckDimension (entget (ssname AllDimensions n)))				; Gets the entity
	(setq dimcontent (cdr (assoc 42 CheckDimension)))				; Reads the measured distance
	(setq dimlist (cons dimcontent dimlist))					; Adds this distance to a totallist
	(setq n (+ 1 n))								; Up the counter for next dimension
)											; End repeat
(if (setq filename (getfiled "\nFile Location..." "DimensionExport" "txt" 11))		; Make a new textfile with default name
	(progn										; When created do this.
		(setq fil (open filename "w"))						; Open the new file
		(foreach x dimlist							; For all dimensions in the totallist
			(princ (strcat (rtos x 2) "\n") fil)				; Print them in them in the textfile
		)									; Close 'foreach'
		(close fil)								; Close filewriter
		(startapp "notepad" filename)						; Open created file with notepad
		(graphscr)								; Return to screen
	)										; Close 'do this'
)											; End if
(princ)												; Silent exit
)												; End function

 

I change _X to _L but not working Select (not pick) dimensions.

Thanks.

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...