Jump to content

how to get x and y coordinates of selected shape


Recommended Posts

Posted (edited)

Hello people i am new in autolisp programing, i have simple question. how to show x and y coordinates and block name of selected shape in alertbox?

my example(not working):

 

(defun c:get (/ pt)
(setq pt (getpoint (entsel "\nSpecify  point: ")))

 (alert pt)
(princ)
 )

Edited by SLW210
Code Tags
Posted

Welcome to CADTutor, insane!

 

Your code revised

(defun c:get (/ pt)
 (if (setq pt (getpoint "\nSpecify point: "))
   (alert (strcat "X = " (rtos (car pt)) "\nY = " (rtos (cadr pt))))
 )
 (princ)
)

And the block and the x,y coordinates

(vl-load-com)
(defun c:demo ( / ins name obj ss)
 (if (setq ss (ssget "_+.:E:S" '((0 . "INSERT"))))
   (progn
     (setq obj  (vlax-ename->vla-object (ssname ss 0))
           name (vla-get-effectivename obj)
           ins  (vlax-get obj 'insertionpoint)
     )
     (alert (strcat "Block Name = "
                    name
                    "\nX = "
                    (rtos (car ins))
                    "\nY = "
                    (rtos (cadr ins))
            )
     )
   )
 )
 (princ)
)

Henrique

Posted

Well big thank you !

 

almost forgot to ask

 

(if (setq ss (ssget "_+.:E:S" '((0 . "INSERT"))))

what does this line?

and this

 (setq obj  (vlax-ename->vla-object (ssname ss 0))
           name (vla-get-effectivename obj)
           ins  (vlax-get obj 'insertionpoint)
     )

Posted

You're welcome, insane.

 ;; if select a single block
 (if (setq ss (ssget "_+.:E:S" '((0 . "INSERT"))))
   (progn
     ;; Transforms the firts selected object to a VLA-object
     (setq obj  (vlax-ename->vla-object (ssname ss 0))
           ;; get the effective name from the block object
           name (vla-get-effectivename obj)
           ;; get the insertionpoint from the block object
           ins  (vlax-get obj 'insertionpoint)
     )

 

Henrique

Posted

Here is a little lisp that allows you to pick a object and see its properties it can be used with VLisp to Vla-get a property or VLA-put a new property. If you pick a block you will see the "Insertionpoint" "Scale" "Rotation" etc

 

A point is normally made up of 3 parts X Y Z using x=car y=Cadr and z=Caddr you can get the individual info, another method is nth, x= nth 0 pt, y=nth 1 pt, Z=nth 2 pt.

 

;; Dump all methods and properties for selected objects              ;
;;;===================================================================; 
;;; DumpIt                                                            ; 
;;;-------------------------------------------------------------------; 
;;;===================================================================; 
(defun C:DumpIt ( / ent) 
 (while (setq ent (entsel)) 
   (vlax-Dump-Object 
     (vlax-Ename->Vla-Object (car ent)) T
   ) 
 ) 
 (princ) 
)

  • 2 weeks later...
Posted

Hi :)

How can I ad Z value to this code:

(defun c:get (/ pt)   (if (setq pt (getpoint "\nSpecify point: "))     (alert (strcat "X = " (rtos (car pt)) "\nY = " (rtos (cadr pt))))   )   (princ) )

Thank you :)

Posted
Hi :)

How can I ad Z value to this code:

 

Replace this part :)

 

(strcat "X = " (rtos (car pt)) "\nY = " (rtos (cadr pt)) "\nZ = " (rtos (caddr pt)))

Posted

All credit goes to Henrique ;)

Nice what you've said, my friend. :)

But all the credits for the modification are going to you Tharwat. ;)

 

Cheers

Henrique

Posted

Tharwat You can lead a horse to water but it may not drink, in my post z=caddr given 237 posts would have thought starting to learn.

Posted
Tharwat ............. , in my post z=caddr given 237 posts would have thought starting to learn.

 

Be more clear and straight to the point please , I am listening .

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