Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Data extraction

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
879 Views, 8 Replies

Data extraction

I have a problem with data extraction. The following image is a part of my Autocad file. I need to extract the XY coordinates of the tip of every line, and the number corresponding (i.e. 85 in the example). It must be automatic since there is about 3000 of these...

 

Every element is composed of 1 text, 1 circle and 1 polyline.

 

Thanks!!!!

 

 

 

exemple_autocad.png<

 

P.S. I'm using AutoCAD Civil 3D 2013, but I have access to other versions if needed.

8 REPLIES 8
Message 2 of 9
drjohn
in reply to: Anonymous

 don't have need to do data extraction in my work, but perhaps if you make a block out of the text, circle, line with the insertion point as the tip of the line (the location you indicated you want).

 

If that fails, perhaps include a field that reports the insertion point of the block and read the fields in the data extraction.

 

 

Regards,

DJ

.

Message 3 of 9
jggerth
in reply to: Anonymous

if those elements are not a block, but are a circle, a piece of text, and a line, then you'll need some 'interesting' custom programming to get data out that associates the line, the end point of the line away from the circle, and the text inside the circle all together.

 

If they are blocks, and the insertion point is the endpoint you need to Id, and the text is an attribute, then dataextraction will work nicely.  Migh even work if they are Mleaders with a block and attribute....

Message 4 of 9
dbroad
in reply to: Anonymous

I agree with 

Architect, Registered NC, VA, SC, & GA.
Message 5 of 9
heinsite
in reply to: jggerth


@jggerth wrote:
  Migh even work if they are Mleaders with a block and attribute....

I had to give this a shot since it sounded so promising.   But alas, it didn't work.  AutoCAD doesn't see an mleader with mleadertype = block as a block.

 

So the solution would be to build a custom block that looks like a leader and has the numbering value as an attribute.  That could be data extracted.  But not the mleader.

 

Dave.

------------------------------------------------------
Dave Hein, P.E.
Message 6 of 9
3wood
in reply to: Anonymous

If you only need data format as [Number, related X, related Y] in a csv file, it won't be hard to do with a lisp routine.

Message 7 of 9
Anonymous
in reply to: 3wood

3wood, how can I do it automatically? Sorry, I'm not an Autocad pro...

 

I might be able to write a lisp to get the data for 1 point. But I need to extract it for about 3000 points.

Message 8 of 9
Ajilal.Vijayan
in reply to: Anonymous

If its not late

Please try the attached code.

 

This program should run on the file that only contains the Circle, Line and Text.

 

Also the program assumes the following.

 

1.The lines are exactly touching the Cicrle.

2.The text is not mtext and the insertion is Middle center.

3.The text insertion point and Circle center point is same.

 

A coordinate list should create at the same folder where the drawing file resides.

 

Click the Plus sign for the code.

