Using entlast...

Using entlast...

zph
Collaborator Collaborator
2,303 Views
5 Replies
Message 1 of 6

Using entlast...

zph
Collaborator
Collaborator

Good day!

 

I have the following routine set up to use txt2mtext and then manually select the new MTEXT entity.  This routine works, but I want the finished MTEXT entity to automatically be added the "textObject" selection set.  I am attempting to use entlast to add the entity to a selection set. 

 

Here is what I've come up with, but of course, the commented lines are me trying to figure this out.  Also, this is all a part of a larger routine that requires the selection set variable "textObject" to contain the MTEXT entity to complete successfully.

 

 

---

 

 (if (= (cdr (assoc 0 (entget (ssname textObject 0)))) "TEXT")
  (progn
  (setq textObject nil)
  (princ "\n\033\n  <>  Select TEXT objects to convert to MTEXT  <>  ")
  (command "txt2mtxt" (ssget) "")
  ;(setq textName (handent (entlast)))
  ;(setq textObject (ssadd (handent textName))
  (princ "\n\033\n  <>  Select the MTEXT object  <>  ")

  ;(setq textName (vla-get-objectid (vlax-ename->vla-object (entlast))))

  ;(setq textName (entlast))
  ;(princ textName) (terpri)
  ;(setq textObject (ssadd (handent textName)))
  ;(princ (handent textName))

  (setq textObject (ssget ":S"))
  ) ;progn
 ) ;if

0 Likes
Accepted solutions (2)
2,304 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

That's not difficult, if I understand correctly what you're trying to do, and assuming that the Text object is the only thing in the textObject selection set when this begins [or if there's more than one thing in that selection, you want to apply TXT2MTXT to them all], and that the same object is always the same one you want to convert to Mtext and put back into that selection-set variable.  Try this:

 

(if (= (cdr (assoc 0 (entget (ssname textObject 0)))) "TEXT")
(progn
(command "txt2mtxt" textObject "")
(setq textObject (ssadd (entlast)))
) ;progn
) ;if

You don't need to select it for TXT2MTXT since the routine can find it, nor to "nil out" the textObject variable because the (ssadd) function, without being given a variable name to add to, will just replace it.

Kent Cooper, AIA
Message 3 of 6

zph
Collaborator
Collaborator

Thank you for your reply, Kent!

Your use of entlast is exactly what I needed.

 

 

---

 

I have one more problem.  Later in the code I have this:

 

(vlax-put (vlax-ename->vla-object (ssname textObject 0)) 'width textBoxWidth)

 

This code does update the text box width when the txt2mtext portion is executed, but doesn't update is the original selection set is already MTEXT.  Any ideas?

0 Likes
Message 4 of 6

zph
Collaborator
Collaborator

Ok. I figured out that the reason the text box width won't update is because the MTEXT in my drawing has its 'column' setting set to 'dynamic'. After the txt2mtxt command is run on TEXT it produces an MTEXT entity with a column setting on 'none'.

I tried this code below to replace the column setting (if it exists) or constructs (if it doesn't exist) it, but it just returns "nil" to the cmd line.

(setq textName (ssname textObject 0))
(setq textList (entget textName))

(if (assoc 75 textList)
(progn (setq textList (subst (cons 75 0) (assoc 75 textList) textList)(entmod textList)) ;progn
(progn (setq textList (append textList (cons 75 0))) ;progn
) ;if

 

EDIT:  found the solution

 

(setq textName (ssname textObject 0))
(setq textList (entget textName))

(setq textList
 (if (assoc 75 textList)
 (subst (cons 75 0) (assoc 75 0) textList)
 (append textList (list (cons 75 0)))
 ) ;if
) ;setq
(entmod textList)

0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@zph wrote:

.... 

(setq textName (ssname textObject 0))
(setq textList (entget textName))

(setq textList
 (if (assoc 75 textList)
 (subst (cons 75 0) (assoc 75 0) textList)
 (append textList (list (cons 75 0)))
 ) ;if
) ;setq
(entmod textList)


This:

(subst (cons 75 0) (assoc 75 0) textList)

should be done this way:

(subst (cons 75 0) (assoc 75 textList) textList)

or:

(subst '(75 . 0) (assoc 75 textList) textList)

 

But if my experience with similar situations holds true here, if there are two association-list entries with the same initial number, and the entity data for that object type can use only one such entry, the later one wins out over the earlier one, so the entry you want can just be added at the end of the entity data list, without (subst)-ing.  You could just do this [untested]:

 

(setq textName (ssname textObject 0))
(entmod

  (append

    (entget textName)

    '((75 . 0))

  )

)

 

If there's a 75-code entry earlier in the list, the (append)ed one will overrule it.  If there isn't one, adding it won't bother anything.

Kent Cooper, AIA
Message 6 of 6

zph
Collaborator
Collaborator
You are correct, good sir.

And your untested code worked like a charm!

0 Likes