How to link userdefined Text in block

How to link userdefined Text in block

Anonymous
Not applicable
1,288 Views
11 Replies
Message 1 of 12

How to link userdefined Text in block

Anonymous
Not applicable

I have prepared below program. In supporting all CAD file "XX" text is used. So when in result of this file is also shows "XX". I want to user give only once a input that what text he wants & as per that "XX" will get replace. So please advise how to edit this program.Which command I will use for this & how to link the text.I have attached some supporting CAD files.
(defun c:WD (/ T_Rotation T_Point)
   (setvar "CMDECHO" 0)
   (initget "DOUBLE DOUBLE")
  
   (while
      "DOUBLE"
      (initget 1 "RIGHT LEFT UP DOWN")
      (setq T_Rotation (getkword "\nSelect Rotation [RIGHT LEFT UP DOWN]: "))
      (setq T_Point (getpoint "Enter the point"))
      (vl-catch-all-apply 'vl-cmdf (list "_.insert" (strcat "*BLOCK_" "DOUBLE" "_" T_Rotation) T_Point 1 1 0))
      )     
   )
   (princ)
)

 

0 Likes
Accepted solutions (3)
1,289 Views
11 Replies
Replies (11)
Message 2 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

You can't use Text for that purpose.  You would need to use an Attribute.  Read about the ATTDEF command in Help.  After replacing the Text objects in the Blocks with Attributes, the Insertion of those into a drawing would have a value fed in after the rotation.  Something like this [untested]:

 

(defun c:WD (/ T_Rotation T_Point)
   (setvar "CMDECHO" 0)

   (setq txt (getstring "\nYour text content for the Attribute: "))
;;;;; (initget "DOUBLE DOUBLE") ;;;;; does nothing with no following (get...) function
   (while T
;;;;;      "DOUBLE"  ;;;;; will always be non-nil, i.e. "True," so just use something like T as above
      (initget 1 "Right Left Up Down")

        ;;;;; if in all-capitals, user must type in full word ; this way they can use just initial letter
      (setq T_Rotation (getkword "\nSelect Rotation [Right/Left/Up/Down]: "))

        ;;;;; in capital-initial-letter case and with slashes, can pick option on-screen
      (setq T_Point (getpoint "Enter the point"))
      (vl-catch-all-apply 'vl-cmdf

        (list "_.insert" (strcat "*BLOCK_DOUBLE_" T_Rotation) T_Point 1 1 0 txt))

        ;;;;; feed in Attribute content at end of Insert command
      )     
   )
   (princ)
)

Kent Cooper, AIA
Message 3 of 12

dbhunia
Advisor
Advisor
Accepted solution

First do as @Kent1Cooper said "You can't use Text for that purpose.  You would need to use an Attribute."....... But I would like to mention that if you want to pass the attribute values using Lisp then you have to take care two system variables in your code ........ like.....

 

