Jump to content

Retrieve pick point from a selected text entity


dax

Recommended Posts

To throw a spanner in the works if you want the insertion point for something to do with text this moves depending on the Justification, which there are 9 settings, you need to look at 2 variables Texinsertionpoint & Textalignmentpt. if you use a vlisp method via say DUMPIT.lsp you will see how the co-ords move.

 

Same text two different justifications

; InsertionPoint = (288.683 511.263 0.0)

; TextAlignmentPoint = (0.0 0.0 0.0)

 

; InsertionPoint = (178.969 511.263 0.0)

; TextAlignmentPoint = (288.683 511.263 0.0)

Link to comment
Share on other sites

  • Replies 32
  • Created
  • Last Reply

Top Posters In This Topic

  • dax

    12

  • Tharwat

    6

  • tombu

    4

  • Roy_043

    4

Top Posters In This Topic

Hi Roy

 

(trans (cdr (assoc 10 (entget ent))) ent 1)

 

The above code return (10 21.0 12.0 0.0). not the (615.0 332.0 0.0).

 

Thanks

Link to comment
Share on other sites

...but when using (entsel) then select the text entity (with "DAX" content) it return this one ( (615.0 332.0 0.0)), for my code above I did'nt get the (615.0 332.0 0.0) it gives me (10 21.0 12.0 0.0).

 

As I noted in my earlier post:

 

(cadr (entsel)) will give the coordinates of the center of the pickbox aperture at the time of selection.

 

The point returned by entsel is not a property of the text object, but merely the coordinates of the center of the pickbox when the text object is selected; therefore, you cannot obtain this point from the text object.

Link to comment
Share on other sites

@ dax:

It seems we are going around in circles. Maybe if you supply more code and/or a dwg your intentions will be clearer.

Link to comment
Share on other sites

@ dax:

It seems we are going around in circles. Maybe if you supply more code and/or a dwg your intentions will be clearer.

 

I'm betting when we finally find out what he's trying to do the code he needs has already been written and we'll post three versions of the code for him to try.

Link to comment
Share on other sites

@ Lee,

 

Thanks for the explanation. Is there a way to get the coordinate points of the selected entity?

 

@ Roy

 

Sorry for this.

 

@ tombu

 

My goal here is to create a circle from selected text entity and the text entity coordinates/location will be the mid point of the circle.

 

@ Lee, Roy, Tombu,

 

Thanks for the responses I really appreciate it.

Link to comment
Share on other sites

My goal here is to create a circle from selected text entity and the text entity coordinates/location will be the mid point of the circle.

 

You'll want to place the center of the circle at the midpoint of the points returned by the textbox function. You could also use the distance between these points to size the circles to contain the text.

 

There are many similar routines out there including the TCIRCLE Express Tool.

Link to comment
Share on other sites

Hi tombu,

 

Your correct on the TCIRCLE routine, but the routine I wanna create is without user interaction, meaning when I run the program it will automatic search the desired text entity then create a circle on it.

Link to comment
Share on other sites

Here is something to play with:

(defun KGA_Geom_MidPoint (pt1 pt2)
 (mapcar '/ (mapcar '+ pt1 pt2) '(2.0 2.0 2.0))
)

(defun KGA_Conv_Pickset_To_EnameList (ss / i ret)
 (if ss
   (repeat (setq i (sslength ss))
     (setq ret (cons (ssname ss (setq i (1- i))) ret))
   )
 )
)

