Entmod question

Entmod question

zph
Collaborator Collaborator
2,201 Views
15 Replies
Message 1 of 16

Entmod question

zph
Collaborator
Collaborator

Good day all,

 

I am experiencing an issue with my application of entmod.

 

After I use entmod to modify the TEXT entity's justification points, (assuming the justification isn't already BC) I expected the assoc 10 point to move, but it doesn't.

 

What am I missing?

 

(defun c:testy ( / adoc eFlag cntr *error* ssA pName pList Pt1 Pt2)

(vl-load-com)
(vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(setvar "cmdecho" 0)
(setq eFlag 1 cntr 0)

(defun *error* (msg)
	(if (member msg '("Function cancelled" "quit / exit abort" "*Cancel*"))
		(progn (setvar "cmdecho" 1)(vla-endundomark adoc)
			(cond
				((= eFlag 1) (princ "\n <!> Routine aborted <!> "))
				((= eFlag 2)
					(princ (strcat 
							"\n\033\n " 
							(itoa cntr) 
							" sets of cable text aligned."
							"\n <!> Routine complete <!> ")))
			) ;cond
		) ;progn
	) ;if
) ;*error*

(princ "\n\033\n...Select text...")

(setq ssA (ssget '((0 . "TEXT,MTEXT")(8 . "TEXT"))))

(while (< cntr (sslength ssA)) 

(princ "\n 1 ")

(setq pName (ssname ssA cntr))
(setq pList (entget pName))

	(if (= (cdr (assoc 0 pList)) "TEXT")
		(progn

(princ "\n 2 ")

		(setq Pt1 (cdr (assoc 10 pList)))

(princ "\n pList1: \n")
(foreach pL pList (progn (princ pL)(terpri)))

(princ "\n Pt1: ")(princ Pt1)(terpri)

		(entmod (setq pList (subst (cons 72 1)(assoc 72 pList) pList)))
		(entmod (setq pList (subst (cons 73 1)(assoc 73 pList) pList)))

		(setq Pt2 (cdr (assoc 10 pList)))

(princ "\n pList2: \n")
(foreach pL pList (progn (princ pL)(terpri)))

(princ "\n Pt2: ")(princ Pt2)(terpri)

		(entmod (setq pList (subst (cons 10 Pt1)(assoc 10 pList) pList)))

(princ "\n 3 ")

		) ;progn
	) ;if

(princ "\n 4 ")

(setq cntr (1+ cntr))
) ;while

(princ "\n 5 ")

(setq eFlag 2)
(exit)
) ;testy

~Z

 

0 Likes
Accepted solutions (1)
2,202 Views
15 Replies
Replies (15)
Message 2 of 16

Kent1Cooper
Consultant
Consultant

Without digging too deeply....

 

Are you aware that (assoc 10) represents the insertion point [what Osnap INS would snap to] of plain Text only if it's Left-justified?  It is the left end of the base-line, no matter what the justification.  For all other justifications, the insertion point is (assoc 11).  That will be 0,0,0 for Left-justified plain text, regardless of the location, but otherwise it's the insertion point.

 

Does adjusting your code for that difference fix things [I didn't try]?

Kent Cooper, AIA
0 Likes
Message 3 of 16

zph
Collaborator
Collaborator

Kent,

 

I am aware that assoc 10 and 11 are different.  However, changing all the assoc 10 to assoc 11 didn't change the outcome.  The text entity's justification updates from BOTTOM LEFT to BOTTOM CENTER and the text 'moves' as a result, but neither the assoc 10 or 11 codes update.  I think one of them *should* change.

 

Via manually copying the text, changing the justification of the new entity, and aligning the insertion points I found that the assoc 10 code is the POINT value that I am looking for because it is different across the two text entities.

 

Does this help?

 

~Z

 

 

0 Likes
Message 4 of 16

john.uhden
Mentor
Mentor
Accepted solution

This may help you (my intent was to keep them in the same spot)...

;;------------------------------------------------
;; Function to set entities current justification:
;; Revised function (06-14-02)
(defun @cv_set_just (ent newjus / etype oldjus tbox boxw boxh p10 p11
                                    ang vcode vjust 1/2pi)
   (setq etype  (cdr (assoc 0 ent))
         oldjus (@cv_get_just ent)
         tbox   (textbox (subst (cons 51 0.0)(assoc 51 ent) ent))
         boxw   (caadr tbox)
         boxh   (cadadr tbox)
         p10    (cdr (assoc 10 ent))
         p11    (cdr (assoc 11 ent))
         ang    (cdr (assoc 50 ent))
         vcode  (if (= etype "TEXT") 73 74)
         1/2pi   (* pi 0.5)
   )
   (cond
      ((= oldjus "Unknown"))
      ((= oldjus newjus))
      ((= newjus "Left")
         (setq p11 (list 0.0 0.0 (last p10)) j72 0 vjust 0)
      )
      ((= newjus "Right")
         (setq p11 (polar p10 ang boxw) j72 2 vjust 0)
      )
      ((= newjus "Center")
         (setq p11 (polar p10 ang (/ boxw 2)) j72 1 vjust 0)
      )
      ((= newjus "Middle")
         (setq p11 (polar p10 ang (/ boxw 2))
               p11 (polar p11 (+ ang 1/2pi)(/ boxh 3))
               j72 4 vjust 0
         )
      )
      ((= newjus "BL")
          (setq p11 (polar p10 (- ang 1/2pi)(/ boxh 3))
                j72 0 vjust 1
          )
      )
      ((= newjus "BC")
         (setq p11 (polar p10 ang (/ boxw 2))
               p11 (polar p11 (- ang 1/2pi)(/ boxh 3))
               j72 1 vjust 1
         )
      )
      ((= newjus "BR")
         (setq p11 (polar p10 ang boxw)
               p11 (polar p11 (- ang 1/2pi)(/ boxh 3))
               j72 2 vjust 1
         )
      )
      ((= newjus "ML")
         (setq p11 (polar p10 (+ ang 1/2pi)(/ boxh 2))
               j72 0 vjust 2
         )
      )
      ((= newjus "MC")
         (setq p11 (polar p10 ang (/ boxw 2))
               p11 (polar p11 (+ ang 1/2pi)(/ boxh 2))
               j72 1 vjust 2
         )
      )
      ((= newjus "MR")
         (setq p11 (polar p10 ang boxw)
               p11 (polar p11 (+ ang 1/2pi)(/ boxh 2))
               j72 2 vjust 2
         )
      )
      ((= newjus "TL")
         (setq p11 (polar p10 (+ ang 1/2pi) boxh)
               j72 0 vjust 3
         )
      )
      ((= newjus "TC")
         (setq p11 (polar p10 ang (/ boxw 2))
               p11 (polar p11 (+ ang 1/2pi) boxh)
               j72 1 vjust 3
         )
      )
      ((= newjus "TR")
         (setq p11 (polar p10 ang boxw)
               p11 (polar p11 (+ ang 1/2pi) boxh)
               j72 2 vjust 3
         )
      )
   )
   (if (/= oldjus newjus)
      (setq ent (subst (cons 11 p11)(assoc 11 ent) ent)
            ent (subst (cons 72 j72)(assoc 72 ent) ent)
            ent (subst (cons vcode vjust)(assoc vcode ent) ent)
      )
   )
   ent
)
;;-----------------------------------------------------
;; Function to get TEXT entity's current justification:
;;
;; vcode is the vertical justification code.
;; It must be either 73 for TEXT or 74 for an ATTRIB
;;
(defun @cv_get_just (ent / etype str j72 vcode vjust)
   (setq etype (cdr (assoc 0 ent))
         j72 (cdr (assoc 72 ent))
         vcode (if (= etype "TEXT") 73 74)
         vjust (cdr (assoc vcode ent))
         str (if (and j72 vjust)(strcat (itoa j72)(itoa vjust)))
   )
   (cond
      ((not str))
      ((= str "00") "Left")     ; 0
      ((= str "10") "Center")   ; 1
      ((= str "20") "Right")    ; 2
      ((= str "30") "Aligned")  ; 3
      ((= str "40") "Middle")   ; 4
      ((= str "50") "Fit")      ; 5
      ((= str "03") "TL")       ; 6
      ((= str "13") "TC")       ; 7
      ((= str "23") "TR")       ; 8
      ((= str "02") "ML")       ; 9
      ((= str "12") "MC")       ; 10
      ((= str "22") "MR")       ; 11
      ((= str "01") "BL")       ; 12
      ((= str "11") "BC")       ; 13
      ((= str "21") "BR")       ; 14
      (1 "Unknown")
   )
)

 

John F. Uhden

0 Likes
Message 5 of 16

zph
Collaborator
Collaborator

John,

 

Thanks for your reply.

 

I commented out my code (except the portion where I define the entities list data as 'pList') and initialized your code like so:

(@cv_set_just pList "BC")

 

However, the function failed to rejustify and move the text entity.  Did I implement it correctly?  Below is the full code:

 

(defun c:testy ( / adoc eFlag cntr *error* ssA pName pList Pt1 Pt2)

(vl-load-com)
(vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
(setvar "cmdecho" 0)
(setq eFlag 1 cntr 0)

(defun *error* (msg)
	(if (member msg '("Function cancelled" "quit / exit abort" "*Cancel*"))
		(progn (setvar "cmdecho" 1)(vla-endundomark adoc)
			(cond
				((= eFlag 1) (princ "\n <!> Routine aborted <!> "))
				((= eFlag 2)
					(princ (strcat 
							"\n\033\n " 
							(itoa cntr) 
							" sets of cable text aligned."
							"\n <!> Routine complete <!> ")))
			) ;cond
		) ;progn
	) ;if
) ;*error*

(princ "\n\033\n...Select text...")

(setq ssA (ssget '((0 . "TEXT,MTEXT")(8 . "TEXT"))))

(while (< cntr (sslength ssA)) 

(setq pName (ssname ssA cntr))
(setq pList (entget pName))

;(@cv_set_just pList "BC")
(setq pList (@cv_set_just pList "BC")) ;(princ "\n 1 ") ; ;(setq pName (ssname ssA cntr)) ;(setq pList (entget pName)) ; ; (if (= (cdr (assoc 0 pList)) "TEXT") ; (progn ; ;(princ "\n 2 ") ; ; (setq Pt1 (cdr (assoc 11 pList))) ; ;(princ "\n pList1: \n") ;(foreach pL pList (progn (princ pL)(terpri))) ; ;(princ "\n Pt1: ")(princ Pt1)(terpri) ; ; (entmod (setq pList (subst (cons 72 1)(assoc 72 pList) pList))) ; (entmod (setq pList (subst (cons 73 1)(assoc 73 pList) pList))) ; ; (setq Pt2 (cdr (assoc 11 pList))) ; ;(princ "\n pList2: \n") ;(foreach pL pList (progn (princ pL)(terpri))) ; ;(princ "\n Pt2: ")(princ Pt2)(terpri) ; ; (entmod (setq pList (subst (cons 11 Pt1)(assoc 11 pList) pList))) ; ;(princ "\n 3 ") ; ; ) ;progn ; ) ;if ; ;(princ "\n 4 ") (setq cntr (1+ cntr)) ) ;while (princ "\n 5 ") (setq eFlag 2) (exit) ) ;testy ;;----------------------------------------------------- ;; Function to get TEXT entity's current justification: ;; ;; vcode is the vertical justification code. ;; It must be either 73 for TEXT or 74 for an ATTRIB ;; (defun @cv_get_just (ent / etype str j72 vcode vjust) (setq etype (cdr (assoc 0 ent)) j72 (cdr (assoc 72 ent)) vcode (if (= etype "TEXT") 73 74) vjust (cdr (assoc vcode ent)) str (if (and j72 vjust)(strcat (itoa j72)(itoa vjust))) ) (cond ((not str)) ((= str "00") "Left") ; 0 ((= str "10") "Center") ; 1 ((= str "20") "Right") ; 2 ((= str "30") "Aligned") ; 3 ((= str "40") "Middle") ; 4 ((= str "50") "Fit") ; 5 ((= str "03") "TL") ; 6 ((= str "13") "TC") ; 7 ((= str "23") "TR") ; 8 ((= str "02") "ML") ; 9 ((= str "12") "MC") ; 10 ((= str "22") "MR") ; 11 ((= str "01") "BL") ; 12 ((= str "11") "BC") ; 13 ((= str "21") "BR") ; 14 (1 "Unknown") ) ) ;;------------------------------------------------ ;; Function to set entities current justification: ;; Revised function (06-14-02) (defun @cv_set_just (ent newjus / etype oldjus tbox boxw boxh p10 p11 ang vcode vjust Hpi) (setq etype (cdr (assoc 0 ent)) oldjus (@cv_get_just ent) tbox (textbox (subst (cons 51 0.0)(assoc 51 ent) ent)) boxw (caadr tbox) boxh (cadadr tbox) p10 (cdr (assoc 10 ent)) p11 (cdr (assoc 11 ent)) ang (cdr (assoc 50 ent)) vcode (if (= etype "TEXT") 73 74) Hpi (* pi 0.5) ) (cond ((= oldjus "Unknown")) ((= oldjus newjus)) ((= newjus "Left") (setq p11 (list 0.0 0.0 (last p10)) j72 0 vjust 0) ) ((= newjus "Right") (setq p11 (polar p10 ang boxw) j72 2 vjust 0) ) ((= newjus "Center") (setq p11 (polar p10 ang (/ boxw 2)) j72 1 vjust 0) ) ((= newjus "Middle") (setq p11 (polar p10 ang (/ boxw 2)) p11 (polar p11 (+ ang Hpi)(/ boxh 3)) j72 4 vjust 0 ) ) ((= newjus "BL") (setq p11 (polar p10 (- ang Hpi)(/ boxh 3)) j72 0 vjust 1 ) ) ((= newjus "BC") (setq p11 (polar p10 ang (/ boxw 2)) p11 (polar p11 (- ang Hpi)(/ boxh 3)) j72 1 vjust 1 ) ) ((= newjus "BR") (setq p11 (polar p10 ang boxw) p11 (polar p11 (- ang Hpi)(/ boxh 3)) j72 2 vjust 1 ) ) ((= newjus "ML") (setq p11 (polar p10 (+ ang Hpi)(/ boxh 2)) j72 0 vjust 2 ) ) ((= newjus "MC") (setq p11 (polar p10 ang (/ boxw 2)) p11 (polar p11 (+ ang Hpi)(/ boxh 2)) j72 1 vjust 2 ) ) ((= newjus "MR") (setq p11 (polar p10 ang boxw) p11 (polar p11 (+ ang Hpi)(/ boxh 2)) j72 2 vjust 2 ) ) ((= newjus "TL") (setq p11 (polar p10 (+ ang Hpi) boxh) j72 0 vjust 3 ) ) ((= newjus "TC") (setq p11 (polar p10 ang (/ boxw 2)) p11 (polar p11 (+ ang Hpi) boxh) j72 1 vjust 3 ) ) ((= newjus "TR") (setq p11 (polar p10 ang boxw) p11 (polar p11 (+ ang Hpi) boxh) j72 2 vjust 3 ) ) ) (if (/= oldjus newjus) (setq ent (subst (cons 11 p11)(assoc 11 ent) ent) ent (subst (cons 72 j72)(assoc 72 ent) ent) ent (subst (cons vcode vjust)(assoc vcode ent) ent) ) ) ent )
0 Likes
Message 6 of 16

john.uhden
Mentor
Mentor

My function was part of a larger app.  It does not perform an entmod...

(entmod (setq plist (@cv_set_just plist "BC")))

Also, I have no recollection whether it works on MTEXT.

John F. Uhden

0 Likes
Message 7 of 16

Kent1Cooper
Consultant
Consultant

@zph wrote:

....  The text entity's justification updates from BOTTOM LEFT to BOTTOM CENTER and the text 'moves' as a result, but neither the assoc 10 or 11 codes update.  I think one of them *should* change.

....


 

For me, starting with BottomLeft-justified Text and running your command, the 10 value does  change [the 11 does not].  What changes in it is the X coordinate only.

Kent Cooper, AIA
0 Likes
Message 8 of 16

zph
Collaborator
Collaborator

John,

 

I figured it was.  Thanks for the additional info.

 

It worked!

 

I could have sworn I read somewhere that using a numeric character as the first character of a variable would throw an error (see your variable "1/2pi").  I guess this rule wasn't as much truth, but instead more of a guideline?  After that routine failed the first couple times I perused the internals of the code and found this and immediately changed all the "1/2pi"s to "Hpi"s thinking that the "1" in front might be the reason for the failure.

 

Thank you for your assistance John and Kent!

~Z

 

 

0 Likes
Message 9 of 16

ВeekeeCZ
Consultant
Consultant

How about just

 

(acet-tjust (ssget '((0 . "*TEXT"))) "BC")
0 Likes
Message 10 of 16

ronjonp
Mentor
Mentor

Have you tried THIS ? Nevermind that is for block insertion. 

0 Likes
Message 11 of 16

zph
Collaborator
Collaborator

Kent,

 

I don't know then.

 

I printed the assoc 10 points of the text, before and after applying the entmod to the assoc 72 and 73 codes, and the assoc 10 points were identical.  The text would move on screen (due to the re-justification) but the assoc 10 object data wouldn't update.  At first I thought it might be the lack of an entupd, but no.

 

*shrugs shoulders*

Maybe I did just overlook that the difference was only in the X coordinate...which would be slightly embarrassing.

 

0 Likes
Message 12 of 16

zph
Collaborator
Collaborator

BCZ,

 

Thank you for your response.  I have never used any "acet-*" functions.  However, I need to be able to use the code on an apple computer using vanilla AutoCAD with no 3rd party add-ons and after some quick research into these functions I am unsure of whether they would be a feasible solution.

 

~Z

0 Likes
Message 13 of 16

ВeekeeCZ
Consultant
Consultant

Sure, fair enough. Those are part of the Express Tools. Probably won't work on mac.

0 Likes
Message 14 of 16

zph
Collaborator
Collaborator

BCZ, no worries.  You guys are the best.  I am always learning something new when I chat with you guys.  Cheers!

0 Likes
Message 15 of 16

Kent1Cooper
Consultant
Consultant

@zph wrote:

.... I don't know then. ....*shrugs shoulders* ....


 

Another thought [untested]:  You said you were going from Bottom Left to Bottom Center, and that's the test I made.  But were you really going from just plain Left  justification to Bottom Center?  In plain Text, there's a difference between Left and Bottom Left.  I think that might make a difference in your outcome, since the "meaning" of and relationship between the 10 & 11 codes is different for [plain] Left justification than for all others.

Kent Cooper, AIA
0 Likes
Message 16 of 16

zph
Collaborator
Collaborator

Kent,

 

On a side note, I feel compelled to express my admiration of your ability to effectively articulate complicated and nuanced subject matter.

 

Back to the matter at hand...

 

Yes, I am certain that the initial text was justified bottom left.  If I memory serves me right, the "left" justification is treated in the same way AutoCAD treats "byLayer" option for a property.  It describes the "default" value that is defined elsewhere; much like how a "pointer" works in C++.  The pointer itself doesn't store any information, but informs the program where to find it.  Something like that... I think.

 

~Z

0 Likes