Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with Text Properties.

8 REPLIES 8
Reply
Message 1 of 9
jsargeantC4P7C
433 Views, 8 Replies

Help with Text Properties.

I'm looking to edit a level marker Lisp routine that brings in a block, and two lines of text.

 

Below is an extract which defines the text properties.

 

;; -------------------------------------------------------------;;
;; Top Text Properties ;;
;; -------------------------------------------------------------;;

;; Text Height
th1 (getvar 'textsize)

;; Text Style
ts1 "Standard"

;; Text Layer
tl1 "07 Structure Text"

;; Text Colour
tc1 251

;; Text Position Relative to Block Insertion Point
tv1 '(0.20 0.10 0.0)

 

1.) I need to justify the text Left (currently comes in as Middle-left) - do i also need to add a qualifier like the others th1, ts1, tc1...etc? further up the routine

 

2.) I need the "Text Position Relative to Block Insertion Point" to adjust based on the Text Height (getvar 'textsize) - for example current position is set up perfect for  text height (th) of 0.13

 

tv1 '(0.20 0.10 0.0) = good for 0.13 th

tv1 '(0.10 0.05 0.0) = would be good for 0.07 th

tv1 '(0.40 0.20 0.0) = would be good for 0.26 th ..... and so on.

 

That said, if the justification changes from middle-left to left so would the y-axis positioning, by half the th?

 

tv1 '(0.20 0.035 0.0) =  0.13 th - adjusted for the justification changing

tv1 '(0.10 0.015 0.0) = 0.07 th - adjusted for the justification changing

tv1 '(0.40 0.07 0.0) = 0.26 th - adjusted for the justification changing

 

Apologies if there's not enough information here. I'm a complete newb to this and have only started editing Lisp files TODAY 😄

 

Happy to share more of the routine in private via email if you think you can help..

 

Many thanks,

8 REPLIES 8
Message 2 of 9
-didier-
in reply to: jsargeantC4P7C

Bonjour @jsargeantC4P7C 

 

I'm a complete newb to this and have only started editing Lisp files TODAY

Maybe it’s not a good idea to pick such a complicated topic to start with.

I agree to exchange a little knowledge by MP, I propose you to log in to my site (in signature) and use the contact form.
When we have made the round of the subject, we will publish the solution on this forum.

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

Didier Aveline

EESignature

Message 3 of 9
john.uhden
in reply to: jsargeantC4P7C

@jsargeantC4P7C ,

Good old vanilla text can be a pain to work with.  DXF codes 71, 72, 73, and 74 (I think) provide different alignment points based on their combination.  It's better to use VLISP object properties to change their alignment.  But you're just starting.  I have old code (pre-Visual Lisp) that figures it all out but I don't remember it, nor do I use it anymore.  I think it's time for you to scrape your knees and bruise your body with a regimen of trial and error.  I think that's what most of us here have done (with some help from the experienced ones.  God bless them).  Failures teach many lessons.

It's like the time my older brother was teaching me to ride a two-wheeler.  He taught me how to pedal and to keep my balance, but he didn't include steering.  So I ran into the curb and went flying (until I landed).  OUCH!  Yep, that was a lesson.

John F. Uhden

Message 4 of 9
stev98312
in reply to: jsargeantC4P7C

Here's a sample of text alignment DXF codes used to create a special character and have it centered on the selected point. Codes 72 and 73 were a challenge. Maybe this will give ideas.

 

;; Original version by hak_vz on 28JULY2021
;; forums.autodesk.com/t5/visual-lisp-autolisp-and-general/check-mark/td-p/10503119
;; Message number 6
;;
;; Modified 01AUG2021 by SteveJ to automate the generation
;;  of the text style, make text character Middle-Center
;;  justified, and put Middle-Center of character at the
;;  selected insertion point. Different character, too.
;;

(defun c:SMILEY (/ pt) 
  ;; Make The Text Style
  (entmake 
    (list 
      '(0 . "STYLE")
      '(100 . "AcDbSymbolTableRecord")
      '(100 . "AcDbTextStyleTableRecord")
      '(2 . "SMILES") ;<- Style name
      '(70 . 0) ;<- ??
      '(40 . 0.0) ;<- Text Height
      '(41 . 1.0) ;<- Width Factor
      '(50 . 0.0) ;<- Oblique Angle
      '(71 . 0) ;<- ??
;;      '(42 . 0.08) ;<- Last Height Used ???
      '(3 . "Wingding.ttf") ;<- Primary Font Name
;;      '(4 . "") ;<- Bigfont File Name (??)
    )
  )
  ;; Put it on the drawing.
  (while (setq pt (getpoint "\nSelect Insertion Point >")) 
    (entmake 
      (list 
        (cons 0 "TEXT") ;<- TEXT entity
        (cons 8 "NOPLOT") ;<- Layer for TEXT entity
        (cons 100 "AcDbText")
        (cons 10 pt) ;<- First Alignment Point
        (cons 11 pt) ;<- Second Alignment Point
        (cons 40 (* 4 (getvar 'Textsize))) ;<- Text Height
        (cons 1 "\U+004A") ;<-  SMILEY FACE
        (cons 7 "SMILES") ;<- Text Style
        (cons 72 1) ;<- Horiz. Text Justification. 1 = Center
        (cons 73 2) ;<- Vert Text Justification. 2 = Middle
        (cons 62 2) ;<- Color No 2.
;;        (cons 100 "AcDbText") ;<- Why is this in here twice??
;;        (cons 210 (trans '(0 0 1) 1 0 T)) ;<- Extrusion Direction (optional)???
      )
    )
  )
  (princ)
)

 

 

EDIT: Just remembered codes 10 and 11 had to be the same for this particular exercise to work.

 

Steve

 

 

Message 5 of 9

@jsargeantC4P7C , your relationships between text heights [th1] and relative locations [tv1] are not constant, but if you want something regularized to use in a routine that will work for any size, they would need to be.  I suggest for your first group:

 

(setq tv1 (mapcar '* (list th1 th1 th1) '(1.5 0.75 0)))

or another way to do the same thing [two more code characters!]:

(setq tv1 (mapcar '(lambda (x) (* x th1)) '(1.5 0.75 0)))

 

which for your example th1 values gives these results, very close to your "good for" values:

0.13 -- (0.195 0.0975 0.0)  [yours: (0.20 0.10 0.0)]

0.07 -- (0.105 0.0525 0.0)  [yours: (0.10 0.05 0.0)]

0.26 -- (0.39 0.195 0.0)  [yours: (0.40 0.20 0.0)]

To hit any of your "good for" values exactly for any of those text sizes would mean the same formula would not hit the others exactly -- this is a generic compromise, with some slightly over and some slightly under, but all using the same formula.

An adjustment of the Y value in the multipliers [just change the 0.75] can do the same for your shift to different justification.

 

Look at the entries about justification and insertion points at the DXF Reference for Text.  There's a chart showing the relationship between the 72 and 73 codes -- not really all that difficult to understand.

 

No, @john.uhden , there's no 74, and you don't have to "think" whether there is -- see above.  [71 relates only to backwards or up-side-down Text, so I imagine most people don't need to deal with that much.]

 

@stev98312 , the 10 and 11 codes won't ever be the same as each other except for Text that is Left-justified with its insertion point at 0,0.

Simple thing to keep in mind:  10 is the left end of the base-line, ALWAYS, regardless of justification.

If it's Left-justified, 10 is therefore also the insertion point [what INS Osnap goes to], and 11 is always 0,0.  If it's any other justification, 11 is the insertion point, and 10 is only a result of the relationship of that, the particular justification, font, height, content, width factor, etc.

Kent Cooper, AIA
Message 6 of 9
john.uhden
in reply to: Kent1Cooper

@Kent1Cooper ,

Thank you for that explanation.

It reminds me why I prefer to use VLISP for text alignment.

John F. Uhden

Message 7 of 9
stev98312
in reply to: Kent1Cooper

@Kent1Cooper 

Thanks for that explanation for codes 10 and 11.

So much more informative than entries for those codes in the Autodesk DXF reference for text.

 

Steve

Message 8 of 9

Hi Kent,

 

Many thanks for the response. I would never have thought to look at the X & Y axis figures as a "best-fit" multiplication of the text height. Genius.

 

With regards to inserting that code then, what is meant by "first group" - The extract below is the first block i have before by Program Parameters (block & text properties) are defined.

;;----------------------------------------------------------------------;;

(defun em:maindl

(
typ
/
*error*

bc1 bl1 blk bln bsc
ocs
pnt
tc1 tc2 th1 th2 tl1 tl2 ts1 ts2 tv1 tv2
uxa
)

(defun *error* ( msg )
(em:endundo (em:acdoc))
(if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
(princ (strcat "\nError: " msg))
)
(princ)
)

(setq

;;----------------------------------------------------------------------;;

 

Can i simply insert it here, then set ";; Text Position Relative to Block Insertion Point" in text properties simply to "tv1"

 

Message 9 of 9


@jsargeantC4P7C wrote:

....

(setq

;;----------------------------------------------------------------------;;

 

Can i simply insert it here, then set ";; Text Position Relative to Block Insertion Point" in text properties simply to "tv1"


Without digging too deeply, I think so, except that of course you would need to have th1 set before including my suggestions.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


AutoCAD Beta