(defun TextBoxMtext (elst / just pt)
 (setq pt (list (cdr (assoc 42 elst)) (cdr (assoc 43 elst)) 0.0))
 (setq just (cdr (assoc 71 elst)))
 (mapcar
   '(lambda (a b) (mapcar '* a b))
   (list pt pt)
   (cond
     ((= 1 just) '(( 0.0  0.0  0.0) ( 1.0 -1.0  0.0))) ; TL
     ((= 2 just) '((-0.5  0.0  0.0) ( 0.5 -1.0  0.0))) ; TC
     ((= 3 just) '((-1.0  0.0  0.0) ( 0.0 -1.0  0.0))) ; TR

     ((= 4 just) '(( 0.0  0.5  0.0) ( 1.0 -0.5  0.0))) ; ML
     ((= 5 just) '((-0.5  0.5  0.0) ( 0.5 -0.5  0.0))) ; MC
     ((= 6 just) '((-1.0  0.5  0.0) ( 0.0 -0.5  0.0))) ; MR

     ((= 7 just) '(( 0.0  1.0  0.0) ( 1.0  0.0  0.0))) ; BL
     ((= 8 just) '((-0.5  1.0  0.0) ( 0.5  0.0  0.0))) ; BC
     ((= 9 just) '((-1.0  1.0  0.0) ( 0.0  0.0  0.0))) ; BR
   )
 )
)

; (TEXTCIRCLE (car (entsel)) nil)
; (TEXTCIRCLE (car (entsel)) 1)
(defun TextCircle (enm margin / box elst ptCen) ; Margin: number or nil.
 (setq elst (entget enm))
 (setq box ((if (vl-position '(0 . "MTEXT") elst) TextBoxMtext textbox) elst))
 (setq ptCen (apply 'KGA_Geom_MidPoint box))
 (entmakex
   (list
     '(0 . "CIRCLE")
     (cons
       10
       (polar
         (if (vl-position '(0 . "MTEXT") elst)
           (trans (cdr (assoc 10 elst)) 0 (cdr (assoc 210 elst)))
           (cdr (assoc 10 elst))
         )
         (+ (cdr (assoc 50 elst)) (angle '(0.0 0.0 0.0) ptCen))
         (distance '(0.0 0.0 0.0) ptCen)
       )
     )
     (cons
       40
       (+
         (distance (car box) ptCen)
         (cond (margin) ((/ (cdr (assoc 40 elst)) 2.0)))
       )
     )
     (assoc 210 elst)
   )
 )
)

(defun c:Test ( / doc ss)
 (vl-load-com)
 (setq doc (vla-get-activedocument (vlax-get-acad-object)))
 (vla-endundomark doc) ; End open undo group.
 (vla-startundomark doc)
 (if (setq ss (ssget '((0 . "ATTDEF,ATTRIB,MTEXT,TEXT"))))
   (foreach enm (KGA_Conv_Pickset_To_EnameList ss)
     (TextCircle enm nil)
   )
 )
 (vla-endundomark doc)
 (princ)
)

Link to comment
Share on other sites

Hi Guys,

 

Below code what I've done so far, I successfully select the desired text entity (DAX) and create a circle on it (credit to Lee i've used the "MINENCCIRCLE"), but if there are multiple Dax text entity on the drawing it wont make separate circle, it just encircle those selected text entity, I know there something wrong on my code, trying to modifying it at this time. Please bear with my code, starting learning lisp.. :)

 

(defun c:SearchTextContent ( / str ss ssL entName i obj insPt ca p x y z yCP l e c ii imp elist s cmde cen rad elast at)*

(setq str "DAX")

(if (setq ss (ssget "_X" (list (cons 0 "*TEXT") (cons 1 str) (cons 410
(getvar 'ctab)))))
(sssetfirst nil ss); select/highlight/grip
)

(setq ssL (sslength ss))
(setq ii 0)
( while ( > ssL ii )

(progn
(setq entName (ssname ss ii))
(princ entName)
(setq obj (vlax-ename->vla-object entName))
(setq insPt (vlax-get-property obj 'insertionpoint))
(setq ca (vlax-variant-value insPt))
(setq p (vlax-safearray->list ca))



(if (setq p (vlax-safearray->list ca))

(progn
(setq x (car p))
(setq yCP (cadr p))
(setq z (caddr p))
(setq y (- yCP 50))
(setq p (list x y z))
(setq p (trans p 1 0)
l (cons p l)
)
(entmake (list '(0 . "POINT") (cons 10 p)))
(setq y (+ yCP 50))
(setq p (list x y z))
(if e
(progn (entdel e) (setq e nil))
)
(setq p (trans p 1 0)
l (cons p l)
)
(if (setq c (LM:MinEncCircle l))
(setq e (entmakex (list '(0 . "CIRCLE") (cons 10 (car c)) (cons 40 (cadr c)))))
)
(setq cmde (getvar "cmdecho"))
(setvar "cmdecho" 0)

)
)
(setq ii ( + ii 1))
)
)
(print "end while")
(setq p nil)
(princ)
)

Link to comment
Share on other sites

Hi Guys,

 

Below code what I've done so far, I successfully select the desired text entity (DAX) and create a circle on it (credit to Lee i've used the "MINENCCIRCLE"), but if there are multiple Dax text entity on the drawing it wont make separate circle, it just encircle those selected text entity, I know there something wrong on my code, trying to modifying it at this time. Please bear with my code, starting learning lisp.. :)

 

 

Well - there are several problems and unnecessary steps in your code. Please take a look at this code:

(defun c:SearchTextContent ( / str ss obj mn mx ii)
  (vl-load-com)
  (setq str "DAX")
  (if (setq ss (ssget "_X" (list (cons 0 "*TEXT") (cons 1 str) (cons 410 (getvar 'ctab))))) ;;Get the Selection Set.
     (repeat (sslength ss) ;; Iterate the length of the Selection set
        ;; Get the VLA-Object and set or increase the counter
        (setq obj (vlax-ename->vla-object (ssname ss (setq ii (if ii (1+ ii) 0)))))
        ;; Get the Bounding Box of the Text Object
        (vla-getboundingbox obj 'mn 'mx)
        ;; if a valid bounding box,
        (if (and mn mx)
           (progn
              ;; Convert the variants to point lists
              (setq mn (vlax-safearray->list mn)
                    mx (vlax-safearray->list mx)
              )
              ;; Run Lee's code to get the curcle
              (setq c (LM:MinEncCircle (list mn mx)))
              ;; Create the circle
              (entmakex (list '(0 . "CIRCLE") (cons 10 (car c)) (cons 40 (cadr c))))
           )
        )
     )
  )
  (princ)
)












Link to comment
Share on other sites

Yes - with a bit of digging in the express tools folder: (bns_tcircle ). The file "acettxt.lsp" must be loaded prior if a manual call to the TCIRCLE command has not be made.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...