get x,y,z coordinate from multiple points

get x,y,z coordinate from multiple points

jyan2000
Advocate Advocate
4,936 Views
11 Replies
Message 1 of 12

get x,y,z coordinate from multiple points

jyan2000
Advocate
Advocate

Hello, 

 

Is it possible to get x,y,z coordinate from the selected point/s as shown in attached image. 

 

Best regards,

 

Victor. 

0 Likes
4,937 Views
11 Replies
Replies (11)
Message 2 of 12

hmsilva
Mentor
Mentor

@jyan2000 wrote:

Hello, 

 

Is it possible to get x,y,z coordinate from the selected point/s as shown in attached image. 

 

Best regards,

 

Victor. 


Hi Victor,

quick and dirty...

(defun c:demo (/ ent i pt ss txtx txty txtz)
    (if (setq ss (ssget '((0 . "POINT"))))
        (repeat (setq i (sslength ss))
            (setq ent  (entget (ssname ss (setq i (1- i))))
                  pt   (cdr (assoc 10 ent))
                  txtx (strcat "X=" (rtos (car pt) 2 2) "\\P")
                  txty (strcat "Y=" (rtos (cadr pt) 2 2) "\\P")
                  txtz (strcat "Z=" (rtos (caddr pt) 2 2))
            )
            (entmake (list
                         '(0 . "MTEXT")
                         '(100 . "AcDbEntity")
                         '(100 . "AcDbMText")
                         (cons 10 (list (car pt) (cadr pt)))
                         (cons 1 (strcat txtx txty txtz))
                     )
            )
        )
    )
    (princ)
)

 

Hope this helps,
Henrique

EESignature

Message 3 of 12

dbroad
Mentor
Mentor

@hmsilva has given a good solution if the need is to create an mtext object to document a point's location.

 

If this is intended as a point labelling device though, you should create a dynamic block with block placeholder fields inside its attributes that document the block's insertion point.  The block would probably be best an annotative one.  Then documenting and placing the block would be automatic.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 4 of 12

jyan2000
Advocate
Advocate

Its perfect.. that what I was looking for. Thanks a lot Henrique..

 

 

best regards

 

Victor 

0 Likes
Message 5 of 12

hmsilva
Mentor
Mentor

@jyan2000 wrote:

Its perfect.. that what I was looking for. Thanks a lot Henrique..

best regards

Victor 


You're welcome, Victor
Glad I could help

Henrique

EESignature

Message 6 of 12

Kent1Cooper
Consultant
Consultant

Here's a question:

That assembles an XY-only insertion point for the Mtext, so all the labels will be at Z=0, and associates it with a 10 for use as the insertion point in the entity data list.  But I assume, since the Z coordinate is part of the label, that the Points can be at different Z coordinates.  Should the Mtext labels be located at each Point's location in all three coordinates?  If so, there's no need to take the location and re-associate it with a 10, but you can use it already associated that way directly from the Point's entity data list.  [You can also eliminate a few variables that are used only once, by just constructing the text string right in the (entmake) list.]

 

(defun c:demo (/ ent i pt ss)
  (if (setq ss (ssget '((0 . "POINT"))))
    (repeat (setq i (sslength ss)); then
      (setq
        ent (entget (ssname ss (setq i (1- i))))
        pt (cdr (assoc 10 ent))
      )
      (entmake
        (list
          '(0 . "MTEXT")
          '(100 . "AcDbEntity")
          '(100 . "AcDbMText")
          (assoc 10 ent)
          (cons 1
            (strcat
              "X=" (rtos (car pt) 2 2) "\\P"
              "Y=" (rtos (cadr pt) 2 2) "\\P"
              "Z=" (rtos (caddr pt) 2 2)
            ); strcat
          ); cons
        ); list
      ); entmake
    ); repeat
  ); if
  (princ)
); defun

By the way, if an XY-only insertion point is wanted, this:

 

  (cons 10 (list (car pt) (cadr pt)))

 

can be simplified, to just this:

 

  (list 10 (car pt) (cadr pt))

Kent Cooper, AIA
Message 7 of 12

hmsilva
Mentor
Mentor

@Kent1Cooper wrote:

Here's a question:

That assembles an XY-only insertion point for the Mtext, so all the labels will be at Z=0, ...


I did put all Mtext at z=0, because our standards (we don't use 3d text), if OP need the MText with the same elevation as Point, it could be modified.

Yes, your comments regarding the creation of three variables are correct, but, I think that creating those three variables, makes the code easier to read and understand, to the OP...

 

Thank you

Henrique

EESignature

0 Likes
Message 8 of 12

jyan2000
Advocate
Advocate

Thank you a lot Kent Cooper. Your code looks perfect too. it looks like in the image. 

 

All my best wishes. 

 

Regards.

Victor

0 Likes
Message 9 of 12

jyan2000
Advocate
Advocate

dear Kent Cooper,

 

I really Loved this code. But, what should I do if I want Z= value  to be ( + / - ) plus or minus 100  but data will shown as " Z: 145.00 - 100 = 45.00" ?

 

Regards 

Victor

0 Likes
Message 10 of 12

Kent1Cooper
Consultant
Consultant

@jyan2000 wrote:

... what should I do if I want Z= value  to be ( + / - ) plus or minus 100  but data will shown as " Z: 145.00 - 100 = 45.00" ?

...


I'm not quite sure I understand exactly what you're asking [another sample image would be helpful], but you can construct such a string.  To get what you show at the end, but using whatever the actual Z value is in place of the example 145.00, replace this line:

 

"Z=" (rtos (caddr pt) 2 2)

 

with this:

 

"Z: " (rtos (caddr pt) 2 2) " - 100 = " (rtos (- (caddr pt) 100) 2 2)

 

You could also have the routine ask for a value [positive or negative] in place of the 100, earlier:

 

(setq Zoffs (getdist "\nZ-coordinate plus/minus value: "))

 

and build the string to show that value and account for whether it's positive or negative [untested]:

 

"Z: " (rtos (caddr pt) 2 2) " " (if (minusp Zoffs) "-" "+") " " (rtos Zoffs 2 2) " = " (rtos (- (caddr pt) Zoffs) 2 2)

 

You could use (getreal) instead of (getdist) for the Zoffs value; (getdist) allows on-screen distance pick if desired, but for a negative value the User wouldn't be able to do that, but would need to type it in.

Kent Cooper, AIA
Message 11 of 12

jyan2000
Advocate
Advocate

Applause once again Kent Cooper,

 

That was complete satisfaction. what I meant with plus or minus ( + / - ) was,

 

"Z: " (rtos (caddr pt) 2 2) " - 100 = " (rtos (- (caddr pt) 100) 2 2)

 

or

 

"Z: " (rtos (caddr pt) 2 2) " + 100 = " (rtos (+ (caddr pt) 100) 2 2)

 

So I could able to add or extract desired digit to Z value. 

 

Thanks a lot. 

Best Regards.

Victor

0 Likes
Message 12 of 12

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

....

You could also have the routine ask for a value [positive or negative] in place of the 100, earlier:

(setq Zoffs (getdist "\nZ-coordinate plus/minus value: "))

and build the string to show that value and account for whether it's positive or negative [untested]:

"Z: " (rtos (caddr pt) 2 2) " " (if (minusp Zoffs) "-" "+") " " (rtos Zoffs 2 2) " = " (rtos (- (caddr pt) Zoffs) 2 2)

....


I'm glad you like it, but I realize I made one mistake.  The blue line above should be:

"Z: " (rtos (caddr pt) 2 2) " " (if (minusp Zoffs) "-" "+") " " (rtos Zoffs 2 2) " = " (rtos (+ (caddr pt) Zoffs) 2 2)

 

because the User's input of a positive or negative value will determine whether it increases or decreases the Point's Z coordinate's value.

Kent Cooper, AIA
0 Likes