Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trying to copy text from perticular boundry region to excel, no manual selection

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
davedt31
944 Views, 13 Replies

Trying to copy text from perticular boundry region to excel, no manual selection

Hi,
Can anyone please help me in
creating lisp for selecting text in
enclosed entity and copy it to excel.
I have tried with below lisp but its
not working out please help. I am new to lisp so there may be many flaws in this lisg please ignore those.
your help is highly appreciated,
(defun C:xport ( / ss elist at cmde
cen rad p1i)
(setq cmde (getvar "cmdecho"))
(setvar "cmdecho" 0)
(setq ss 0 elist (entget (car (ssget
"X" ' (list(( 0 . "POLYLINE" ) ( 8 .
"avn" ))))))))
(setvar "OSMODE" (boole 7 (getvar
"OSMODE") 16384))
(if (zerop (getvar "CMDACTIVE"))
(command "_select"))
(command "_wp") ; or _CP
(if (= (cdr(assoc 0 elist)) "CIRCLE")
(progn
(setq cen (cdr (assoc 10 elist))
rad (cdr (assoc 40 elist))
)
(repeat 90 ; 360/4
0.06981317=4*pi/180
(setq p1 (polar cen (* ss
0.06981317) rad) ss (1+ ss))
; (command "_POINT" (trans p1 0
1))
(command (trans p1 0 1))
)); else
(repeat (length elist)
(setq at (nth ss elist) ss (1+ ss))
; (if (= (car at) 10) (command (cdr
at)))
(if (= (car at) 10) (command (trans
(cdr at) 0 1)))
)
);if CIRCLE
(command "")
(setvar "OSMODE" (boole 2 (getvar
"OSMODE") 16384))
(setvar "cmdecho" cmde)
(progn
(setq fname (getfiled "Save Text File
As:" "" "csv" 1))
(setq fn (open fname "w"))
(setq i -1)
(repeat (sslength ss)
(setq i (1+ i))
(setq en (ssname ss i)
elist (entget en)
txt (cdr (assoc 1 elist)))
(write-line txt fn))
(close fn)))
(princ (strcat "\n* Text file " fname
" \n has been created *"))
(setvar "cmdecho" 1)
(setq fn fname)
(startapp (strcat "Notepad " (chr 34)
fn (chr 34)))
(princ))
)
Thanks in advance.
13 REPLIES 13
Message 2 of 14
pbejse
in reply to: davedt31


@davedt31 wrote:
Hi,
Can anyone please help me in creating lisp for selecting text in enclosed entity and copy it to excel.
I have tried with below lisp but its not working out please help. I am new to lisp so there may be many flaws in this lisg please ignore those.
your help is highly appreciated,

Thanks in advance.

I had a hard time understanding the sequence of your posted code. Maybe you can describe for us what you are wanting to do. Better yet, attached a sample drawing and excel file here davedt3.

 

 

 

Message 3 of 14
davedt31
in reply to: davedt31

Hi,
Thanks for the reply and sorry for the trouble. I am looking for a lisp, in which I can export the text enclosed in polylines to excel without manual selection Those polylines will be in some perticular layers. I used entsel, and then after picking closed loop polylines manualy it is selecting everything inside those polylines, but I am not able to export it to excel. Sorry if I am confusing... please reply...
Thanks in advance.
Message 4 of 14
pbejse
in reply to: davedt31


@davedt31 wrote:
Hi,
Thanks for the reply and sorry for the trouble. I am looking for a lisp, in which I can export the text enclosed in polylines to excel without manual selection Those polylines will be in some perticular layers. I used entsel, and then after picking closed loop polylines manualy it is selecting everything inside those polylines, but I am not able to export it to excel. Sorry if I am confusing... please reply...
Thanks in advance.

Is there a particular layer for  TEXT inside the polyline ? what properties of the text you want to export? the string value? the insertion point? Like i said before, a drawing sample would be better for us to understand your need davedt31

 

 

Message 5 of 14
Hallex
in reply to: davedt31

Adopt this file to your suit Dave

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 6 of 14
pbejse
in reply to: Hallex