(defun c:WD (/ T_Rotation T_Point)
(setq Adia (getvar 'ATTDIA))
(setq Areq (getvar 'ATTREQ))
(setvar 'ATTDIA 0);;Required to feed Attribute values without a dialog box
(setvar 'ATTREQ 1);;Required to Turns on prompts or a dialog box for attribute values
(setvar 'CMDECHO 0)
(setq txt (getstring "\nYour text content for the Attribute: "))
   (while (setq T_Point (getpoint "Enter the point of insertion"))
	(initget 1 "Right Left Up Down")
	(setq T_Rotation (getkword "\nSelect Rotation [Right/Left/Up/Down]: "))
	(vl-catch-all-apply 'vl-cmdf
      	    (list "_.insert" (strcat "BLOCK_DOUBLE_" T_Rotation) T_Point 1 1 0 txt)
	)
   )
(setvar 'ATTDIA Adia)
(setvar 'ATTREQ Areq)
(setvar 'CMDECHO 1)
(princ)
)

 

There is a question from the line.....

 

(vl-catch-all-apply 'vl-cmdf (list "_.insert" (strcat "*BLOCK_" "DOUBLE" "_" T_Rotation) T_Point 1 1 0))

Why do you using this "*" symbol....... to explode the block?......

 

If so then I would like to say that, if you "Explode" an Attributed block ....... then after "Explode" the Attribute values always replaced by the "Attribute Tag Name"...... in that case your Input Attribute Tag Value will not show in drawing......

 

In that case you have to use "BURST" command instead of "EXPLODE"......Like

 

(defun c:WD (/ T_Rotation T_Point)
(setq Adia (getvar 'ATTDIA))
(setq Areq (getvar 'ATTREQ))
(setq Pf (getvar 'PICKFIRST))
(setvar 'PICKFIRST 1)
(setvar 'ATTDIA 0);;Required to feed Attribute values without a dialog box
(setvar 'ATTREQ 1);;Required for Turns on prompts or a dialog box for attribute values
(setvar 'CMDECHO 0)
(setq txt (getstring "\nYour text content for the Attribute: "))
   (while (setq T_Point (getpoint "Enter the point of insertion"))
	(initget 1 "Right Left Up Down")
	(setq T_Rotation (getkword "\nSelect Rotation [Right/Left/Up/Down]: "))
	(vl-catch-all-apply 'vl-cmdf
      	    (list "_.insert" (strcat "BLOCK_DOUBLE_" T_Rotation) T_Point 1 1 0 txt)
	)
	(sssetfirst nil (ssget "L"))
	(C:BURST)
   )
(setvar 'PICKFIRST Pf)
(setvar 'ATTDIA Adia)
(setvar 'ATTREQ Areq)
(setvar 'CMDECHO 1)
(princ)
)

But the Main thing ......All the above code is valid only for Single Attributed Block......Like ..... go through the attachment........

 


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

Anonymous
Not applicable

Thanks Kent! Your explanation is really very useful. I used your code. I have below doubts:
1. I used this, it ask me to provide the value for attribute but it doesn't incorporate the given attribute value. It returns "XX".
2. How this attributes prepared. I know the ATTDEF command but it does not include any symbols.
3. Also advise how to create attribute if there are multiple text. Also advise how to use that in program.

0 Likes
Message 5 of 12

Anonymous
Not applicable

Thanks Debashis Bhunia for the code with expalnation! Many doubts get resolved. I have below doubts:
1. I used this, it ask me to provide the value for attribute but it doesn't incorporate the given attribute value. It returns "XX".
2. How this attributes prepared. I know the ATTDEF command but it does not include any symbols.
3. Also advise how to create attribute if there are multiple text. Also advise how to use that in program.

0 Likes
Message 6 of 12

dbhunia
Advisor
Advisor

First you make 4 blocks with attributes (As in my attached drawing) or copy from my attached drawing into your drawing and run the code....

 

To create attributed block......first create an attribute and then make symbols(using line, polyline, circle....etc) and place it as per your requirement ..... Now make a block with these Attribute & symbols (as a whole)..... Whenever you Insert this block it will ask you for new Attribute value ..... put the value and press ok ...... the block will insert with new attribute value.....

 

If you create a block with multiple attributes then it will ask you to input multiple Attribute value (for each attribute).....

 

Lastly go through AutoCAD Help for more clarifications....

 


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

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....
1. I used this, it ask me to provide the value for attribute but it doesn't incorporate the given attribute value. It returns "XX".
....


 

I hadn't noticed the asterisk in your code, which puts the Block in pre-Exploded.  Two possibilities:

 

1.  Leave the Block with Text instead of an Attribute.  The Last object could be any of the pieces of the Block, so the routine would need to mark the last object in the drawing first, and step through everything newer than that after Inserting, to find which is the Text object and give it the value.  This would be more complicated if there are more than one, and the question arises how you would specify which one gets which content.

 

2.  Keep the Attribute, and remove the asterisk in Inserting, so it will remain a Block.  This would be easier for multiple Attributes, since you can know in what order it will ask for values for them.  And you could even not  ask for values ahead of time, and just leave the asking for the dialog box that comes up to ask for them when you Insert a Block with Attributes -- that's what Attribute Tags are for, to let the User distinguish what value should go into each.

 

So one important question is whether there is any reason for you to want the Block Exploded when you're done.  There are several benefits to not  Exploding it, so I would recommend the Attribute approach, even with more than one Attribute.

Kent Cooper, AIA
Message 8 of 12

Anonymous
Not applicable

Thanks everyone for your prompt reply! Below codes work for me. Only it is in block.I want to burst all the blocks which I got in result. In some codes I used (command "_.BURST" "last") & it worked for me. But here for multiple output how can I use Burst command for all the blocks.

(defun c:WD (/ T_Rotation T_Point)
(setq Adia (getvar 'ATTDIA))
(setq Areq (getvar 'ATTREQ))
(setvar 'ATTDIA 0)
(setvar 'ATTREQ 1)
(setvar 'CMDECHO 0)
(setq txt (getstring "\nYour text content for the Attribute: "))
   (while (setq T_Point (getpoint "Enter the point of insertion"))
 (initget 1 "Right Left Up Down")
 (setq T_Rotation (getkword "\nSelect Rotation [Right/Left/Up/Down]: "))
 (vl-catch-all-apply 'vl-cmdf
           (list "_.insert" (strcat "BLOCK_DOUBLE_" T_Rotation) T_Point 1 1 0 txt)
 )
   )
(setvar 'ATTDIA Adia)
(setvar 'ATTREQ Areq)
(setvar 'CMDECHO 1)
(princ)
)

0 Likes
Message 9 of 12

dbhunia
Advisor
Advisor

check my 2nd code....(in my 1st post)


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

dbhunia
Advisor
Advisor
Accepted solution

Another way .......

 

(defun c:WD (/ T_Rotation T_Point ss)
(setq Adia (getvar 'ATTDIA))
(setq Areq (getvar 'ATTREQ))
(setvar 'ATTDIA 0)
(setvar 'ATTREQ 1)
(setvar 'CMDECHO 0)
(setq ss (ssadd))
(setq txt (getstring "\nYour text content for the Attribute: "))
   (while (setq T_Point (getpoint "Enter the point of insertion"))
	(initget 1 "Right Left Up Down")
	(setq T_Rotation (getkword "\nSelect Rotation [Right/Left/Up/Down]: "))
	(vl-catch-all-apply 'vl-cmdf
      	    (list "_.insert" (strcat "BLOCK_DOUBLE_" T_Rotation) T_Point 1 1 0 txt)
	)
        (ssadd (entlast) ss)
   )
(setvar 'ATTDIA Adia)
(setvar 'ATTREQ Areq)
(setvar 'CMDECHO 1)
(sssetfirst nil ss)
(c:burst)
(princ)
)

But I an unable to understand .... How can you BURST an object like.....(command "_.BURST" "last") .......By doing this AutoCAD will show you this message....."_.BURST Unknown command "BURST". Press F1 for help."

 

 


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

Anonymous
Not applicable

Hello, usually I use (command "_.EXPLODE" "last") & it works, but now when I use this for burst it shows error. Don't know why?
As you said this code is for only for one attribute. So what changes do I need to do if there is more than one attribute? For example in existing drawing if I add two more attributes, then how to add these in codes?

0 Likes
Message 12 of 12

dbhunia
Advisor
Advisor

Try this with your given type of Block.......(this is one type of approach)

 

(defun c:WD (/ T_Rotation T_Point ss TU TD Txt)
(vl-load-com)
(setq Areq (getvar 'ATTREQ))
(setvar 'ATTREQ 0)
(setvar 'CMDECHO 0)
(setq ss (ssadd))
(if (= (setq TU (getstring T "\nYour text content for the Up Attribute: ")) "") (setq TU " "))
(if (= (setq TD (getstring T "\nYour text content for the Down Attribute: ")) "") (setq TD " "))
(if (= (setq Txt (getstring T "\nYour text content for the Txt Attribute: ")) "") (setq Txt " "))
   (while (setq T_Point (getpoint "Enter the point of insertion"))
	(initget 1 "Right Left Up Down")
	(setq T_Rotation (getkword "\nSelect Rotation [Right/Left/Up/Down]: "))
	(vl-catch-all-apply 'vl-cmdf
      	    (list "_.insert" (strcat "BLOCK_DOUBLE_" T_Rotation) T_Point 1 1 0)
	)
	(setq obj (vlax-ename->vla-object (entlast)))
	(foreach att (vlax-invoke Obj 'GetAttributes)
	   (if (= (vla-get-Tagstring att) (strcat (strcase T_Rotation) "U")) (vla-put-textstring att TU))
	   (if (= (vla-get-Tagstring att) (strcat (strcase T_Rotation) "D")) (vla-put-textstring att TD))
	   (if (= (vla-get-Tagstring att) "TXT") (vla-put-textstring att Txt))
	)
	(ssadd (entlast) ss)
   )
(setvar 'ATTREQ Areq)
(setvar 'CMDECHO 1)
(sssetfirst nil ss)
(c:burst)
(princ)
)

For Blocks go through the attachment.......(For the above code you do not think about the Attribute Tag sequence/order)........

 

 

Another approach if you can manage the Attribute Tag sequence/order of all the 4 Blocks in a same pattern then you can try this way ..... (For the below code you have to think about the Attribute Tag sequence/order)........

 

(defun c:WD (/ T_Rotation T_Point ss TU TD Txt)
(setq Adia (getvar 'ATTDIA))
(setq Areq (getvar 'ATTREQ))
(setvar 'ATTDIA 0)
(setvar 'ATTREQ 1)
(setvar 'CMDECHO 0)
(setq ss (ssadd))
(if (= (setq TU (getstring T "\nYour text content for the Up Attribute: ")) "") (setq TU " "))
(if (= (setq TD (getstring T "\nYour text content for the Down Attribute: ")) "") (setq TD " "))
(if (= (setq Txt (getstring T "\nYour text content for the Txt Attribute: ")) "") (setq Txt " "))
   (while (setq T_Point (getpoint "Enter the point of insertion"))
	(initget 1 "Right Left Up Down")
	(setq T_Rotation (getkword "\nSelect Rotation [Right/Left/Up/Down]: "))
	(vl-catch-all-apply 'vl-cmdf
      	    (list "_.insert" (strcat "BLOCK_DOUBLE_" T_Rotation) T_Point 1 1 0 TU TD Txt)
	)
	(ssadd (entlast) ss)
   )
(setvar 'ATTDIA Adia)
(setvar 'ATTREQ Areq)
(setvar 'CMDECHO 1)
(sssetfirst nil ss)
(c:burst)
(princ)
)

 

For.....

 


@Anonymous wrote:

Hello, usually I use (command "_.EXPLODE" "last") & it works, but now when I use this for burst it shows error. Don't know why?
As you said this code is for only for one attribute. So what changes do I need to do if there is more than one attribute? For example in existing drawing if I add two more attributes, then how to add these in codes?


 

I also can't say why it is happening with you......

 

 


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