Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

export "bounding box" coordinates of 3d solids

Status
Not open for further replies.

dciadmin

Mechanical
Jul 17, 2002
11
Hi,

anybody know of a simple routine for autocad 2002 to export all of the coordinates for 3d solids in a drawing? I am able to select multiple 3d solids in the drawing and then do a "list" on them. This shows me the "Upper Bound x", Upper Bound Y", Upper Bound Z", Lower bound x, Lower bound y, and lower bound z.

I would like to send these to a text file or to excel so I can use them to determine sizes of my individual parts (makeshift bill of materials). It just needs to do the 3d solids and nothing else.
 
Replies continue below

Recommended for you

Dear dciadmin,

The below code can create an output file containing
min and max coordinates of bounding box for selected
3DSolids.

1. copy the below code and paste it to a text file.
2. Save the text file named BBOX.LSP
3. Enter the AutoCAD environment.
4. Load the above-mentioned file using the APPLOAD command.
5. Enter the new command BBOX in the command line.
6. Select 3DSolids.
7. Enter the file name and path in file create dialog box.
8. Run EXCEL.
9. Open the output file as a comma delimited text file.
10. You will find 6 numbers in each row. The first three
are min coordinates of bounding box and the last three
are max coordinates of bounding box for each 3DSolid.



(defun c:BBox( / ss n m e vla-e minpt maxpt fp fn )
(vl-load-com)
(setq ss (ssget '((0 . "3DSOLID"))))
(setq fn (getfiled "" "" "" 7))
(if (null fn) (exit))
(setq fp (open fn "w"))
(setq n 0)
(setq m (sslength ss))
(while (< n m)
(setq e (ssname ss n))
(setq vla-e (vlax-ename->vla-object e))
(vla-getboundingbox vla-e 'minpt 'maxpt)
(setq minpt (vlax-safearray->list minpt))
(princ (car minpt) fp)(princ &quot;,&quot; fp)
(princ (cadr minpt) fp)(princ &quot;,&quot; fp)
(princ (caddr minpt) fp)(princ &quot;,&quot; fp)
(setq maxpt (vlax-safearray->list maxpt))
(princ (car maxpt) fp)(princ &quot;,&quot; fp)
(princ (cadr maxpt) fp)(princ &quot;,&quot; fp)
(princ (caddr maxpt) fp)
(princ (chr 13) fp)
(setq n (1+ n))
)
(close fp)
(princ)
)



:)
Farzad
 
Hi FH,

Your code works great!! Thank you for writing it. I now can add a couple of columns to the excel file to calculate the overall size of my parts. I would only need to output the layer that each solid is on to the excel file so I know which solid is which. The idea is to draw each part on its own layer and then run your program. This would give me the layer (and thus the part name) and its overall size from the bounding box coordinates.

Thanks again for your help. I appreciate it.

dciadmin
 
Dear dciadmin,

To get the layer name for each 3DSolid next to bounding
box coordinates in Excel worksheet, just insert the below
expressions after 20th line of previous code.

(princ &quot;,&quot; fp)
(princ (cdr (assoc 8 (entget e))) fp)

Notice:
There is a way to get an arbitrary name to each object in
AutoCAD, which it helps you to find objects by your
assigned name. But the this solution needs some more
coding. If you are interested to learn about the
above-mentioned method, you can study AutoLISP references
(Extended Datat).

:)
Farzad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor