Extract insertion point of existing Mtext

Extract insertion point of existing Mtext

Anonymous
Not applicable
1,308 Views
4 Replies
Message 1 of 5

Extract insertion point of existing Mtext

Anonymous
Not applicable

The fourth line-  Need to use the Mtext that is in my selection set, ss1, rather than prompt the user. This program is a snippet of one that will delete an existing Mtext and insert a new Mtext using a notepad file(already have that figured out). I think the selection set needs to be converted to a list that VLA can understand. I've tried modifying some examples with no luck. The circle is just for me to verify that the program is extracting the insertion point.

 

(defun c:ptTest (/ ss1 mtext mobj base)
(setq ss1 (ssget "_C" '(86 342) '(-11 303) '((0 . "mtext"))))

(vl-load-com)
(setq mtext (car (entsel "\Select mtext:")))
(setq mobj (vlax-ename->vla-object mtext))
(setq base (vlax-safearray->list (vlax-variant-value (vlax-get-property mobj 'insertionpoint))))

(command "circle" base "2")
)

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

CodeDing
Advisor
Advisor
Accepted solution

@Anonymous ,

 

Assuming your selection set will only consist of 1 MTEXT object, then this should work:

(defun c:ptTest ( / ss1 mtext base osm)
(if (setq ss1 (ssget "_C" '(86 342) '(-11 303) '((0 . "mtext"))))
  (progn
    (setq mtext (ssname ss1 0))
    (setq base (cdr (assoc 10 (entget mtext))))
    (setq osm (getvar 'OSMODE)) (setvar 'OSMODE (logior 16384 osm))
    (command "circle" base "2")
    (setvar 'OSMODE osm)
  );progn
  (prompt "\nNo MTEXT found...")
);if
(princ)
);defun

If it ever will contain more than 1 then you would need to loop through the selection set...

 

Best,

~DD

0 Likes
Message 3 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

The simple answer is to replace this:

 

(setq mtext (car (entsel "\Select mtext:")))

 

with this:

 

(setq mtext (ssname ss1 0)); get the first entity name out of the selection set

 

and you should be able to keep the rest.  @CodeDing suggested a simpler way to get the insertion point, but in their Circle-drawing part, I would not bother saving and changing and resetting the OSMODE setting, but rather would simply add a "none" Osnap call before giving it the base point for the Circle's center:

 

(command "circle" "_none" base 2)

 

[and the 2 can be just a number -- it doesn't need quotation marks to make it a text string].

Kent Cooper, AIA
Message 4 of 5

Anonymous
Not applicable

Perfect!

Thanks for the help.

0 Likes
Message 5 of 5

Anonymous
Not applicable

Hey Ken. That works too. Thanks for the additional info.

0 Likes