long12345 Posted March 2, 2020 Posted March 2, 2020 (edited) 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 March 2, 2020 by long12345 Quote
dlanorh Posted March 2, 2020 Posted March 2, 2020 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 1 Quote
BIGAL Posted March 2, 2020 Posted March 2, 2020 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. 1 Quote
long12345 Posted March 3, 2020 Author Posted March 3, 2020 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? Quote
long12345 Posted March 3, 2020 Author Posted March 3, 2020 (edited) 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 March 3, 2020 by long12345 Quote
long12345 Posted March 4, 2020 Author Posted March 4, 2020 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. 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...... Quote
Lee Mac Posted March 4, 2020 Posted March 4, 2020 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) 3 Quote
long12345 Posted March 5, 2020 Author Posted March 5, 2020 Thank you. I know this Field expression : "%<\\AcObjProp Object(%<\\_ObjId " (LM:objectid o) ">%).InsertionPoint \\f \"%lu2%pt3%pr1\">%" Quote
Tron Posted March 5, 2020 Posted March 5, 2020 Do is posbile to the lisp ask me wich text I want to insert and give the coordinates to where be inserted? Quote
goyalx1d Posted March 6, 2020 Posted March 6, 2020 HELLO LEE PLEASE ADD FUNCTION X= , Y= ,Z= AND CHANGE FONT SIZE AS PER DRAWING SCALE Quote
tombu Posted March 6, 2020 Posted March 6, 2020 Many ways to do this, Tharwat wrote one with leaders from text placement to the point: https://www.cadtutor.net/forum/topic/68126-require-lisp-3-in-1-for-xyz-coordinates-with-leader/?tab=comments#comment-552696 another: https://www.cadtutor.net/forum/topic/62823-xy-coordinates-for-a-selected-object/?tab=comments#comment-518368 1 Quote
pbelon Posted March 20, 2020 Posted March 20, 2020 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 Quote
pbelon Posted March 21, 2020 Posted March 21, 2020 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 Quote
Recommended Posts
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.