DWG files scanning and extracting coordinates

DWG files scanning and extracting coordinates

Anonymous
Not applicable
480 Views
5 Replies
Message 1 of 6

DWG files scanning and extracting coordinates

Anonymous
Not applicable

Hello, I'd like your opinion on how to best approach the following task:

I'm looking for an automated way to get the mean coordinate of lines, blocks from each DWG file (model space only) in my computer (mean and not centroid in order to get the approximate coordinates of the "central mass") and to write the mean coordinate + the file adress to a txt file (or any other file type I can later work with without AutoCad).
I need to do that in order to later search my DWG files by location/nearest to given (x, y). If there is an easier way please let me know!

I tried to approach the problem using python but the dwg format is a problem. ( I can write a scrips to do that with dxf files but that not the case)

Is it possible to do using autolisp? is it worth learning the language from 0 or should I try to manipulate some existing code?

I'd really appreciate any help 🙂

Roy.

0 Likes
481 Views
5 Replies
Replies (5)
Message 2 of 6

devitg
Advisor
Advisor

@Anonymous . please upload 2 or 3 sample.dwg , and please state what would be the MEAN point in one sample  

 

0 Likes
Message 3 of 6

devitg
Advisor
Advisor
(SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT))
(SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ)) ;_ el DWG que esta abierto-
(SETQ MODEL (VLA-GET-MODELSPACE ADOC))

(VLA-ZOOMEXTENTS ACAD-OBJ)

(SETQ VIEWCTR (GETVAR 'VIEWCTR))
0 Likes
Message 4 of 6

john.uhden
Mentor
Mentor

Gabriel,

That is such a great simple approach!

I depends on what the OP considers the "central mass."

I would look at it more complexly by gathering all the endpoints, centers and vertices, etc., and adding up all the Xs and Ys and dividing both by the number of sampled points to achieve one "average" point as your approach does.

Of course it becomes meaningless if his drawings, like ours at work, are a mixed bag of assumed coordinate systems (5000, 5000) vs. NAD83 plane coordinate systems (600000, 400000).

But if you're going to run a program that writes just one coordinate then you might as well pick it yourself because you know what the center of attention is just by inspection.

At least there's one thing we can probably agree on... save the coordinates to a file named "<DWGNAME>-Central Mass.txt" or something like that depending on language and preferred nouns and adjectives.

John F. Uhden

0 Likes
Message 5 of 6

Sea-Haven
Mentor
Mentor

My $0.05 extmax extmin divide by 2. 

 

Python can talk to Autocad, if you must do multiple dwgs then use accoreconsole with a simple script to write to a file the answer use "A" append option. The accoreconsole will scream through multiple dwgs as it does not open them. The required script would say call a lisp (load "my export dwglims")

 

Before everyone jumps in yes extmin/max can return like 0,0 & 2371235,640123 as you have some object at 0,0 that is not relevant to the rest of the dwg often a block. But can take extmax and say make a good guess of size. 

 

 

(defun lims ( )
(setq xymin (getvar 'extmax))
(setq xymax (getvar 'extmin))
(setq fo (open (setq fname "D:\\acadtemp\\limminmax.txt") "A"))
(setq dwgname (getvar 'dwgname))
(write-line (strcat dwgname "," (rtos (car xymin) 2 0) ","  (rtos (cadr xymin) 2 0) "," (rtos (car xymax) 2 0) "," (rtos (car xymax) 2 0)) fo)
(close fo)
(princ)
)
(lims)

 

Tested with multi cad open and worked fine.

Message 6 of 6

Anonymous
Not applicable

Thank you so much for the help! I'll work on it and implement your suggestions. I'll post when It's done and tell you in what way I implemented it. Also I will post my solution in case someone else would need it 🙂

0 Likes