TXT2BLK changes the current rotation.

TXT2BLK changes the current rotation.

Anonymous
Not applicable
1,490 Views
5 Replies
Message 1 of 6

TXT2BLK changes the current rotation.

Anonymous
Not applicable

I have found this code on the forums and need to modify it so it will use the rotation of the already existing text. IE if my existing text is at 92 degrees the newly inserted block should be at 92 degrees after the lisp is complete.  How would I go about doing that?

 

(defun get_block_name (/ blkName)

 (if (eq (getvar "users5") "")
  (prompt "\nBlock name: ")
  (prompt (strcat "\nBlock name <" (getvar "users5") ">: "))
 ); if

 (if (= (setq blkName (getstring t)) "")
  (setq blkName (getvar "users5"))
  (setvar "users5" blkName)
 ); if

 (if (/= blkName "")
  (if (null (tblsearch "block" blkName))
   (progn
    (vlr-beep-reaction)
    (prompt (strcat "\nBlock " (strcase blkName) " is not exist."))
    (setvar "users5" (setq blkName ""))
   )
  )
 )

 blkName
)


(defun get_middle_text_point (e / insPt box t0 t1 p0 p1)
 (setq ins (cdr (assoc '10 e)))
 (setq box (textbox (list (assoc '1 e))))
 (setq t0 (car box) t1 (cadr box))
       
 (setq p0 (list (+ (car ins) (car t0)) (+ (cadr ins) (cadr t0))))
 (setq p1 (list (+ (car ins) (car t1)) (+ (cadr ins) (cadr t1))))
  
 (polar p0 (angle p0 p1) (/ (distance p0 p1) 2))
)


(defun c:txt2blk (/ savOSmode savAttdia savAttreq blkName ss i ent e p10 text)
 (vl-load-com)

 (setvar "cmdecho" 0); disable command echo 
 (command ".undo" "begin")

 (setq savOSmode (getvar "osmode")); save osnap
 (setq savAttdia (getvar "attdia")); save attdia
 (setq savAttreq (getvar "attreq")); save attreq

 (setvar "attdia" 0); disable attribute dialog
 (setvar "attreq" 1); enable attribute request
  
 (if (/= (setq blkName (get_block_name)) "")
  (if (setq ss (ssget (list '(0 . "TEXT")))); select only TEXT objects
   (progn
    (setvar "osmode" 0); disable osnap
     
    (setq i -1)
    (repeat (sslength ss)
     (setq i (1+ i))
     (setq e (entget (setq ent (ssname ss i))))
     (setq p10 (get_middle_text_point e))
     (setq text (cdr (assoc '1 e)))
     (command ".insert" blkName p10 "" "" "" text)
     (entdel ent)
    ); repeat

    (setvar "osmode" savOSmode)
   ); progn
  ); if
 ); if

 (setvar "attdia" savAttdia); restore attdia
 (setvar "attreq" savAttreq); restore attreq

 (command ".undo" "end")
 (setvar "cmdecho" 1); restore command echo
 (princ)
  
); defun

 

0 Likes
Accepted solutions (1)
1,491 Views
5 Replies
Replies (5)
Message 2 of 6

dlanorh
Advisor
Advisor
Please attach a copy of the block, or post the code for making the block.

I am not one of the robots you're looking for

0 Likes
Message 3 of 6

Anonymous
Not applicable

This code takes the selected single line text (not mtext) from an existing drawing and inserts it into any block that has an attribute field. This will work with any block that will accept attributes no specific block is necessary. The code will prompt the user for the name of the block to be used/ inserted and replace all text with the user specified block. the existing text will be placed in the 1st attribute line of the block regardless of what the tag is. The code it self works, it just defaults to 0 degree rotation for all inserted blocks. I would like it to maintain the orientation of the text it is replacing. 

 

Thanks.

0 Likes
Message 4 of 6

dbhunia
Advisor
Advisor
Accepted solution

Hi,

 

As per your requirement......

 


@Anonymous wrote:

This code takes the selected single line text (not mtext) from an existing drawing and inserts it into any block that has an attribute field. This will work with any block that will accept attributes no specific block is necessary. The code will prompt the user for the name of the block to be used/ inserted and replace all text with the user specified block. the existing text will be placed in the 1st attribute line of the block regardless of what the tag is. The code it self works, it just defaults to 0 degree rotation for all inserted blocks. I would like it to maintain the orientation of the text it is replacing. 

 

Thanks.


 

And also for "if my existing text is at 92 degrees the newly inserted block should be at 92 degrees after the lisp is complete."

 

Try this....(Red line has been added / modified)

 

(defun get_block_name (/ blkName)
 (if (eq (getvar "users5") "")
  (prompt "\nBlock name: ")
  (prompt (strcat "\nBlock name <" (getvar "users5") ">: "))
 ); if
 (if (= (setq blkName (getstring t)) "")
  (setq blkName (getvar "users5"))
  (setvar "users5" blkName)
 ); if
 (if (/= blkName "")
  (if (null (tblsearch "block" blkName))
   (progn
    (vlr-beep-reaction)
    (prompt (strcat "\nBlock " (strcase blkName) " is not exist."))
    (setvar "users5" (setq blkName ""))
   )
  )
 )
 blkName
)


(defun get_middle_text_point (e / insPt box t0 t1 p0 p1)
 (setq ins (cdr (assoc '10 e)))
 (setq box (textbox (list (assoc '1 e))))
 (setq t0 (car box) t1 (cadr box))
 (setq p0 (list (+ (car ins) (car t0)) (+ (cadr ins) (cadr t0))))
 (setq p1 (list (+ (car ins) (car t1)) (+ (cadr ins) (cadr t1))))
 (polar p0 (angle p0 p1) (/ (distance p0 p1) 2))
)


(defun c:txt2blk (/ savOSmode savAttdia savAttreq blkName ss i ent e p10 text)
 (vl-load-com)
 (setvar "cmdecho" 0); disable command echo 
 (command ".undo" "begin")
 (setq savOSmode (getvar "osmode")); save osnap
 (setq savAttdia (getvar "attdia")); save attdia
 (setq savAttreq (getvar "attreq")); save attreq
 (setvar "attdia" 0); disable attribute dialog
 (setvar "attreq" 0); disable attribute request
 (if (/= (setq blkName (get_block_name)) "")
  (if (setq ss (ssget (list '(0 . "TEXT")))); select only TEXT objects
   (progn
    (setvar "osmode" 0); disable osnap
    (setq i -1)
    (repeat (sslength ss)
     (setq i (1+ i))
     (setq e (entget (setq ent (ssname ss i))))
     (setq p10 (get_middle_text_point e))
     (setq text (cdr (assoc '1 e)))
     (setq text_rotation (/ (* (cdr (assoc '50 e)) 180) pi));Get TEXT Rotation
     (command ".insert" blkName p10 "" "" text_rotation)
     (entdel ent)
     (Change_Att_Val text)
    ); repeat
    (setvar "osmode" savOSmode)
   ); progn
  ); if
 ); if
 (setvar "attdia" savAttdia); restore attdia
 (setvar "attreq" savAttreq); restore attreq
 (command ".undo" "end")
 (setvar "cmdecho" 1); restore command echo
 (princ)
); defun


(defun Change_Att_Val (text / obj num x )
(setq num 0)
(setq obj (vlax-ename->vla-object (entlast)))
(if (and (vlax-property-available-p obj 'hasAttributes)(eq (vla-get-HasAttributes obj) :vlax-true))
   (progn
	(setq x 0)
	(foreach att (vlax-invoke Obj 'GetAttributes)
	   (princ ( strcat (rtos x 2 0) "= " (vla-get-Textstring att) "\n"))
	   ;The above line will give you the Attribute sequence, you can comment this line
	   (if (= x num)(vla-put-Textstring att text)); Change Attribute Value
	   (setq x (+ x 1))
	)
   )
)
)

 

For more go through the below link ........

 

http://forums.augi.com/showthread.php?169776-LISP-routine-to-grab-an-attribute-value-from-a-block-(which-varies)

 

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 5 of 6

Anonymous
Not applicable

Works perfectly. Thank you. 

0 Likes
Message 6 of 6

marie-pierre.lebelXBW9B
Enthusiast
Enthusiast

I tried using this code, but I get an "unknown command "BEGIN" " error message.  Do you have any idea what's causing this?

0 Likes