Jump to content

Recommended Posts

Posted

Either an Excel file or .CSV file would be fine.

 

Pline1 xy xy xy xy

ITRP;

33624;

52;

 

Ideally one column per line of text.

  • 2 weeks later...
  • Replies 47
  • Created
  • Last Reply

Top Posters In This Topic

  • Drafty

    21

  • BIGAL

    20

  • pBe

    3

  • Tyke

    1

Top Posters In This Topic

Posted Images

Posted (edited)

This code works but found out a few things like if text is contained within 2 polygons it will find it twice. If I run it on your dwg it does not work, if I copy bits of your dwg then it works I am not sure what is causing error maybe something about blank polygons with no objects. Will try to find

 

(vl-load-com)
(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 coordsxy (cons xy coordsxy))
(setq I (+ I 2))
) ; end repeat
) ; end defun
; program starts here
(setq plobjs (ssget (list (cons 0 "lwpolyline"))))
(setq numb1 (sslength plobjs))
(setq x numb1)
(repeat numb1
(setq obj (ssname plobjs (setq x (- x 1))))
(setq co-ords (getcoords obj))
(co-ords2xy)
; write pline co-ords here
(setq ss (ssget "WP" coordsxy (list (cons 0 "Text,Mtext")))) ; selection set of text within polygon
(setq coordsxy nil) ; reset for next time
(setq numb2 (sslength ss))
(setq y numb2)
(repeat numb2
(setq anstext (vlax-get-property (vlax-ename->vla-object (ssname ss (setq y (- y 1)))) "Textstring"))
(princ anstext) ; change to write text to file
(princ "\n")
) ; end repeat2
(setq ss nil) ; reset for next poly
) ; end repeat1
(princ)

Edited by BIGAL
Posted

Good work BigAl, Cheers.

What is the command line text i should type in to run the programme?

Posted

I have been trying to get it to work and found a few problems your polygons are doubled up and possibly overlapping line work and so does not work, if you just draw a closed pline put some text in will work. I have not finished it because it will not work properly with your drawing but any I make works perfect.

 

Just save the code via Notepad call it say text in poly.lsp then appload "text in poly" it will ask for selection pick all on screen.

 

Somebody out there ? any suggestion re his drawing ?

Posted

i keep getting this error when trying to load it:

 

Getpoly.lsp successfully loaded.

Command: ; error: syntax error

Command:

Posted

When you copied it into notepad did you copy all of it you must scroll down, I copied it from here and ran it works ok.

Posted

ahh yes, that now works in as much as i can select multiple polylines. i recive this error instead whether i select items from the existing drawing or from a new drawing:

 

Select objects:

; error: no function definition: VLAX-ENAME->VLA-OBJECT

Command:

 

Did you manage to successfully output the information into an excel spreadsheet?

Posted

Hi Drafty

 

First add (VL-load-com) as first line of code, second I stopped because I could not get it to work with your drawing, I need help anyone out there ? something about your drawing.

 

As a test just draw a few closed plines add some text and mtext you should see result on screen press F2. this is what would be output plus co ordinates.

Posted

It appears not to work in my drawing as you have confirmed. I then created a new drawing with some MTEXT and got this result in the command line:

 

Select objects:

test\P123\P56\Pgreen

 

Where are the coordinates though?

 

I will have a play round with my drawing some more to see if i can ascertain the issue.

 

Thanks for your persistance with this :-)

Posted

As I implied I didn't finish it the x y variables are in 2 places co-ords & co-ordsxy just two different ways of making a list of the co-ords. I was just going to write out co-ords as excel will read it as space delimited.

 

old (setq co-ords (getcoords obj))

new (setq co-ords (getcoords obj))
(princ co-ords)

Posted

I have copied the entire contents of the drawing and pasted it into a new file. When i run the lisp routine it now picks up the polygons and text. Maybe the file has corrupted or something?!

Posted

Will try to find time I dont have much spare time at moment to finish

Posted (edited)

Have a look at this needs some refining not much time at moment use space delimeted into excel

 

(vl-load-com)
(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 coordsxy (cons xy coordsxy))
(setq I (+ I 2))
) ; end repeat
) ; end defun
; program starts here
; choose output file change acdatemp to what you want
(setq fname (strcat "c:/acadtemp/" (getstring "\nEnter file name ")))
(setq fout (open fname "w"))
(setq plobjs (ssget (list (cons 0 "lwpolyline"))))
(setq numb1 (sslength plobjs))
(setq x numb1)
(repeat numb1
(setq obj (ssname plobjs (setq x (- x 1))))
(setq co-ords (getcoords obj))
(co-ords2xy)
; write pline co-ords here
(setq numb3 (length co-ords))
(setq z numb3)
(setq ansco-ords "")
(repeat numb3 
(setq ansco-ords (strcat ansco-ords (rtos (nth (setq z (- z 1)) co-ords) 2 3 ) " " ))
)
(setq ans (strcat "Pline " ansco-ords))
(write-line ans fout)
(setq ansco-ords "")
(setq ss (ssget "WP" coordsxy (list (cons 0 "Text,Mtext")))) ; selection set of text within polygon
(if (= ss nil) 
(princ "\nnothing inside")
(progn 
(setq coordsxy nil) ; reset for next time
(setq numb2 (sslength ss))
(setq y numb2)
(repeat numb2
(setq anstext (vlax-get-property (vlax-ename->vla-object (ssname ss (setq y (- y 1)))) "Textstring"))
(princ anstext) ; change to write text to file
(write-line (strcat "text " anstext) fout)
(princ "\n")
) ; end repeat2
(setq ss nil) ; reset for next poly
)
)
) ; end repeat1
(close fout)
(princ)

Edited by BIGAL
Posted

Enter file name test

Select objects: 1 found

Select objects:

; error: no function definition: VLAX-ENAME->VLA-OBJECT:unsure:

Posted

my guess

(vl-load-com)

is missed, put this one at the start of lisp

Posted

Thanks for the reply fixo. I have now got this error message!

 

Select objects:

Pline 2086.866 -3770.095 2086.866 -2220.239 2693.972 -2220.239 2693.972

-3770.095

ABC\P123\P1\PTESTtext ABC\P123\P1\PTEST

 

Pline 1579.479 -1333.768 1579.479 -3033.326 1940.223 -3033.326 1940.223

-1333.768

ABC2\P1232\P12\PTEST2text ABC2\P1232\P12\PTEST2

 

; error: bad argument type: streamp nil

Posted

BigAl,

I have attached the drawing that you are familiar with along with a new one which contains two polygons and text inside each of them.

 

The error message comes up on both drawings so i imagine its not drawing related?

 

Thanks

Existing Basket.dwg

New Basket.dwg

Posted

as Bigal already noted on the lisp

; choose output file change acdatemp to what you want

 

make sure this folder exists "c:/acadtemp/" otherwise change it to whatever folder you want. [existing that is]

Posted

pBe,

Thanks but i still get the same error message

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...