Cool mod Oleg, have to admit, i dont rally understand the code the OP posted till i saw you modifcation, then it clicks 🙂

 

Cheers my friend 

Message 7 of 14
pbejse
in reply to: pbejse

Another approach [Play time for pBe]

 

(defun c:ShowMe	(/ _outside-p text ss Pline Txtinside i e entdata spc)
(defun _outside-p (pt ent / YoRay len)
;;;		pBeFeb20014				;;;
;;; http://en.wikipedia.org/wiki/Point_in_polygon	;;;
;;;	  	even-odd rule				;;;
    (setq YoRay
	   (entmakex (list
		       '(0 . "RAY")
		       '(100 . "AcDbEntity")
		       '(100 . "AcDbRay")
		       (cons 10 pt)
		       '(11 1.0 0.0 0.0)
		     )
	   )
    )
    (setq len (/  (length (vlax-invoke
			(vlax-ename->vla-object YoRay)
			'intersectwith
			ent
			acextendnone
		      )
	      ) 3)
    )
    (entdel YoRay)
    (zerop (rem len 2))
  )

  (if (setq text      nil
	    Pline     nil
	    Txtinside nil
	    ss	      (ssget "_X"
			     (list '(-4 . "<OR")
				   '(-4 . "<AND")
				   '(0 . "LWPOLYLINE")
				   '(8 . "avn")
				   '(-4 . "AND>")
				   '(-4 . "<AND")
				   '(0 . "TEXT")
				   '(8 . "Anno-Text")
				   '(-4 . "AND>")
				   '(-4 . "OR>")
				   (cons 410 (getvar 'ctab))
			     )
		      )
      )
    (progn
      (repeat (setq i (sslength ss))
	(setq e	      (ssname ss (setq i (1- i)))
	      entdata (entget e)
	)
	(if (eq "TEXT" (cdr (assoc 0 entdata)))
	  (setq text (cons (list e (cdr (assoc 10 entdata))) text))
	  (setq Pline (cons (vlax-ename->vla-object e) Pline))
	)
      )
      (foreach itm text
	(if (setq hit (vl-some '(lambda	(pl)
				  (if (not (_outside-p (Cadr itm) pl))
				    (car itm)
				  )
				)
			       pline
		      )
	    )
	  (setq	Txtinside (cons hit Txtinside)
	  )
	)
      )
      (foreach tx Txtinside (print (cdr (assoc 1 (entget tx)))))
    )
  )(princ)
)

 

 NOT THOROUGHLY TESTED

 

HTH

Message 8 of 14
davedt31
in reply to: Hallex

Hi Hallex,

Sorry for late reply, your script is excellent, it is he same thing I was looking for, but it is not exporting all the text to excel.
Can you suggest the modification. Sorry for bothering you.

Thanks in advance.
Message 9 of 14
davedt31
in reply to: pbejse

Hi pbejse,

Thanks for your script, your script is exactly what I am looking for, but its not exporting text to excel, can you please help me in this?
Thanks in advance...
Message 10 of 14
pbejse
in reply to: davedt31


@davedt31 wrote:
Hi pbejse,

Thanks for your script, your script is exactly what I am looking for, but its not exporting text to excel, can you please help me in this?
Thanks in advance...

Would you settle for CSV extension and not XLS* ?

Message 11 of 14
davedt31
in reply to: pbejse

Yes I am ok with CSV as well.
Message 12 of 14
davedt31
in reply to: davedt31

Hi pbejse,

Can you please tell me how to export this text to csv?

Thanks in advance.
dave.
Message 13 of 14
pbejse
in reply to: davedt31


@davedt31 wrote:
Hi pbejse,

Can you please tell me how to export this text to csv?

Thanks in advance.
dave.

I'll have a look Davedt31. I'll get back to you....

 

EDIT: See attached File <Showme.lsp>

 

 

Message 14 of 14
davedt31
in reply to: pbejse

So sorry for so late reply, it works superb. I need one change to same lisp, instead of selecting text can I get attribute values from same selection set?

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

Post to forums  

Autodesk Design & Make Report

”Boost