LISP to extract coordinates of bottom left and top right corners of a map or 3D model

LISP to extract coordinates of bottom left and top right corners of a map or 3D model

MattAAM
Contributor Contributor
902 Views
4 Replies
Message 1 of 5

LISP to extract coordinates of bottom left and top right corners of a map or 3D model

MattAAM
Contributor
Contributor

Hi all. 

 

Our practice has a lot of 3D models and maps used as context in our projects, and I want to create an interactive map on our internal intranet showing the areas we have available. 

 

To do this, I'm trying to extract 2 coordinate points for the bottom left and top right corners of a 'bounding box' surrounding the geometry (including blocks, lines, surfaces, etc) inside each CAD file.

 

I'm not familiar with writing LSP routines myself - I tried to get Chat GPT to write this for me with limited success.

 

Has anyone written such a script in the past, or could suggest how to go about writing one?

 

Any tips much appreciated.

 

 

 

 

0 Likes
903 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant

@MattAAM wrote:

... I'm trying to extract 2 coordinate points for the bottom left and top right corners of a 'bounding box' surrounding the geometry (including blocks, lines, surfaces, etc) inside each CAD file.

....


If that geometry is all there is inside each CAD file, then the bottom left and top right corners are directly available, as the EXTMIN and EXTMAX System Variables.  Do a ZOOM Extents before you extract them, because certain changes in the drawing may not be reflected in those System Variables until you do.

 

If there's other stuff that would make those not what you're after, but you want to select things, DrawBoundingBoxMult.lsp >here< will find the collective bounding box of multiple objects [and there are other routines out there that will do the same].  You can just omit the drawing of the rectangle from it, but use the rest to get the LL and UR results.

Kent Cooper, AIA
0 Likes
Message 3 of 5

MattAAM
Contributor
Contributor

Thanks for the fast response @Kent1Cooper !

 

The last bit I forgot to mention.. I want to run this routine on a range of files in a folder in batch, without manually opening each file. Can the EXTMIN and EXTMAX method be done this way or does that need to be done manually?

 

I also tried the LSP you linked to (thank you) - this works, but it is adaptable to automatically select all objects in the file? To answer your question, these files generally don't have other extraneous stuff that would influence the bounding box. If there's an easy way to get it to ignore text as a failsafe all the better.

0 Likes
Message 4 of 5

Kent1Cooper
Consultant
Consultant

I'm not versed in pulling information from drawing files without opening them.  I couldn't say whether things like those System Variables are available in that way -- it could be that they are not stored in any way, but are simply a result of what is stored, and therefore may not be extractable.

 

But I do expect that if they are, the ZOOM Extents thing I suggested would not be necessary.  I tried changing something in a way that changed the extents but did not affect those values [awaiting a Zoom Extents to update them, which I didn't do] and then saving/closing the drawing.  When I reopened it, the values were updated.  So in a just-opened drawing, that Zoom is not needed.

 

DBBM could easily be adjusted to just use everything, but you can also just type in ALL at its selection prompt.  It could be made to automate that omitting Text [& Mtext? & Multileaders?] if you like.

Kent Cooper, AIA
0 Likes
Message 5 of 5

Sea-Haven
Mentor
Mentor

Like Kents answer, variables extmax & extmin can be found, (getvar 'extmax), using a script you can open a dwg get these values in a lisp and do something.

 

open "d:/BIGAL/XXXX/3dcar"
(princ (getvar 'extmax))
0 Likes