Jump to content

How to use DTEXT in autolisp


fathihvac

Recommended Posts

Hello,

Can sombody tell me how to use DTEXT in autolisp to insert:) two or more predeterrmined texts as follows in model space of autocad drawing:

(command "dtext" text1 text2 text3.....)

The result would be: text1

text2

text3

Link to comment
Share on other sites

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • fathihvac

    7

  • Lt Dan's legs

    7

  • MSasu

    4

  • BlackBox

    3

Top Posters In This Topic

Posted Images

You should reproduce the prompts of that command as arguments when call the COMMAND function - your code will look like:

 

(foreach TextLabel (list Text1st Text2nd Text3rd)
(command "_DTEXT" InsertionPoint TextHeight TextAngle TextLabel)
)

 

Regards,

Mircea

Link to comment
Share on other sites

The way I do it is like this:

 

(command "TEXT" pt0 "0.1" "0" eastin)
  (command "TEXT" "" northin)

 

The second command has a null response for the position ("") and writes it underneath the preceding text.

NextText.jpg

Link to comment
Share on other sites

Nice approach @eldon. You can write that also as:

 

(foreach TextLabel (list Text1st Text2nd Text3rd)
(command "_TEXT")
(if InsertionPoint (setq InsertionPoint (command InsertionPoint TextHeight TextAngle)) (command ""))
(command TextLabel)
)

Regards,

Mircea

Edited by MSasu
Link to comment
Share on other sites

 
(defun text ( text insertionpoint layer height )
 (entmakex
   (list
     (cons 0 "text")
     (cons 1 text);text content
     (cons 7 "Romans");style
     (cons 8 layer)
     (cons 10 insertionpoint)
     (cons 72 1)
     (cons 73 2)
     (cons 40 height)
     (cons 11 insertionpoint)
   )
 )
)

(
 (lambda ( insertionpoint1 insertionpoint2 )
   (foreach x (list insertionpoint1 insertionpoint2)
     (text "testing" x "0" 3.)
   )
 )
 (list 0. 0. 0.)
 (list 0. 4. 0.)
)

 

 

 

 

 
(vl-load-com)
(
 (lambda ( ms insertionpoint1 insertionpoint2 )
   (foreach x (list insertionpoint1 insertionpoint2)
     (vla-addtext ms  "testing"  (vlax-3d-point (trans x 0 1)) 3)
   )
 )
 (vla-get-modelspace 
   (vla-get-activedocument (vlax-get-acad-object))
 )
 (list 0. 0. 0.)
 (list 0. 4. 0.)
)

Edited by Lt Dan's legs
Link to comment
Share on other sites

 
(defun text ( text insertionpoint layer height )
 (entmakex
   (list
     (cons 0 "text")
     (cons 1 text);text content
     (cons 7 "Romans");style
     (cons 8 layer)
     (cons 10 insertionpoint)
     (cons 72 1)
     (cons 73 2)
     (cons 40 height)
     (cons 11 insertionpoint)
   )
 )
)

(
 (lambda ( insertionpoint1 insertionpoint2 )
   (foreach x (list insertionpoint1 insertionpoint2)
     (text "testing" x "0" 3.)
   )
 )
 (list 0. 0. 0.)
 (list 0. 4. 0.)
)
(
 (lambda ( pt1 pt2 )
   (foreach x (list pt1 pt2)
     (text "testing" (cdr x) (car x) 3.)
   )
 )
 (cons "0" (list 0. 0. 0.))
 (cons "Defpoints" (list 0. 4. 0.))
)

 

 

 

(vl-load-com)
(
 (lambda ( ms pt1 pt2 )
   (foreach x (list pt1 pt2)
     (vla-put-layer
       (vla-addtext ms  "testing"  (vlax-3d-point (trans (cdr x) 0 1)) 3)
       (car x)
     )
   )
 )
 (vla-get-modelspace 
   (vla-get-activedocument (vlax-get-acad-object))
 )
 (cons "0" (list 0. 0. 0.))
 (cons "Defpoints" (list 0. 4. 0.))
)

 

 

If you are planning on using msasu's example

(foreach TextLabel (list Text1st Text2nd Text3rd)
 (command "_TEXT")
 (if InsertionPoint (setq InsertionPoint (command InsertionPoint TextHeight TextAngle)) (command ""))
 (command TextLabel)
[color=red][b](and
   (setq elast (entget (entlast)))
   (entmod 
     (subst 
       (cons 8 x);put new layer here
       (assoc 8 elast)
       elast 
     )
   )
[/b][/color][color=red][b]  )
[/b][/color])

Link to comment
Share on other sites

>

 

many Thanks to everybody.

