Modification in LISP

Modification in LISP

krishravi2000
Enthusiast Enthusiast
874 Views
11 Replies
Message 1 of 12

Modification in LISP

krishravi2000
Enthusiast
Enthusiast

Hi guys,

I have a 2 lisp codes one is aligning the text and label on the right and another is placing it in the left.The text align for right lisp is working perfectly but the left align lisp is making issue.

20240314_171301.jpg

 

When i give the lisp command "1" the text aligned on the right

20240314_171133.jpg

defun c:1();to keep the text aligned at right side
(command "ucs" "world")
(setq objs (ssget)
scalef (/ (cdr(assoc 40(entget(ssname objs 0))))9))
(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 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 (setvar "clayer" "0-25text"))
;(setvar "clayer" "0-25text")
(command "pline" lp1 lp2 lp3 lp4 "")
;(setvar "clayer" clay)
(setvar "clayer" "0-35")
)
;----------------------------------------------

20240314_171201.jpg

 when i give the lisp command "2" the text is moved to another location

20240314_172333.jpg

--------------------------------------
(defun c:2();to the text algined at left side
(command "ucs" "World")
(setq objs (ssget)
scalef (/ (cdr(assoc 40(entget(ssname objs 0))))9))
(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 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 2))
(setq objp (subst objj_new (assoc 72 objp) objp))
(entmod objp)

(setq objp (entget obj))
(setq objj (assoc 10 objp))
(setq objjj (assoc 11 objp))
(setq objjx (car (cdr objj)))
(setq objjjx (car (cdr objjj)))
(setq deltaxx (- objjjx objjx))


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

(setq objp (subst objc_10 (assoc 10 objp) objp))
(setq objp (subst objc_11 (assoc 11 objp) objp))

(entmod objp)

(setq count (+ count 1))

)

(setvar "osmode" osm)
(setq lpx1 (- cx (* SCALEF 12.0)))
(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 (setvar "clayer" "0-25text"))
;(setvar "clayer" "0-25text")
(command "pline" lp1 lp2 lp3 lp4 "")
;(setvar "clayer" clay)
(setvar "clayer" "0-35")
)

 

Can anyone help me to fix this issue

0 Likes
875 Views
11 Replies
Replies (11)
Message 2 of 12

autoid374ceb4990
Collaborator
Collaborator

Both routines work fine on my computer after I needed to add a beginning parenthesis to the 1st line of 1.lsp - (defun c:1() ;to keep the text aligned at right side. 

Text is moved to the new location and the brackets are added correctly. I am, however, using a really old version of AutoCAD.  When you try #2 do you get any error messages?

0 Likes
Message 3 of 12

krishravi2000
Enthusiast
Enthusiast

No sir i don't get any errors

20240321_195650.jpg

0 Likes
Message 4 of 12

autoid374ceb4990
Collaborator
Collaborator

You might try starting a new drawing, add some text, and see if that changes anything.

0 Likes
Message 5 of 12

Kent1Cooper
Consultant
Consultant

Are you in the World Coordinate System?

Kent Cooper, AIA
0 Likes
Message 6 of 12

krishravi2000
Enthusiast
Enthusiast

20240321_205925.jpg

20240321_205913.jpg

As in the above pic you can see only the Mtext moved to the new location but the text aligned perfectly is it possible to alter the LISP so the Mtext gets aligned on the left side

20240314_171201.jpg

0 Likes
Message 7 of 12

krishravi2000
Enthusiast
Enthusiast

Yes sir it is WCS

0 Likes
Message 8 of 12

autoid374ceb4990
Collaborator
Collaborator

Are you saying that the TEXT works properly, but the MTEXT does not?

As a quick solution you could XPLODE the MTEXT, then move it as TEXT.

0 Likes
Message 9 of 12

krishravi2000
Enthusiast
Enthusiast

That's the problem sir we cannot explode the text because those text are created by a extension software called RebarCAD

0 Likes
Message 10 of 12

Kent1Cooper
Consultant
Consultant

So you receive them from something that generates them as Mtext.  Do you need to somehow feed them back to that something after you've worked with them?  If not, I see no reason you couldn't Explode them into plain Text, if that makes it all work.

Kent Cooper, AIA
0 Likes
Message 11 of 12

autoid374ceb4990
Collaborator
Collaborator

Your pictures show both TEXT and MTEXT.  Does RebarCAD create both?  When you try to EXPLODE the MTEXT nothing happens or is there some other reason you cannot/will not explode the MTEXT?

0 Likes
Message 12 of 12

Kent1Cooper
Consultant
Consultant

The code was written for plain Text, not Mtext.  For example, the 72-code entry is for a different purpose in the two object types.  And the 11-code entry does not exist in Mtext.  So either you need to Explode the Mtext, or some significant re-working needs to be done to figure out the equivalent things that should be adjusted for Mtext, what the adjustments should be, and to have the routine check which kind of object something is in order to apply the right set of adjustments.

 

[Also, the QUIck Osnap mode is obsolete.  This:

(command "osnap" "qui,end")

gives an invalid error in newer versions.  Use "end" alone.]

Kent Cooper, AIA
0 Likes