Fields and Text/Mtext

Fields and Text/Mtext

shannongreen_17
Contributor Contributor
2,211 Views
4 Replies
Message 1 of 5

Fields and Text/Mtext

shannongreen_17
Contributor
Contributor

So I'm very new to lisp and I'm not sure what to do. I've attached two images and the sample lisp. one image shows the result of running test1, test2, test3 and the desired output at the bottom. The other image shows a zoomed-in view of the first image since the result of test2 produces a massive output.

 

Test1 and Test2 are both Mtext while Test3 is Text.

 

what I want to know is:

1) What is it about the format for test1 that cases the field to not evaluate to look like the last row?

2) How can I alter Test2 to look like the last row? I've tried entmod but I must be doing something wrong because it doesn't work for me

3) Test3 evaluates to look like the last row only after switching pages or doing a regen. why is this?

 

I'm asking these questions so that I can get a better understanding so that I will be able to fix/deal with these issues in the future.

0 Likes
Accepted solutions (2)
2,212 Views
4 Replies
Replies (4)
Message 2 of 5

pbejse
Mentor
Mentor
Accepted solution

@shannongreen_17 wrote:

what I want to know is:

1) What is it about the format for test1 that cases the field to not evaluate to look like the last row?

2) How can I alter Test2 to look like the last row? I've tried entmod but I must be doing something wrong because it doesn't work for me

3) Test3 evaluates to look like the last row only after switching pages or doing a regen. why is this?

 


 

Assuming layout names are A1, A2, A23...

Number 1: Not sure what you meant by STACKED TEXT

EDIT: [ still not sure / following your logic of combining VL and Vanilla]

 

(defun c:Test1 ()
  (if
    (setq CreatedTeXt
	   (entmakex
	     (list
	       (cons 0 "MTEXT")		; Entity Type
	       (cons 100 "AcDbEntity")	; 100 Entity Code
	       (cons 8 "0")		; The Layer
	       (cons 100 "AcDbMText")	; 100 Entity Code

					; For Other Formatting Codes See the:
					; ActiveX and VBA Developer's Guide ->
					; Chapter 4 -- Creating and Editing AutoCAD Entities ->
					; Adding Text to Drawings ->
					; Using Multiline Text (Mtext) ->
					; Formatting Multiline Text
	       (cons 7 "Arial")
	       (cons 1 "-")		; Stacked Text
	       (cons 10 '(7.2743 2.8353 0.0)) ; Insertion Point
	       (cons 40 0.12)
	       (cons 71 5)
	       (cons 72 5)
	       (cons 41 4.12618)
	       (cons 6 "ByLayer")
	     )
	   )
    )

     (vla-put-TextString
       (vlax-ename->vla-object CreatedTeXt)
       "MATCHLINE TO SHEET \\P %<\\AcDiesel $(substr,$(getvar,ctab),2)>%"
     )
  )

)

Number 2: 

 

(vla-addMText
      space
      (vlax-3d-point 7.2743 2.8353 0.0)
      4.
      "MATCHLINE TO SHEET  %<\\AcDiesel $(substr,$(getvar,ctab),2)>%"
    )

Number 3:

..
(CreateText "mc" 0.12 (nth 0 ptlist) "MATCHLINE TO SHEET %<\\AcDiesel $(substr,$(getvar,ctab),2)>%" "0")
..

..
(setq Created_text (entmakex (list (cons 0 "TEXT") (cons 72 horJust) ;Horizontal text justification,0=Left,1=Center,2=Right,4=Center,5=Fit (cons 73 verJust) ;Vertical text justification, 0=Baseline,1=Bottom,2=Middle,3=Top (cons 7 "Arial") (cons 10 insertPt) (cons 11 insertPt) (cons 40 txtHeight) (cons 1 txtString) (cons 8 txtLayer) ) ) ) (command "_updatefield" Created_text "") )

HTH

 

 

0 Likes
Message 3 of 5

shannongreen_17
Contributor
Contributor

