Modify Text Align LISP

Modify Text Align LISP

krishravi2000
Enthusiast Enthusiast
726 Views
1 Reply
Message 1 of 2

Modify Text Align LISP

krishravi2000
Enthusiast
Enthusiast

Hi guys,

Can anyone help me to modify this lisp

The LISP below will align the text right side i want it to be modified so when i give the command "1" the text to be aligned in left side

 

(defun c:1 ()
(setq scale (getvar "dimstyle"))
(if (= scale "CADS_DIM_96")
(setq scalef 1)
(progn
(if (= scale "CADS_DIM_48")
(setq scalef 0.5)
(progn
(if (= scale "CADS_DIM_24")
(setq scalef 0.25)
(progn (if (= scale "CADS_DIM_64")
(setq scalef 0.6667)
(progn (if (= scale "CADS_DIM_32")
(setq scalef 0.3333)

(progn (if (= scale "CADS_DIM_192")
(setq scalef 2)

(progn (if (= scale "CADS_DIM_120")
(setq scalef 1.25)

(progn (if (= scale "CADS_DIM_144")
(setq scalef 1.5)
(progn (if (= scale "CADS_DIM_72")
(setq scalef 0.75)
(progn (if (= scale "CADS_DIM_128")
(setq scalef 1.33333)
(setq scalef 1)
)
)
)
)
)
)
)
)

)
)
)
)
)
)
)
)

)
)
)


(setq x_x (* scalef 4.0))
(setq y_y (* scalef 4.0))
(setq text_gap (* scalef 16.0))
(setq text_height (* scalef 9.0))

(setq objs (ssget))
(setq ss_len (sslength objs))
(setq osm (getvar "osmode"))
(command "osnap" "qui,end")
(setq cxy (getpoint "pick a point"))
(command "osmode" 0)
(setq cx (car cxy))
(setq cy (car (cdr cxy)))
(setq count 0)

(repeat ss_len
(if (= count 0)
(progn
(setq tx1 (+ cx x_x))
(setq ty1
(+ cy
(/ (+ (* (- ss_len 1.0) text_gap) text_height)
2
)
)
)
(setq tx2 tx1)
(setq ty2 (- ty1 text_height))
)
(setq ty2 (- ty2 text_gap))
)

(setq obj (ssname objs count))
(setq objp (entget obj))


(setq objj_new (cons 72 0))

(setq objc_11 (cons 11 (list 0 0 0)))
(setq objc_10 (cons 10 (list tx2 ty2 0)))

(setq objp (subst objc_10 (assoc 10 objp) objp))
(setq objp (subst objc_11 (assoc 11 objp) objp))
(setq objp (subst objj_new (assoc 72 objp) objp))
(entmod objp)

(setq count (+ count 1))

)

(setvar "osmode" osm)
(setq lpx1 (+ cx (* 12.0 SCALEF)))
(setq lpx2 cx)
(setq lpx3 cx)
(setq lpx4 lpx1)

(setq lpy1 (+ ty1 x_x))
(setq lpy2 lpy1)
(setq lpy3
(- ty1
(+ (+ (* text_gap (- count 1)) text_height) (* scalef 5.0))
)
)
(setq lpy4 lpy3)

(setq lp1 (list lpx1 lpy1))
(setq lp2 (list lpx2 lpy2))
(setq lp3 (list lpx3 lpy3))
(setq lp4 (list lpx4 lpy4))
(setq clay (getvar "clayer"))
(setvar "clayer" "0-25text")
(command "pline" lp1 lp2 lp3 lp4 "")
(setvar "clayer" clay)
)

0 Likes
Accepted solutions (1)
727 Views
1 Reply
Reply (1)
Message 2 of 2

Kent1Cooper
Consultant
Consultant
Accepted solution

@krishravi2000 wrote:

....

The LISP below will align the text right side i want it to be modified so when i give the command "1" the text to be aligned in left side

....


Is that backwards?  It aligns to the left side for me, and this supports that idea:

(setq objj_new (cons 72 0))

If you want it to align on the right side, change that to:

(setq objj_new (cons 72 2))

 

But there are other things involved -- I don't have your whole drawing setup to check, and don't understand everything it's trying to do, so it does some things oddly for me.  But that at least makes Text objects right-justified.  I assume you also want to change the Polyline bracket to face the other way, which might be as simple as changing this:

(setq lpx1 (+ cx (* 12.0 SCALEF)))

to this:

(setq lpx1 (- cx (* 12.0 SCALEF)))

but I haven't tried it.

 

By the way, your excessively nested set of possibilities for setting the scalef variable at the beginning, with line after line of trailing right parentheses, can all be replaced with just this:

  (setq
    scale (getvar "dimstyle")
    scalef
      (if (wcmatch (strcase scale) "CADS_DIM_##*")
        (/ (atof (substr scale 10)) 96); then
        1 ; else
      ); if
  ); setq

 

Kent Cooper, AIA