Jump to content

Recommended Posts

Posted

Hi Guys,

 

First of all, happy new year.

 

Second of all, i have a problem with inserting text with variables,

but i can't get the variables in between the text.

 

This is my code.

(defun c:text_doorsnede (/ lay text style T1 T2)
 ;;;; Checking if the textstyle exists
   (if (null (tblsearch "style" "tekst 2.5"))
     (entmake
       (list
         '(0 . "STYLE")
     '(-3                                     ;; Make the style annotative
           ("AcadAnnotative"
             (1000 . "AnnotativeData")
             (1002 . "{")
             (1070 . 1)
             (1070 . 1)
             (1002 . "}")
           )
     )
         '(100 . "AcDbSymbolTableRecord")
         '(100 . "AcDbTextStyleTableRecord")
         '(2 . "Tekst 2.5")                       ;; Style name
         '(70 . 0)                                ;; Standard flag values (bit-coded values)
         '(40 . 2.5)                              ;; text height
         '(41 . 1.0)                              ;; width factor
         '(50 . 0.0)                              ;; oblique angle
         '(71 . 0)                                ;; text generation "0" normal text
         '(42 . 0)                                ;; last height used
         '(3 . "Arial.ttf")                       ;; font file name
         '(4 . "")                                ;; bigfont (blank for no)
       )                                          ;; end list
     )                                            ;; end entmake
   )                                              ;; end if
 ;;;; Checking if the layer exists
   (if (null (tblsearch "layer" "tekst 2.5"))
     (entmake
       (list
         '(0 . "LAYER")
         '(100 . "AcDbSymbolTableRecord")
         '(100 . "AcDbLayerTableRecord")
         '(2 . "Tekst 2.5")                       ;; Layer name
         '(70 . 0)                                ;; Standard flag values (bit-coded values)
         '(6 . "Continuous")                      ;; Linetype
         '(62 . 3)                                ;; Colour
         '(290 . 1)                               ;; Plot on/off (0 for no plot, 1 for plot)
         '(370 . 35)                              ;; Lineweight (for height 2.11mm, choose 211 etc.)
       )                                          ;; end list
     )                                            ;; end entmake
   )                                              ;; end if
 ;;;; Begin function
   (setq text (getvar "textstyle"))
   (setq lay (getvar "clayer"))
   (setvar "textstyle" "Tekst 2.5")
   (setq T1 (getstring "\nDoorsnedeletter 1:"))
   (setq T2 (getstring "\nDoorsnedeletter 2:"))
   (command "layer" "set" "Tekst 2.5" "")
   (command "text" "J" "BL" pause 0 "doorsnede "T1"-"T2)
   (setvar "clayer" lay)
   (setvar "textstyle" text)
 (princ)
)

The problem is in this line:

(command "text" "J" "BL" pause 0 "doorsnede "T1"-"T2)

What i want to do is make the text "doorsnede A-B", when T1 is A and T2 is B.

 

How can i accomplish this?

 

Sorry for the Dutch text.

Posted

This ... ??

 

(command "text" "J" "BL" pause "" 0 (strcat "doorsnede " T1 "-" T2) )

Posted

Thanks Tharwat,

 

That worked, you really helped me out.

Posted
Thanks Tharwat,

 

That worked, you really helped me out.

 

You're very welcome ..

 

Consider this example which is much better than using setvars many times before and after command calls to include the Textstyle and the Layer name within the entmake function .

 


(if (setq p (getpoint "\n Specify Text location :"))

(entmake (list '(0 . "TEXT")
              (cons 40 (getvar 'textsize))
              (cons 10 p)
              '(73 . 1)
             [b][color=blue] '(7 . "Tekst 2.5")
              '(8 . "Tekst 2.5")[/color][/b]
              (cons 1 (strcat "doorsnede " T1 "-" T2))
        )
))

If you faced any problem , just ask .

 

Tharwat

Posted

Hi Tharwat,

 

Your code for replacements of the setvars is good.

Maybe i'm wrong, but i want to change the layer back to the previous layer and your code sets the layer without changing it back to previous.

Since I'm quite an beginner in LISP coding, this was the easiest way to change the layer. Maybe you have a better suggestion.

Posted (edited)

My previous codes would do instead of all these codes that you did in your routine with a little modifications to be completed and no matter your current layer name is or current text style is ..

Replace these ....

(setq text (getvar "textstyle"))    
(setq lay (getvar "clayer"))     
(setvar "textstyle" "Tekst 2.5")    
(setq T1 (getstring "\nDoorsnedeletter 1:"))    
(setq T2 (getstring "\nDoorsnedeletter 2:"))    
(command "layer" "set" "Tekst 2.5" "")   
 (command "text" "J" "BL" pause 0 "doorsnede "T1"-"T2)    
(setvar "clayer" lay)     
(setvar "textstyle" text)

With these ....

 

(if (and (setq T1 (getstring "\nDoorsnedeletter 1:"))
        (setq T2 (getstring "\nDoorsnedeletter 2:"))
        (setq p  (getpoint "\n Specify Text location :"))
     )
(entmake (list '(0 . "TEXT")
              (cons 40 (getvar 'textsize)) ; Text height
              (cons 10 p)        ; Text Location ( xyz )
              (cons 11 (trans p 0 1)) ; Second Text alignment
              '(73 . 1)          ; Text Justification as Bottom Left
              '(7 . "Tekst 2.5") ; <= Text style
              '(8 . "Tekst 2.5") ; <= Layer name
              (cons 1 (strcat "doorsnede " T1 "-" T2))
        )
))

Edited by Tharwat
(cons 11 (trans p 0 1)) added
Posted

Tharwat, DXF Group 11 for TEXT requires a value if either DXF 72 or 73 are non-zero.

Posted

(setq p  (getpoint "\n Specify Text location :"))
...
(cons 10 p) 
(cons 11 (trans p 0 1))

 

Note that p is defined relative to the UCS, and DXF Groups 10 & 11 require points defined relative to the OCS (Object Coordinate System). If the WCS plane = UCS plane then the OCS = WCS, however, if not, the points will need to be transformed to the OCS.

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