Jump to content

Can I automate putting text elements into a 'roomtag' block?


Recommended Posts

Posted

Hi,

 

I'm trying to change existing room tags text, sometimes multi-line along with a Room Number into a 'roomtag' block to match our other drawings.

 

There's lots of them and I'd like to find a way that's faster than simply inserting the new block and deleting the text.

 

Is this possible? If so, how?

 

Thanks!

 

-Aaron Holmes.

Posted

Theres different ways it could be done basicly with a program lsp, if say text is on layer "roomname" then just find all text add block at text insert pt and put text into block attribute erase text.

 

Or pick text1 pick text2 pick block position insert block with attributes do next room.

 

You need to post a dwg or image to explain more.

Posted

Thanks for the quick response.

 

The two attributes I need to capture are on separate layers, and the pick text1 pick text2 pick block position, insert block with attributes, do next room strategy seems perfect, and will save me retyping all the room names and numbers.

 

I'm trying to get the text in the rooms on the right into the block on the left.

(Sometimes the room names go multiple lines, but I'd settle for simple and mostly effective at the moment). (Having trouble with images at the moment.)

 

I get the sense a lisp routine is the way to go here, but I don't really know how to get started.

 

Thanks,

 

Aaron.

 

SLW210 - Thanks for moving this to where it belongs.

Posted

OK. I'm trying to create some code here, but keep running into trouble.

 

Trying to pick text element 1, pick text element 2, then insert a block with those as attributes.

 

(defun C:rt ()

;get room name from text element
;get room number from text element


; insert a roomtag.
(while (setq pt (getpoint "\nPick Insertion Point."))
   (command "-insert" "ROOMTAG.DWG" "_NON" pt "" "" ""
)
;then insert the room name and room number into the block attributes
(princ)
)

 

Even the part that's actually in lisp doesn't run properly. - It keeps asking for an insertion point. I'm probably missing something simple. Help?

Posted

Getting closer?

 

;define function - Roomtag, activate with rt
(defun c:rt ( )

;get room name from text element
(setq roomname (entsel))
;get room number from text element
(setq roomnumber (entsel))
; insert a roomtag.
(while (setq pt (getpoint "\nPick Insertion Point."))
   (command "-insert" "ROOMTAG.DWG" "_NON" pt "" "" "" roomname "" roomnumber ""
   )
;then insert the room name and room number into the block attributes
)
(princ)
)

Posted

So how do I get from (entsel) to the text in the entity, so that I can use it in the insert command?

Thanks!

Posted

Try this not tested

;define function - Roomtag, activate with rt
(defun c:rt ( )
(defun picktext ()
(setq en1 (car (entsel "\nSelect text :" )))
(setq el1 (entget en1))
   (if (= (cdr (assoc 0 el1)) "TEXT")
           (setq ans (assoc 1 el1))
    )
) ;end defun
(while (setq pt (getpoint "\nPick Insertion Point."))
;get room name from text element
(picktext)
(setq roomname ans)
;get room number from text element
(picktext)
(setq roomnumber ans)
; insert a roomtag.

   (command "-insert" "ROOMTAG.DWG" "_NON" pt "" "" "" roomname "" roomnumber ""
   )
;then insert the room name and room number into the block attributes
)
(princ)

Posted

Thanks again for taking a look at this. (I particularly like how you defined then called the picktext function.)

 

I'll let you know, and post the version I end up running with once I get it working.

-Aaron.

Posted

I've got it working!

 

Thanks for the help.

 

;define function - Roomtag, activate with rt

(defun c:rt ( )
;define picktext for use later in the script
(defun picktext ()  (setq en1 (car (entsel "\nSelect text :" )))  (setq el1 (entget en1))
   (if (= (cdr (assoc 0 el1)) "TEXT")
           (setq ans (assoc 1 el1))
    )
) ;end defun


;identify pt as insertion point for roomtag
   (while (setq pt (getpoint "\nPick Insertion Point:")) 
       ;get room name from a text element
       (picktext)
       (setq roomname ans)
       ;get room number from text element
       (picktext)
       (setq roomnumber ans)

; insert a roomtag based on the information stored above

           (command "-insert" "ROOMTAG.DWG" "_NON" pt "1" "1" "0" (cdr roomname) "" (cdr roomnumber) )
   )
(princ)

)

Posted
I've got it working!

 

Thanks for the help.

 

;define function - Roomtag, activate with rt

(defun c:rt ( )
;define picktext for use later in the script
(defun picktext ()  (setq en1 (car (entsel "\nSelect text :" )))  (setq el1 (entget en1))
   (if (= (cdr (assoc 0 el1)) "TEXT")
           (setq ans (assoc 1 el1))
    )
) ;end defun


;identify pt as insertion point for roomtag
   (while (setq pt (getpoint "\nPick Insertion Point:")) 
       ;get room name from a text element
       (picktext)
       (setq roomname ans)
       ;get room number from text element
       (picktext)
       (setq roomnumber ans)

; insert a roomtag based on the information stored above

           (command "-insert" "ROOMTAG.DWG" "_NON" pt "1" "1" "0" (cdr roomname) "" (cdr roomnumber) )
   )
(princ)

)

 

Fix this:

(command "-insert" "ROOMTAG.DWG" "_NON" pt "1" "1" "0" (cdr roomname) "" (cdr roomnumber) )

 

Revise to this:

(command "-insert" "ROOMTAG.DWG" "_NON" pt "1" "0) (cdr roomname) (cdr roomnumber))

 

cheers, Steve

Posted

Thanks for your feedback Steve, however I'm not sure that helps me. When I was troubleshooting, it wanted to know x scale, y scale, rotation (1, 1, 0) and then my block asks for a second (or third) line for roomname, and I need the "" carriage return to get to the next section - which was the room number.

 

I've also updated it for multiple lines of text with different commands as follows:

 

;insert roomtag based on text
;v 1.0 - AaronHolmes Feb3, 2012
;define function - Roomtag, activate with rt

(defun c:rt ( )
;define picktext for use later in the script
(defun picktext ()  (setq en1 (car (entsel "\nSelect text :" )))  (setq el1 (entget en1))
   (if (= (cdr (assoc 0 el1)) "TEXT")
           (setq ans (assoc 1 el1))
    )
) ;end defun


;identify pt as insertion point for roomtag
   (while (setq pt (getpoint "\nPick Insertion Point:")) 
       ;get room name from a text element
       (picktext)
       (setq roomname ans)
       ;get room number from text element
       (picktext)
       (setq roomnumber ans)

; insert a roomtag based on the information stored above

           (command "-insert" "ROOMTAG.DWG" "_NON" pt "1" "1" "0" (cdr roomname) "" (cdr roomnumber) )
   )
(princ)

)


(defun c:rt2 ( )
;define picktext for use later in the script
(defun picktext ()  (setq en1 (car (entsel "\nSelect text :" )))  (setq el1 (entget en1))
   (if (= (cdr (assoc 0 el1)) "TEXT")
           (setq ans (assoc 1 el1))
    )
) ;end defun


;identify pt as insertion point for roomtag
   (while (setq pt (getpoint "\nPick Insertion Point:")) 
       ;get room name from a text element
       (picktext)
       (setq roomname ans)
       (picktext)
       (setq roomname2 ans)
       ;get room number from text element
       (picktext)
       (setq roomnumber ans)

; insert a roomtag based on the information stored above

           (command "-insert" "ROOMTAG.DWG" "_NON" pt "1" "1" "0" (cdr roomname) (cdr roomname2) "" (cdr roomnumber) )
   )
(princ)

)


(defun c:rt3 ( ) ;Three Line Room Name.
;define picktext for use later in the script
(defun picktext ()  (setq en1 (car (entsel "\nSelect text :" )))  (setq el1 (entget en1))
   (if (= (cdr (assoc 0 el1)) "TEXT")
           (setq ans (assoc 1 el1))
    )
) ;end defun


;identify pt as insertion point for roomtag
   (while (setq pt (getpoint "\nPick Insertion Point:")) 
       ;get room name from a text element
       (picktext)
       (setq roomname ans)
       (picktext)
       (setq roomname2 ans)
       (picktext)
       (setq roomname3 ans)
       ;get room number from text element
       (picktext)
       (setq roomnumber ans)

; insert a roomtag based on the information stored above

           (command "-insert" "ROOMTAG.DWG" "_NON" pt "1" "1" "0" (cdr roomname) (cdr roomname2) (cdr roomname3) "" (cdr roomnumber) )
   )
(princ)

)

(defun c:rt0 ( ) ;no roomname - Just a room number
;define picktext for use later in the script
(defun picktext ()  (setq en1 (car (entsel "\nSelect text :" )))  (setq el1 (entget en1))
   (if (= (cdr (assoc 0 el1)) "TEXT")
           (setq ans (assoc 1 el1))
    )
) ;end defun


;identify pt as insertion point for roomtag
   (while (setq pt (getpoint "\nPick Insertion Point:")) 
       ;get room name from a text element

       ;get room number from text element
       (picktext)
       (setq roomnumber ans)

; insert a roomtag based on the information stored above

           (command "-insert" "ROOMTAG.DWG" "_NON" pt "1" "1" "0" "" (cdr roomnumber) )
   )
(princ)

)

 

I'm sure there's a more elegant way to use the same stuff over and over again with minor tweaks, but this seems to be working for me for now. rt for one line room name one line room number, rt2 for 2 lines in the room name, same with rt0 and rt3.

Posted

@aaron

I see what you mean, I was playing around with only one line for roomname and one line for roomnumber in my makebelieve block.

cheers, S

Posted

Thanks for taking an interest. This script turned a 3 hour task into about 20-25 minutes several times today.

Posted

To speed up more is the the two text picks or more on seperate layers if so could use window to pick and search through what was picked for correct attribute.

Posted (edited)

Hi Al, Thanks, and I'm afraid I don't understand how to implement what you're suggesting here.

 

There is, of course, still room for improvement. - If there's a way to select the insertion point for the block based on the first text item selected, that would move it from three clicks per insertion to two.

 

Also, there's an rounded rectangle in the roomtag block around the room number. It's set with a custom attribute which identifies the width. Sometimes on rooms with 5-6 character room numbers it needs to be stretched a bit to accommodate the room number. Is this something that can be automatically handled within the script?

 

Something like checking the roomnumber attribute for length, then setting the 'distance3' custom attribute (which sets the width in the tag) as the roomtag is inserted?

 

Thanks for your interest.

 

Aaron.

Edited by AaronHolmes
Accidentally posted before the reply was finished.
Posted

Now I'm trying to do the same thing, but to get the information from block attributes rather than just text.

 

I'm basing my initial attempt on Lee Mac's {Get Attribute Value} script, but none of the things I tried seemed to work when I tried to get the attribute name into the roomname or roomnumber variables I needed for inserting the block.

 

;;----------------=={ Get Attribute Value }==-----------------;;
;;                                                            ;;
;;  Returns the attribute value associated with the specified ;;
;;  tag, within the supplied block, if present.               ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2010 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  block - Block (Insert) Entity Name                        ;;
;;  tag   - Attribute TagString                               ;;
;;------------------------------------------------------------;;
;;  Returns:  Attribute TextString, else nil                  ;;
;;------------------------------------------------------------;;



;; Replace block with 2 attributes with another block, reinserting attributes.
;; Based on Lee Mac's Get Attribute routines.



;; Strategy:
;; For each block with a specific name, get two attributes and location

;; Block name in this scenario is P_Iden_Room, on layer A-Flor-Iden 
;; roomname - Tag attribute name is "roomobjects:name"
;; roomnumber - Tag attribute name is "roomobjects:numberprojectbased"
;; pt insertion point for new block

;; Insert new roomtag block based on this information at the found insertion point.

;; Delete existing roomtag.
;; I'd settle for doing this one at a time, but all at once would be nice too.

(defun LM:GetAttributeValue ( block tag )
   (setq tag (strcase tag))
   (if
       (eq "ATTRIB"
           (cdr
               (assoc 0
                   (setq elist
                       (entget
                           (setq block (entnext block))
                       )
                   )
               )
           )
       )
       (if (eq tag (strcase (cdr (assoc 2 elist))))
           (cdr (assoc 1 elist))
           (LM:GetAttributeValue block tag)
       )
   )
)


;;;; I was trying to hardcode the attribute name here instead of (getstring "\nAttribute Name:")
(defun c:TEST ( / ss )
   (if (setq ss (ssget "_+.:E:S" '((0 . "INSERT") (66 . 1))))
       (princ (LM:GetAttributeValue (ssname ss 0) ("ROOMOBJECTS:NAME")))
   )
   (princ)
)





; This RT script below worked for inserting the element based on picking 2 text elements
; If I can get the pt, roomname, and roomnumber variables from the existing block, I should be in good shape.

;(defun c:rt ( )
;;define picktext for use later in the script
;(defun picktext ()  (setq en1 (car (entsel "\nSelect text :" )))  (setq el1 (entget en1))
;    (if (= (cdr (assoc 0 el1)) "TEXT")
;            (setq ans (assoc 1 el1))
;     )
 ;end defun
;
;;identify pt as insertion point for roomtag
;    (while (setq pt (getpoint "\nPick Insertion Point:")) 
;;get room name from a text element
;        (picktext)
;        (setq roomname ans)
;;get room number from text element
;        (picktext)
;        (setq roomnumber ans)
;
;;insert a roomtag based on the information stored above
;
;            (command "-insert" "ROOMTAG.DWG" "_NON" pt "1" "1" "0" (cdr roomname) "" (cdr roomnumber) )
;    )
;(princ)
;




 

If there's an easier way than the strategy I laid out in the comments, I'm totally open to that as well.

 

Thanks.

 

-Aaron.

Posted

Not a answer to your last question but a suggestion I do something similar pick an object then check is it text or is it a block then do correct defun to find the attribute values this way its within one program. Its VBA but am looking at changing back to VL as per LEE's code.

Posted

Hi Al, Thanks,

 

I made some progress on this last section, but ended up with attributes returning as value"value" rather than just value.

 

The code for that is in a separate thread:

Why am I getting the attributes twice as in value"value"

 

I'm close, and I think it'll work, but the values are duplicated, I'd love a second set of eyes.

I don't want to post the code here though, because I don't want to cross post my problem.

 

 

 

-Aaron.

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...