Text to Block LISP

Text to Block LISP

gustavo.dower
Explorer Explorer
4,356 Views
6 Replies
Message 1 of 7

Text to Block LISP

gustavo.dower
Explorer
Explorer

Hello Everyone,

 

I have a file with 1.000+ text elements and wish to make them block references where the name or attribute is their current text value.

 

Thank you in advance for any tips.

0 Likes
Accepted solutions (1)
4,357 Views
6 Replies
Replies (6)
Message 2 of 7

john.uhden
Mentor
Mentor

Question #1:  Why?

Question #2:  Is that ALL the text entities, or only ones on certain layer(s) or color(s) or style(s) or height(s), or containing certain string(s)

Question #3:  Do you mean one (1) block definition with one (1) attribute each, and do you already have a block definition?

Question #4:  Is the block definition in just the drawing that you want to process, or is it located as a DWG in AutoCAD's search path?

Question #5:  Are the text entities at different angles and alignments, and do they want to stay in the same location and orientation as attributes?

Question #6:  Are the text entities connected to any registered application or some kind of database extraction thingy?

Question #7:  Does any of the text entities belong to any group(s)?

John F. Uhden

0 Likes
Message 3 of 7

gustavo.dower
Explorer
Explorer
First of all thank you for your response. #1 I'll later on assign two parameters for the defined block which will be in a second stage manually populated with ones and zeroes for each individual block reference based on GIS image.
The project consists of a water distribution network and the text on the dwg represents the name of each link. The main purpose is to define if the link goes through paved or unpaved sidewalk based on a GIS image. My idea was to assign a value of 1 to an attribute if it was on a paved sidewalk and 0 if it wasn't. In order to do that I would need the links defined as block references with its name and a Boolean function.
Later I would just extract the data to a xls file and match link name to a previous spreadsheet.
#2 ALL
#3 One block definition where the texts are the name or the attribute of the block reference, doesnt really matter.
#4 just in this drawing
#5 at least same location, same orientation would help also but not a priority
#6 no
#7 no

Hope you or someone can help me with this or at least give me any sort of guidance.
0 Likes
Message 4 of 7

john.uhden
Mentor
Mentor

What about the lengths through various surfaces?  If you had closed polylines representing the limits of surfaces (like a soils map), then we/you could get totals of the various types of demolition/excavations and trench repairs.  And if the pipes were polylines either on layers representing their diameter or widths representing their diameter, then we could break down the quantities by pipe size.  Or might you be using directional drilling?

 

Pardon me, but I have this habit of looking at the bigger picture.

John F. Uhden

0 Likes
Message 5 of 7

m_badran
Advocate
Advocate
Accepted solution

Hi,maybe this code help,you can convert all text to att text and make them as  one block.

;;-------------------=={ Text 2 Attribute }==-----------------;;
;;                                                            ;;
;;  Converts single-line text to an attribute definition.     ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;

(defun c:txt2att ( / el i ss st ) (vl-load-com)
 
  (if (setq ss (ssget "_:L" '((0 . "TEXT"))))
    (repeat (setq i (sslength ss))
      (setq el (entget (ssname ss (setq i (1- i))))
            st (vl-string-translate " " "_" (cdr (assoc 1 el)))
      )
      (if
        (entmakex
          (append '((0 . "ATTDEF"))
            (vl-remove-if '(lambda ( pair ) (member (car pair) '(0 100 73))) el)
            (list
              (cons 70  0)
              (cons 74 (cdr (assoc 73 el)))
              (cons  2 st)
              (cons  3 st)
            )
          )
        )
        (entdel (cdr (assoc -1 el)))
      )
    )
  )
  (princ)
)

 

 

0 Likes
Message 6 of 7

gustavo.dower
Explorer
Explorer

Not exactly what I wanted because every text becomes an attribute, but it will do the trick.

 

Thank you!

0 Likes
Message 7 of 7

m_badran
Advocate
Advocate

 


@gustavo.dower wrote:

Not exactly what I wanted because every text becomes an attribute, but it will do the trick.

 

Thank you!


you're welcome.

0 Likes