Firstly, sorry about the random comments, remnants from another solution. I tried using (vla-update) to see if that would force an update on the object after it was created but the format wasn't correct and I forgot to remove it before putting it on the forum. Probably wouldn't have worked if it was correct anyway :P.

 

Secondly, Thanks a mill. number1 and number 3 work wonderfully :). Question on number 2

 

number 2:

Asssuming sheet labels 1,2,3

(defun c:Test2 ()
; Tharwat 14. 06. 2011
(setq space (vla-get-paperspace
(vla-get-ActiveDocument (vlax-get-acad-object))
)
)

(vla-addMText
space
(vlax-3d-point 7.2743 2.8353 0.0)
4.
(strcat "MATCHLINE TO SHEET %<\$(-, $(getvar,ctab), 1)>%"
)
)

(princ)
)

 

This causes the field to evaluate but the problem is that it comes out at a massive text height. The format for number 1 and 3 allows me to set the criteria for the resulting text/mtext object but when I try to use entmod on number 2 nothing happens. Is there another way to edit the object or did I just not do it right? If entmod is the answer, how can I alter multiple criteria at the same time? For example, change the layer and the height at the same time.

 

Lastly, I realized that your solution doesn't work if entmake is used, only with entmakex. Is that because entmakex gives it a handle and entity name or is it because it doesn't apply an owner? I just want to understand why this specific one works.

 

 

 

 

 

0 Likes
Message 4 of 5

pbejse
Mentor
Mentor
Accepted solution

 


@shannongreen_17 wrote:

 

This causes the field to evaluate but the problem is that it comes out at a massive text height. The format for number 1 and 3 allows me to set the criteria for the resulting text/mtext object but when I try to use entmod on number 2 nothing happens. Is there another way to edit the object or did I just not do it right? If entmod is the answer, how can I alter multiple criteria at the same time? For example, change the layer and the height at the same time.


 

Entnmod doesnt work with VLA objects, you need to convert the object to ENAME

 

	(setq CreatedMtext
		(vla-addMText
		      space
		      (vlax-3d-point 7.2743 2.8353 0.0)
		      4.
		      (strcat "MATCHLINE TO SHEET %<\$(-, $(getvar,ctab), 1)>%"
				)      
		    )
	      )
	(setq enameCreatedMtext (vlax-vla-object->ename CreatedMtext)
	      enameCreatedMtextEntData (entget enameCreatedMtext))

	(foreach itm
		     '((8 . "This Layer") (40 . 0.25))
	  (setq	enameCreatedMtextEntData
		 (entmod
		   (subst
		     itm
		     (assoc (Car itm)
			    enameCreatedMtextEntData
		     )
		     enameCreatedMtextEntData
		   )
		 )
	  )
	)

This will do the same thing without converting the object to ename

 

(setq CreatedMtext
		(vla-addMText
		      space
		      (vlax-3d-point 7.2743 2.8353 0.0)
		      4.
		      (strcat "MATCHLINE TO SHEET %<\$(-, $(getvar,ctab), 1)>%"
				)      
		    )
	      )
	(foreach itm
		 '(("Layer" . "This Layer") ("Height" . 0.25))
	  
	  (Vlax-put CreatedMtext (car itm) (Cdr itm)))


Set the TEXTSIZE to desired height and set layer to desired layer before running the program also works

 

IMHO stick with entmod/enmtmakex Shannon 🙂

 


@shannongreen_17 wrote:

Lastly, I realized that your solution doesn't work if entmake is used, only with entmakex. Is that because entmakex gives it a handle and entity name or is it because it doesn't apply an owner? I just want to understand why this specific one works.

Looks like you've beeen reading up on this

 

They both work really, difference is

entmakeX = returns the created entity
entmake = returns the created entity's dxf dump (same as entget).

 

HTH

 

Message 5 of 5

shannongreen_17
Contributor
Contributor

Thanks a lot for the reply. Really appreciate you taking the time to answer this 🙂

0 Likes