Jump to content
Drafty

Extracting X,Y, coordinates with Handle

Recommended Posts

Drafty

I have attached an AutoCAD 2010 file as an example of what i am about to try and explain. Please bare with me. :cry:

 

I can export the x/y information in itself using the ptExport.lsp routine. I haven't found a way of exporting the entity information because i can't seem to get that one working. (both lsp files attached)

 

What i actually require is being able to extract the polygon x,y, information along with the corresponding text within the polygon itself i.e ITRD 33651 37, and ideally the entity handle itself.

 

If you understood that, firstly thanks.

If you know how to help then i would forever in your debt.:geek:

 

Thanks in advance for looking

 

Note i have to do this for somewhere in excess of 5000 polygons!! GULP!

Basket.dwg

PtExport.lsp

gethandle.lsp

Share this post


Link to post
Share on other sites
BIGAL

A couple of ideas when doing a ssget you can do "WP" within polygon so do a ssget first make a list of polygons actually they are plines then use that polygon ID for your "WP" in the second ssget.

 

Secondly theres lots of point from pline routines search here or Lee-mac.com

 

You need this also for the code below to work tested with 4 points

 

(setq ss (ssget "WP" (list pt1 pt2 pt3 pt4) (list (cons 0 "Text,mtext"))))
; replace (list pt1 pt2 pt3 pt4) with say (setq newlst (pts returned from pline vertex's))
(setq ss (ssget "WP" newlist (list (cons 0 "Text,mtext"))))
;then foreach or repeat x times
(setq ans (entget (ssname ss x))) 
(setq handle (assoc 5 ans))
(setq text (assoc 2 ans) ; need different for mtext walk line by line

 

PS your dwg has the text etc twice in some cases.

Share this post


Link to post
Share on other sites
Drafty

Thanks for your reply 'BIGAL'.

Although i have been a CAD design draughtsman for many years i am on very unfamilar ground with this. What is 'ssget'? What is a point from pline routine?

 

The text isn't quite duplicated, what the drawing depicts is cable baskets at different levels. The numbers are all the same but fo one digit.

 

Thanks, for your help :-)

Share this post


Link to post
Share on other sites
BIGAL

The code example by me is lisp code.

 

You need a programming language to do what you want hence the example in lisp you can use VBA .Net C## maybe even a Autocad macro to do what you want.

 

Have you written any programs ? Do you have basic lisp skills ? Because you posted the lisps you are using I assumed that you understood how to write programs.

 

Ssget is "get a selection set of objects" the you can drill down and retrieve the properties of the object such as the vertices that make up a pline.

 

Using "WP" this is within a ploygon so it will only search within a certain area, "X" is complete drawing

 

cons 0 "text" is a filter only look for text objects used with "X" it would every bit of text in your drawing

 

adding cons 8 "Connections" would mean search within polygon for text objects on layer "Connections"

Share this post


Link to post
Share on other sites
Drafty

Thanks for the explantions.

No i haven't written any programs at all. I downloaded the lisp files from this site.

I think i need to look for a "dummies" guide to writing lisp scripts?!

I have a feeling it will take me a considerable amount of time to write what i need so i may have to resort to doing it the long winded way!

Share this post


Link to post
Share on other sites
BIGAL

Its not that hard its just a case of getting the two or 3 programs you need and glueing them together you have the first two you need a 3rd which is what I was hinting at.

 

So you want the polygon x,y points and the text within thats ok why do you want the handle ? Also when you get all this info how do you really want it exported as a CSV file, simple column text file or straight into excel etc

 

The rtos is exporting 8 decimals do you need that many ?

 

(setq pnt (trans pnt 0 1));;**CAB
;at this point you would do a CONS to make a list of all the points in that pline and then use it in the ssget 

Share this post


Link to post
Share on other sites
Drafty

I was thinking that i could extract the handle and associate that with the text, as some of the text in my other drawings doesn't sit within the confinds of the polygon.

I need it in a simple .csv file so that i can import it into a software database.

 

What is rtos?

Share this post


Link to post
Share on other sites
Tyke
What is rtos?

 

rtos = real to string. It's a LISP function that converts a real number into a string.

Share this post


Link to post
Share on other sites
BIGAL

Your changing the rules text outside now, do you just want all text drawn on a single layer and its xy ? this is easy.

 

(setq ss (ssget "X" (list (cons 0 "Text,mtext")(cons 8 "mylayer"))))

Share this post


Link to post
Share on other sites
Drafty

I give up. I simply don't understand how to do it. Thanks all for your help.

Share this post


Link to post
Share on other sites
BIGAL

Dont give up that easy

 

Have a look at this similar problem with solution http://www.cadtutor.net/forum/showthread.php?78109-Block-by-windowing-lisp

 

What I was saying is your asking 2 questions needs 2 different answers.

 

Also pretty sure handles are unique so no 2 would be alike so can not find object in 2nd dwg.

 

Also its about time this is a free forum so we still have to work and play. I would have done it for you but I am busy, I do repsonses in my lunch time not company time.

Share this post


Link to post
Share on other sites
Drafty

Hi BigAl,

Thanks again for your comment.

What i would probably do with text that currently sits outside the polygons is move them inside. That will make things a lot quicker than trying to write two pieces of code!

 

I appreciate that the forum is free and i don't expect people to give-up hours of their free time to right a code for someone that is a newbie to the forum.

 

I am greatful for your input, it has helped. I will persist a bit longer with finding an online manual to help me wite this code.

 

Thanks

Share this post


Link to post
Share on other sites
BIGAL

I have made a start this pulls co-ords from pline very simple method and then allows ssget to find text it needs some debugging but a start next will be to create a loop for all plines selected.

 

(defun getcoords (ent)
 (vlax-safearray->list
   (vlax-variant-value
     (vlax-get-property
   (vlax-ename->vla-object ent)
   "Coordinates"
     )
   )
 )
)

(defun co-ords2xy ()
; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
(setq numb (/ (length co-ords) 2))
(setq I 0)
(repeat numb
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
)
)
; program starts here
(setq co-ords (getcoords (car (entsel "\nplease pick pline"))))
(co-ords2xy)
(setq ss (ssget "WP" co-ordsxy (list (cons 0 "*text")))) ; selection set of text within polygon

Edited by BIGAL

Share this post


Link to post
Share on other sites
BIGAL

Fixed a mistake in code

Share this post


Link to post
Share on other sites
Drafty

I have tried your code on the dwg file i attached at the start of this thread. It doesn't seem to pick up any of the polygons.

On a positive note though i am working my way through the online tutorial and so i am starting to pick up and understand the odd bits of text

Share this post


Link to post
Share on other sites
BIGAL

I will check it and if I have time add the missing do all plines.

Share this post


Link to post
Share on other sites
BIGAL

an upgrade still work in progress a bit busy right now

 

(defun getcoords (ent)
 (vlax-safearray->list
   (vlax-variant-value
     (vlax-get-property
   (vlax-ename->vla-object ent)
   "Coordinates"
     )
   )
 )
)

(defun co-ords2xy (/ xy)
; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
(setq numb (/ (length co-ords) 2))
(setq I 0)
(repeat numb
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 2))
)
)
; program starts here
(setq plist (ssget (list (cons 0 "lwpolyline"))))
(setq numb (sslength plist))
(setq J 0)
(repeat numb
(setq co-ords (getcoords (ssname plist J)))
(co-ords2xy)
(setq ss (ssget "WP" co-ordsxy (list (cons 0 "*text")))) ; selection set of text within polygon
(princ (sslength ss)) ; this is howmany texts etc 
(setq co-ordsxy nil)
(setq J (+ J 1))
(setq ss nil)
) ; end repeat

Share this post


Link to post
Share on other sites
Drafty

I am over the moon that you are helping me with this Big Al.

I have run the lisp and it is now picking up multiple polygons :-)

 

Thank you

Share this post


Link to post
Share on other sites
BIGAL

What are you trying to achieve in terms of output a simple TXT file or excel or a CSV

 

pline1 xy xy xy xy

text1 abcde

text2 addd

pline2 xy xy xy xy

text3 jjjj

pline4 and so on ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×