MTEXT Entmake

MTEXT Entmake

zph
Collaborator Collaborator
5,368 Views
16 Replies
Message 1 of 17

MTEXT Entmake

zph
Collaborator
Collaborator

Good day,

 

I am having issue creating an MTEXT entity using Entmake:

 

(setq nVal (cadr rL))
(setq nStyle (cdr (assoc 7 (entget mL))))
(setq cIns (cdr (assoc 10 (entget mL))))
(setq cTh (cdr (assoc 40 (entget mL))))
(setq nIns (list (car cIns) (+ (cadr cIns) 19.25) 0))

(terpri)(princ nVal)
(terpri)(princ nStyle)
(terpri)(princ nLayer)
(terpri)(princ cIns)
(terpri)(princ nIns)
(terpri)(princ cTh)
(princ "\n 9 ")

(entmake
	(list
		(cons 0 "MTEXT")
		(cons 1 nVal)
		(cons 7 nStyle)
		(cons 8 nLayer)
		(cons 10 nIns)
		(cons 40 cTh)
		(cons 41 0.0)
		(cons 50 0.0)
		(cons 71 2)
		(cons 72 1)
		(cons 100 "AcDbEntity")
		(cons 100 "AcDbMText")
	) ;list
) ;entmake

(princ "\n 10 ")

 

The routine completes, but the Mtext object doesn't show up.  Do you guys know what is going on?

 

EDIT:  I've attached the entire routine for context (if you need it).

0 Likes
Accepted solutions (2)
5,369 Views
16 Replies
Replies (16)
Message 2 of 17

Ranjit_Singh
Advisor
Advisor

Nothing seems wrong with the mtext entmake portion. In below line

(princ "\n No MTEXT entities on "A-AREA-IDEN" layer.")

A-AREA-IDEN is a symbol and evaluates to nil. Add backslash for your quotes

 

(princ "\n No MTEXT entities on \"A-AREA-IDEN\" layer.")
Message 3 of 17

john.uhden
Mentor
Mentor

I noticed that your snippet includes (cons 100 "AcDbMtext")

but your file says (cons 100 "AcDbText")

 

Thus it appears you have a conflict that AutoCAD doesn't automatically handle.

 

Oh, and maybe it's okay but your Room_No_Create function sets nval to (cadr rlist) which is "RoomName" not "RoomNumber."

John F. Uhden

0 Likes
Message 4 of 17

zph
Collaborator
Collaborator

Ranjit,

 

Thank you for pointing this out!  I fixed this, but it didn't resolve the issue of the MTEXT object being displayed after being created using ENTMAKE.

 

~Z

0 Likes
Message 5 of 17

ВeekeeCZ
Consultant
Consultant
Accepted solution

Not sure when but sometimes the order matters.

 

      (cons 0 "MTEXT")
      (cons 100 "AcDbEntity")
      (cons 100 "AcDbMText")
...

This may help.

0 Likes
Message 6 of 17

zph
Collaborator
Collaborator
Accepted solution

John,

 

You are correct.  This was a latch ditch effort to create a 'simpler' object (TEXT) just to see if the routine would work.  I just forgot to add the M back after removing it.

 

I added it back, but still no cigar.

 

Yes, the first item in rList is the room number and second item is room name.

 

I fooled around with this routine again this morning, but to no avail.

 

So, I tried a different way that works:

 

(defun ROOM_NAME_ADD_create ( / t1)

(command "copy" mL "" "" "" "move" mL "" (list 0 0 0) (list 0 19.25 0))
(setq t1 (vlax-ename->vla-object mL))
(vla-put-textString t1 (cadr rL))
(vla-put-layer t1 nLay)
(vla-put-width t1 nWid)
(vla-put-height t1 nHgt)

) ;ROOM_NAME_ADD_create

 

VLA for the win!

 

~Z

0 Likes
Message 7 of 17

john.uhden
Mentor
Mentor

In my limited testing, ROOM_NO_Create never gets called.

John F. Uhden

0 Likes
Message 8 of 17

zph
Collaborator
Collaborator

John, thank you for taking the time to test it.

 

However, I intentionally placed (princ "\n # ") in the 'Create' function to see if it was entered during the execution...and it always was.

 

Also, since switching from entmake to copy/move/modify, the routine works as needed.

 

Cheers!

0 Likes
Message 9 of 17

john.uhden
Mentor
Mentor

Cheers to you too.  Don't forget to accept your own solution.

John F. Uhden

0 Likes
Message 10 of 17

zph
Collaborator
Collaborator

After reordering the list to have the "100"s directly after the "0", the ENTMAKE function worked.

 

So, I accepted this as a solution as well.

 

However, the ENTMAKE option seems to be a little bit slower than the option I chose.

 

I wrote a benchmark routine a while back, but I'm not sure where it is.

 

Do you guys know of the good one?

0 Likes
Message 11 of 17

zph
Collaborator
Collaborator

So, using (getvar "millisecs") and taking the difference between the execution and ending the routine actually found the opposite.

 

With 885 room numbers present in variable rList, ENTMAKE took 19 (2nd test 17) seconds while VLA + copy/move/update took 20 (2nd test 19) seconds.

 

So, looks like I'll be using ENTMAKE after all 🙂

 

Cheers everyone!

~Z

 

 

0 Likes
Message 12 of 17

ВeekeeCZ
Consultant
Consultant

The COMMAND version is usually slower. (do you really care so much?)

 

Some other versions: 

 

(defun c:CopyMText nil
  
  (setq ml (car (entsel "Mtext: ")))
  
  (command "_.COPY" mL "" "_D" (list 0 19.25 0))
  (setq t1 (vlax-ename->vla-object (entlast)))
  (vla-put-textString t1 "Content")
  (vla-put-layer t1 "Layer1")
  (vla-put-width t1 0.8)
  (vla-put-height t1 2)
  )


(defun c:EntmakeAppendText nil
  
  (setq ed (entget (car (entsel "Text: ")))
	pt (assoc 10 ed))
  
  (entmake
    (append
      ed
      (list
	(cons 1 "Content")
	(cons 8 "Layer1")
	(cons 40 2)
	(cons 41 0.8)
	(list 10 (cadr pt) (+ 19.25 (caddr pt)) (last pt))
	(list 11 (cadr pt) (+ 19.25 (caddr pt)) (last pt))
	))))

 

 

0 Likes
Message 13 of 17

zph
Collaborator
Collaborator

It isn't that I care so much, but I was curious if one method was faster than the other.  Turns out, one of them was ~10% faster.  So, I stuck with the faster one 😉

0 Likes
Message 14 of 17

john.uhden
Mentor
Mentor

Those nanoseconds can add up.  You might be able to leave work a minute earlier at the end of the year.

John F. Uhden

0 Likes
Message 15 of 17

zph
Collaborator
Collaborator

Nah, too many clock watchers around here for that 😉

 

I'll just need to be content with knowing that I can deliver a product to my customer in minutes as opposed to hours/days.

0 Likes
Message 16 of 17

Anonymous
Not applicable

Hi, I tried using your lisp but it gives me an error every time. Would you please share your final version of the code in here so I can give it a try?

0 Likes
Message 17 of 17

Anonymous
Not applicable

Hi, I tried using your lisp but it gives me an error every time. Would you please share your final version of the code in here so I can give it a try?

 

Farid

0 Likes