Spoiler
(vl-load-com)
(defun C:CPLNTS( / ss_Circle ss_Pline ss_Text int tn tn1 tn2 ary ary_lst Cir_Ins Txt_Ins Tpline Tcir My_List Req_Crd )

(setq My_List '())

(defun get_Pline_Coord (intpnt obj / Orig_Pnt P1 P2 ret_crd)
(setq P1 (vlax-curve-getstartpoint obj))
  (setq P2 (vlax-curve-getendpoint obj))
  (setq Orig_Pnt intpnt)


(cond
((equal Orig_Pnt P1 0.000001)(setq ret_crd P2))
((equal Orig_Pnt P2 0.000001)(setq ret_crd P1))
);cond
  ;(princ ret_crd)
  );get_Pline_Coord

(defun Write_to_Txt(Crd_List)
(setq fname (open (strcat  (getvar "dwgprefix") "Crd_List.txt")"W"))

(foreach n Crd_List
(write-line n fname)
);for each
(close fname)
  );Write_to_Txt

(setq ss_Circle (ssget "X" (list (cons 0 "CIRCLE"))))
(setq ss_Pline (ssget "X" (list (cons 0 "LWPOLYLINE"))))
(setq ss_Text (ssget "X" (list (cons 0 "TEXT"))))

(setq tn 0)
(repeat (sslength ss_Circle);loop through each Circle
(setq Tcir (vlax-ename->vla-object (ssname ss_Circle tn)))

(setq tn1 0)
(repeat (sslength ss_Pline);loop through each polyline
(setq Tpline (vlax-ename->vla-object (ssname ss_Pline tn1)))

(setq int (vla-intersectwith Tcir Tpline acExtendNone))

 (if int ;if intersection found
(progn

  (setq ary (vlax-variant-value int))
   (if (< 0 (vlax-safearray-get-u-bound ary 1))
   (progn
    (setq ary_lst (vlax-safearray->list ary))

(setq Found_Circle (entget (vlax-vla-object->ename Tcir)))
(setq Cir_Ins (cdr(assoc 10 Found_Circle)))

(setq tn2 0)
(repeat (sslength ss_Text)
(setq Ttext (entget (ssname ss_Text tn2)))
(setq Txt_Ins (cdr(assoc 11 Ttext)))

(if (equal Cir_Ins Txt_Ins)
(progn
(setq Req_Crd(get_Pline_Coord ary_lst Tpline))
(setq tline (strcat (cdr(assoc 1 Ttext)) "," (rtos (car Req_Crd) 2 3) "," (rtos (cadr Req_Crd) 2 3)))
(setq My_List (append (list tline)My_List))

);progn 
);if
(setq tn2 ( + 1 tn2))
);repeat text
	
	
);progn
);if

);progn
);if

(setq tn1 ( + tn1 1))
);repeat polyline

(setq tn ( + tn 1))
);repeat circle

(Write_to_Txt My_List)

);defun



 

 

Message 9 of 9

I updated the code to remove the entities that already processed.

 

I used the suggestion by Lee Mac to use List instead of Repeat through Selection Set. from here

 

But still its taking time to process 3000+ objects.

 

 

Code here.

Spoiler
(vl-load-com)
(defun C:CPLNTS( / ss_Circle ss_Pline ss_Text int tn tn1 tn2 ary ary_lst Cir_Ins Txt_Ins Tpline Tcir My_List Req_Crd )

(setq My_List '())

(defun get_Pline_Coord (intpnt obj / Orig_Pnt P1 P2 ret_crd)
(setq P1 (vlax-curve-getstartpoint obj))
  (setq P2 (vlax-curve-getendpoint obj))
  (setq Orig_Pnt intpnt)


(cond
((equal Orig_Pnt P1 0.000001)(setq ret_crd P2))
((equal Orig_Pnt P2 0.000001)(setq ret_crd P1))
);cond
  ;(princ ret_crd)
  );get_Pline_Coord

(defun Write_to_Txt(Crd_List)
(setq fname (open (strcat  (getvar "dwgprefix") "Crd_List.txt")"W"))

(foreach n Crd_List
(write-line n fname)
);for each
(close fname)
  );Write_to_Txt

(setq ss_Circle (ssget "X" (list (cons 0 "CIRCLE"))))
(setq ss_Pline (ssget "X" (list (cons 0 "LWPOLYLINE"))))
(setq ss_Text (ssget "X" (list (cons 0 "TEXT"))))


(setq ss_Circle (mapcar 'cadr (ssnamex ss_Circle)))
(setq ss_Pline (mapcar 'cadr (ssnamex ss_Pline)))
(setq ss_Text (mapcar 'cadr (ssnamex ss_Text)))

(foreach Cir_Ob ss_Circle ;loop through each Circle
(setq Tcir (vlax-ename->vla-object Cir_Ob))


(foreach Pln_Ob ss_Pline ;loop through each polyline
(setq Tpline (vlax-ename->vla-object Pln_Ob))

(setq int (vla-intersectwith Tcir Tpline acExtendNone))

 (if int ;if intersection found
(progn

  (setq ary (vlax-variant-value int))
   (if (< 0 (vlax-safearray-get-u-bound ary 1))
   (progn
    (setq ary_lst (vlax-safearray->list ary))

(setq Found_Circle (entget (vlax-vla-object->ename Tcir)))
(setq Cir_Ins (cdr(assoc 10 Found_Circle)))


(foreach Txt_Ob ss_Text ;loop through each text
(setq Ttext (entget Txt_Ob))
(setq Txt_Ins (cdr(assoc 11 Ttext)))

(if (equal Cir_Ins Txt_Ins)
(progn
(setq Req_Crd(get_Pline_Coord ary_lst Tpline))
(setq tline (strcat (cdr(assoc 1 Ttext)) "," (rtos (car Req_Crd) 2 3) "," (rtos (cadr Req_Crd) 2 3)))
(setq My_List (append (list tline)My_List))
(setq ss_Text (vl-remove Txt_Ob ss_Text))
(setq ss_Pline (vl-remove Pln_Ob ss_Pline))
(setq ss_Circle (vl-remove Cir_Ob ss_Circle))
);progn 
);if

);repeat text
	
	
);progn
);if

);progn
);if


);repeat polyline



);repeat circle

(Write_to_Txt My_List)

);defun




 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost