Jump to content

How to update text value with x, y coordinate values automatically


long12345

Recommended Posts

Hi all,
I create a text entity with x, y coordinate value example as below (100.0 100.0 0.0)
(entmake (list (cons 0 "TEXT") (cons 10 (list 100.0 100.0 0.0)) (cons 40 25) (cons 1 "100.0,100.0")))

 

then I get the text entity info with:

Command: (entget (entlast))
((-1 . <Entity name: 17e9ede32f0>) (0 . "TEXT") (330 . <Entity name: 17eea97c700>) (5 . "467") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbText") (10 100.0 100.0 0.0) (40 . 25.0) (1 . "100.0,100.0") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "Standard") (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 0))

 

then I select the text entity and move it to (297.46 231.108 0.0), but the text value is still "100.0,100.0"

I get the text entity info with:
Command: (entget (entlast))
((-1 . <Entity name: 17e9ede32f0>) (0 . "TEXT") (330 . <Entity name: 17eea97c700>) (5 . "467") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbText") (10 297.46 231.108 0.0) (40 . 25.0) (1 . "100.0,100.0") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "Standard") (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 0))

 

I would like the text value is updated with new x, y coordinate value (297.46 231.108 0.0) automatically.
How could I do that with autolisp?
Thanks

Edited by long12345
Link to comment
Share on other sites

1 hour ago, long12345 said:

Hi all,
I create a text entity with x, y coordinate value example as below (100.0 100.0 0.0)
(entmake (list (cons 0 "TEXT") (cons 10 (list 100.0 100.0 0.0)) (cons 40 25) (cons 1 "100.0,100.0")))

 

then I get the text entity info with:

Command: (entget (entlast))
((-1 . <Entity name: 17e9ede32f0>) (0 . "TEXT") (330 . <Entity name: 17eea97c700>) (5 . "467") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbText") (10 100.0 100.0 0.0) (40 . 25.0) (1 . "100.0,100.0") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "Standard") (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 0))

 

then I select the text entity and move it to (297.46 231.108 0.0), but the text value is still "100.0,100.0"

I get the text entity info with:
Command: (entget (entlast))
((-1 . <Entity name: 17e9ede32f0>) (0 . "TEXT") (330 . <Entity name: 17eea97c700>) (5 . "467") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . "AcDbText") (10 297.46 231.108 0.0) (40 . 25.0) (1 . "100.0,100.0") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "Standard") (71 . 0) (72 . 0) (11 0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbText") (73 . 0))

 

I would like the text value is updated with new x, y coordinate value (297.46 231.108 0.0) automatically.
How could I do that with autolisp?
Thanks

 

I don't think this is possible with text, but is possible with a block (see attached example dwg). The drawing contains a block (coords) which has a single attribute, which contains a field linked to the blocks insertion point. If you insert the block in will display the insertion point. If you move or copy the block you will need to do a regen.

coord.dwg

  • Thanks 1
Link to comment
Share on other sites

Like Dlanorh you can use a mtext Field it would normally have something its tied to like a point, a end point and so on.

 

The simplest is to use a Autocad point you can display or not.

 

image.png.c5a92ca6c379a9d43c9b9ffb4a0ed559.png

 

 

  • Thanks 1
Link to comment
Share on other sites

Thank you.

So the solution is : Block + Attribute + Field...

Because this is a common case in autolisp world, it's good if there is a sample autolisp code for my reference.

 

How about event handing system in autolisp?

It's very easy to modify a dxf code value of a text entity such as this code from Lee Mac

(defun c:req ( / ent enx )
   (while
       (progn (setvar 'errno 0) (setq ent (car (entsel)))
           (cond
               (   (= 7 (getvar 'errno))
                   (princ "\nMissed, try again.")
               )
               (   (null ent) nil)
               (   (not (wcmatch (cdr (assoc 0 (setq enx (entget ent)))) "TEXT,MTEXT"))
                   (princ "\nPlease select a text or mtext object.")
               )
               (   (entmod (subst '(1 . "REQUIRED") (assoc 1 enx) enx)))
           )
       )
   )
   (princ)
)

 May I catch a position change event then updating the text value with new x,y coordinate values? 

 

Link to comment
Share on other sites

20 hours ago, dlanorh said:

 

I don't think this is possible with text, but is possible with a block (see attached example dwg). The drawing contains a block (coords) which has a single attribute, which contains a field linked to the blocks insertion point. If you insert the block in will display the insertion point. If you move or copy the block you will need to do a regen.

coord.dwg 67.46 kB · 2 downloads

 

when I open the attached file coord.dwg some label value is changed to ###### in my drawing file......

it's strange.......... I also see the function "s::startup-load" run that I never see before........

Edited by long12345
Link to comment
Share on other sites

On 3/3/2020 at 6:28 AM, BIGAL said:

Like Dlanorh you can use a mtext Field it would normally have something its tied to like a point, a end point and so on.

 

The simplest is to use a Autocad point you can display or not.

 

image.png.c5a92ca6c379a9d43c9b9ffb4a0ed559.png

 

 

 

Thank you.

Now, I could select another Object such as : Line, Circle ........and see its Property......a kind of object oriented...

very helpful information for me......

Link to comment
Share on other sites

You can actually achieve this with a self-referencing text field (though, this has to be created programmatically):

(defun c:test ( / o p )
    (if (setq p (getpoint "\nSpecify insertion point: "))
        (progn
            (setq o
                (vla-addtext
                    (vlax-get-property (LM:acdoc)
                        (if (= 1 (getvar 'cvport))
                            'paperspace
                            'modelspace
                        )
                    )
                    " "
                    (vlax-3D-point (trans p 1 0))
                    (getvar 'textsize)
                )
            )
            (vla-put-textstring o
                (strcat
                    "%<\\AcObjProp Object(%<\\_ObjId "
                    (LM:objectid o)
                    ">%).InsertionPoint \\f \"%lu2%pt3%pr1\">%"
                )
            )
            (vla-regen (LM:acdoc) acactiveviewport)
        )
    )
    (princ)
)

;; ObjectID  -  Lee Mac
;; Returns a string containing the ObjectID of a supplied VLA-Object
;; Compatible with 32-bit & 64-bit systems
 
(defun LM:objectid ( obj )
    (eval
        (list 'defun 'LM:objectid '( obj )
            (if (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
                (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
               '(itoa (vla-get-objectid obj))
            )
        )
    )
    (LM:objectid obj)
)

;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object

(defun LM:acdoc nil
    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:acdoc)
)

(vl-load-com) (princ)

 

  • Thanks 3
Link to comment
Share on other sites

Thank you.

I know this Field expression

 

"%<\\AcObjProp Object(%<\\_ObjId "
                    (LM:objectid o)
                    ">%).InsertionPoint \\f \"%lu2%pt3%pr1\">%"
Link to comment
Share on other sites

HELLO LEE   

 

PLEASE ADD FUNCTION   X=         , Y=        ,Z=

AND CHANGE FONT SIZE  AS PER DRAWING SCALE 

 

Link to comment
Share on other sites

  • 2 weeks later...
On 3/6/2020 at 6:08 AM, goyalx1d said:

HELLO LEE   

 

PLEASE ADD FUNCTION   X=         , Y=        ,Z=

AND CHANGE FONT SIZE  AS PER DRAWING SCALE 

 

With the permition of Lee-Mac

Maybe this can help you

COORX.lsp

Link to comment
Share on other sites

On 3/6/2020 at 6:08 AM, goyalx1d said:

HELLO LEE   

 

PLEASE ADD FUNCTION   X=         , Y=        ,Z=

AND CHANGE FONT SIZE  AS PER DRAWING SCALE 

 

;;;  LEE-MAC Programming
;;; Modified by PBG 20/03/01
;; https://www.cadtutor.net/forum/topic/69959-how-to-update-text-value-with-x-y-coordinate-values-automatically/?tab=comments#comment-562342

(defun c:coorx ( / o p ptoX ptoY ptoZ)

	(setq ptoX "%lu2%pt1%pr2%ls59%ps[X=,   ]%ds44%th46\">%")
	(setq ptoY "%lu2%pt2%pr2%ls59%ps[Y=,  ]%ds44%th46\">%")
	(setq ptoZ "%lu2%pt4%pr2%ls59%ps[Z=,]%ds44%th46\">%")

    (if (setq p (getpoint "\nSpecify insertion point: "))
        (progn
            (setq o
                (vla-addtext
                    (vlax-get-property (LM:acdoc)
                        (if (= 1 (getvar 'cvport))
                            'paperspace
                            'modelspace
                        )
                    )
                    " "
                    (vlax-3D-point (trans p 1 0))
                    (getvar 'textsize)
                )
            )
            (vla-put-textstring o
                (strcat
                    "%<\\AcObjProp Object(%<\\_ObjId "
                    (LM:objectid o)
                    ">%).InsertionPoint \\f \"" ptoX 
	   "\\U+000A"
	  "%<\\AcObjProp Object(%<\\_ObjId "
                    (LM:objectid o)
                    ">%).InsertionPoint \\f \"" ptoY 
	     "%<\\AcObjProp Object(%<\\_ObjId "
                    (LM:objectid o)
                    ">%).InsertionPoint \\f \"" ptoZ
                )
            )
            (vla-regen (LM:acdoc) acactiveviewport)
        )
    )
    (princ)
)

;; ObjectID  -  Lee Mac
;; Returns a string containing the ObjectID of a supplied VLA-Object
;; Compatible with 32-bit & 64-bit systems
 
(defun LM:objectid ( obj )
    (eval
        (list 'defun 'LM:objectid '( obj )
            (if (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
                (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
               '(itoa (vla-get-objectid obj))
            )
        )
    )
    (LM:objectid obj)
)

;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object

(defun LM:acdoc nil
    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:acdoc)
)

(vl-load-com) (princ)

With the permition of Lee-Mac, maybe this can help you

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...