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

Aligning MTEXT with group Code 71 attachment point

7 REPLIES 7
Reply
Message 1 of 8
GeeHaa
938 Views, 7 Replies

Aligning MTEXT with group Code 71 attachment point

Hi,

 

I wrote a lisp routine to align text vertically and change the Justification at the same time. It works fine for Plain text but when I try it on Mtext It doesn't change group code 71 or group code 10 with ENTMOD. Is there a way to do this?

 

Thanks in advance.

7 REPLIES 7
Message 2 of 8
_Tharwat
in reply to: GeeHaa

Hi.

 

If you put the entmoding codes after eachother into your codes , it would do only the first entmod only  , so this should

do the trick .

 

(defun c:Test (/ e)
  (defun _Entmoding (selectionset key value / i sn e)
;;;            Tharwat 01 . January 2012      ;;;
;;;          This sub-routine would entmod    ;;;
;;;   any entity according to keys and values ;;;
    (if (eq (type selectionset) 'PICKSET)
      (repeat (setq i (sslength selectionset))
        (setq sn (ssname selectionset (setq i (1- i))))
        (setq e (entget sn))
        (entmod
          (subst (cons key value)
                 (assoc key e)
                 e
          )
        )
      )
    )
  )

  (if (setq e (ssget "_:L" '((0 . "MTEXT"))))
    (progn
      (_Entmoding e 71 1)
      (_Entmoding e 10 '(0. 0. 0.))
    )
  )
  (princ)
)

 Tharwat

Message 3 of 8
pbejse
in reply to: GeeHaa


@GeeHaa wrote:

Hi,

 

I wrote a lisp routine to align text vertically and change the Justification at the same time. It works fine for Plain text but when I try it on Mtext It doesn't change group code 71 or group code 10 with ENTMOD. Is there a way to do this?

 

Thanks in advance.


Easy way, YES. VL-codes. Theres also a way to do it with Entmod,

Post your code so we can have a look-see.

 

Message 4 of 8
GeeHaa
in reply to: pbejse

(DEFUN C:alignV2 (/	 Elist	e2     e3     e4     ETYPE  cnt
		  vert	 XDST	YDST   p3     p2     p1	    TB
		  Csnap	 *ERROR*
		 )
;;;THIS PROGRAM ALIGNS TEXT VERTICALLLY CHANGING THE JUSTIFICATION
;;;03-16-1999
  (vl-load-com)
  (setq Csnap (getvar "snapmode"))
  (setvar "snapmode" 0)
  (if (< (getvar "OSMODE") 16383)
    (setvar "OSMODE" (+ (getvar "OSMODE") 16384))
  )
  (defun *ERROR* (msg)
    (setvar "snapmode" Csnap)
    (setvar "osmode" (- (getvar "osmode") 16384))
    (princ (strcat "error " msg))
    (princ)
  )
  (defun getbbox (ename / pts)
    (vla-getboundingbox (vlax-ename->vla-object ename) 'LL 'UR)
    (setq pts (mapcar 'vlax-safearray->list (list LL UR)))
  )
  (defun getattach (just curAttach)
    (setq Justidx (list (list 1 2 3) (list 4 5 6) (list 7 8 9)))
    (foreach justGrp justIdx
      (if (member curAttach justGrp)
	(setq newJust (nth just justGrp))
      )
    )
    newJust
  )


  (princ
    "\nSelect Text item then text to align vertically with it"
  )
  (setq e1 (ssget))
  (setq pts (getbbox (ssname e1 0)))
  (setq	pLL (car pts)
	pUR (cadr pts)
  )
  (setq pJust (getpoint "\nEnter point for justification "))
  (setq cnt 1)
  (cond
    ((< (car pJust) (car pLL))
     (setq just 0)
     (setq alignPx (car pll))
    )
    ((and (> (car pJust) (car pLL)) (< (car pJust) (car pUR)))
     (setq Just 1)
     (setq alignPx (+ (car pLL) (/ (- (car pUR) (car pLL)) 2.0)))
    )
    ((> (car pJust) (car pUR))
     (setq just 2)
     (setq alignPx (car pUR))
    )

  )
  (setq cnt 0)
  (repeat (sslength e1)
    (setq e2 (ssname e1 cnt))
    (setq e3 (entget e2))

    (IF	(OR (= (setq ETYPE (cdr (assoc 0 E3))) "TEXT")
	    (= (setq ETYPE (cdr (assoc 0 E3))) "MTEXT")
	)
      (PROGN
	(IF (= ETYPE "TEXT")
	  (PROGN
	    (setq vert 73)
	    (setq vertIdx (cdr (assoc vert e3)))
	    (setq P1 (cdr (assoc 10 E3)))
	    (if
	      (and (= 0 (cdr (assoc 73 e3))) (= 0 (cdr (assoc 73 e3))))
	       (PROGN

		 (setq assocNum 10)
	       )
	       (progn
		 (setq assocNum 11)	;else
	       )
	    )
	    (setq p2 (cdr (assoc assocNum e3)))
	    (setq P3 (list alignPx (cadr P2)))
	    (setq E3 (subst (cons 72 just) (assoc 72 E3) E3))
	    (setq E3 (subst (cons vert vertIdx) (assoc vert E3) E3))
	    (if	(and (= 0 just) (= 0 (cdr (assoc vert e3))))
	      (setq E3 (subst (cons 10 P3) (assoc 10 E3) E3))
	      (setq E3 (subst (cons 11 P3) (assoc 11 E3) E3))
	    )
	    (entmod E3)
	    (entupd e2)
	  )
	)
	(IF (= ETYPE "MTEXT")
	  (PROGN
	    (setq vert 71)
	    (setq vertIdx (getattach just (cdr (assoc vert e3))))
	    (setq p2 (cdr (assoc 10 e3)))
	    (setq P3 (list alignPx (cadr P2)))
	    (setq E3 (subst (cons 10 P3) (assoc 10 E3) E3))
	    (setq E3 (subst (cons vert vertIdx) (assoc vert E3) E3))
	    (entmod E3)
	    (entupd E2)
	  )
	)


      )
    )
    (setq cnt (1+ cnt))

  )
  (setvar "snapmode" Csnap)
  (setvar "osmode" (- (getvar "osmode") 16384))
  (princ)
)

 

 

 

Message 5 of 8
GeeHaa
in reply to: GeeHaa

Using the VL functions works

 

I put these lines in instead of the subst and entmod functions and it works.

 

(setq vlEnt (vlax-ename->vla-object e2))     

(vlax-put-property vlEnt 'attachmentpoint vertIdx)    

(vlax-put-property vlEnt 'insertionpoint (vlax-3d-point p3))

 

I still don't know why entmod doesn't

 

Thanks very Much.

Message 6 of 8
pbejse
in reply to: GeeHaa


@GeeHaa wrote:

Using the VL functions works

 

I put these lines in instead of the subst and entmod functions and it works.

 

(setq vlEnt (vlax-ename->vla-object e2))     

(vlax-put-property vlEnt 'attachmentpoint vertIdx)    

(vlax-put-property vlEnt 'insertionpoint (vlax-3d-point p3))

 

I still don't know why entmod doesn't

 

Thanks very Much.


Glad that helps.

 

I tried your code just, nowunless you're using annotative textstyle , it appears to be working fine here. when and what condition when your code bombs?

 

Anyhoo. no need to ponder on it now then.

 

 

Message 7 of 8
GeeHaa
in reply to: pbejse

That's what it was. My text style was annotative. When I turn it off, entmod works.

 

Thanks again.

Message 8 of 8
pbejse
in reply to: GeeHaa


@GeeHaa wrote:

That's what it was. My text style was annotative. When I turn it off, entmod works.

 

Thanks again.


There you go. I suggest you stick with VL on this one to make it generic, Annotative and Entmod just dont mix.

 

Glad i could help

Cheers

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

Post to forums  

Autodesk Design & Make Report

”Boost