Can we put every text (text1' date='text2,..) in a different layer.[/quote']

 

>

 

... Can we repeat the process 256 times' date=' so that there's 256 text entities on top of eachother, and make each iteration a corresponding color to each of the 256 Standard (non-true color) colors respectively? :unsure:

 

[i'][/i]

Link to comment
Share on other sites

quotes did not show Renderman.. Did I do something wrong or am I missing something?

 

CT_implied.facepalm.png

 

:lol:

 

Edit: Please disregard, I've got what I came for (a laugh). Cheers! :beer:

Link to comment
Share on other sites

... Can we repeat the process 256 times, so that there's 256 text entities on top of eachother, and make each iteration a corresponding color to each of the 256 Standard (non-true color) colors respectively? :unsure:

 

One of our clients specs had something similar to that. I am sure whoever wrote it had just read the AutoCAD manual that says "you can have up to 256 layers and colours" so decided that is what they should use. It was (almost) horizontal lines
Link to comment
Share on other sites

I did't understand well

My goal is to insert two texts text1 and text2 at one time but with two different layers layername1 layername2.

Thanks:)

Link to comment
Share on other sites

One of our clients specs had something similar to that. I am sure whoever wrote it had just read the AutoCAD manual that says "you can have up to 256 layers and colours" so decided that is what they should use. It was (almost) horizontal lines

 

Whoa... See I was only kidding with LT Dan, as he posted code, received a request for change, and then immediately followed up with revisions. I was imply playing a(n unrelated) prank, hence the last line. LoL

 

I thought proposing such a (ridiculous?) request would be indicate my not being serious... how wrong I was. LoL

 

I did't understand well

My goal is to insert two texts text1 and text2 at one time but with two different layers layername1 layername2.

Thanks:)

 

Sorry for the confusion, I accept the blame for the unrelated tangent, fathihvac.

Link to comment
Share on other sites

Can we put every text (text1,text2,..) in a different layer.

 

I will write it like:

 

(foreach TextLabel (list (list Text1st Layer1st) (list Text2nd Layer2nd) (list Text3rd Layer3rd))
(command "_TEXT") (if InsertionPoint (setq InsertionPoint (command InsertionPoint TextHeight TextAngle)) (command ""))
(command (car TextLabel) "_CHPROP" (entlast) "" "_LA" (cadr TextLabel) "")
)

 

Regards,

Mircea

Link to comment
Share on other sites

I thought proposing such a (ridiculous?) request would be indicate my not being serious... how wrong I was. LoL
Some clients will do anything to delay payment! It was only after submission & rejection of the cad files that this standard was passed from our sales guys to us (not in budget obviously). To redaw to their standard would not have been easy except for this new equipment bit which allowed us to re-submit some very yellow drawings (I think I exploded everything as well as blocks had a different sub section of their standard) very quickly.
Link to comment
Share on other sites

For Renderman

 

(defun rendermanrequest ( text insertionpoint layer color height )
 (entmakex
   (list
     (cons 0 "text")
     (cons 1 text);text content
     (cons 7 "Romans");style
     (cons 8 layer)
     (cons 62 color)
     (cons 10 insertionpoint)
     (cons 72 1)
     (cons 73 2)
     (cons 40 height)
     (cons 11 insertionpoint)
   )
 )
)
(
 (lambda ( co )
   (while (>= 256 (setq co (1+ co)))
     (rendermanrequest (strcat "Color" (itoa co)) (getvar 'viewctr) "0" co 4.)
   )
 )
 0
)

 

 

This maybe not be as confusing for you..?

 
(defun text ( text insertionpoint layer height )
 (entmakex
   (list
     (cons 0 "text")
     (cons 1 text);text content
     (cons 7 "Romans");style
     (cons 8 layer)
     (cons 10 insertionpoint)
     (cons 72 1)
     (cons 73 2)
     (cons 40 height)
     (cons 11 insertionpoint)
   )
 )
)

(foreach x 
 (list 
   (list "text #1" (list 0. 4. 0.) "0" 3.)
   (list "text #2" (list 0. 0. 0.) "Defpoints" 3.)
 )
 (apply (function text) x)
)

Link to comment
Share on other sites

Hello,

Another question is how to modify spacing between text lines?

 

(defun text ( text insertionpoint layer height )
 (entmakex 
   (list (cons 0 "text")
     (cons 1 text);text content 
     (cons 7 "Romans");style 
     (cons 8 layer) 
     (cons 10 insertionpoint) 
     (cons 72 1) 
     (cons 73 2) 
     (cons 40 height) 
     (cons 11 insertionpoint) 
   ) 
 ) 
) 
(foreach x 
 (list 
   (list "text #1" [color="red"](list 0. 4. 0.)[/color] "0" 3.) 
   (list "text #2" (list 0. 0. 0.) "Defpoints" 3.) 
 ) 
 (apply (function text) x) 
) 

 

Or lookup POLAR

 

(Polar point angle distance)

Link to comment
Share on other sites

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