help to get geometry position values for points on drawing

help to get geometry position values for points on drawing

miroslav.pristov
Advocate Advocate
1,473 Views
6 Replies
Message 1 of 7

help to get geometry position values for points on drawing

miroslav.pristov
Advocate
Advocate

Hello all I have drawing in georeferenced system

 

I need to get geometry values for some points on drawing.

 

What I usually do? I pick each point, open properties, copy position X, paste in excell, etc.. the same i do with Y and Z position.

 

If u have one point this is ok but if You have 50 points or more its quite boring and i can make error somewhere.

 

I didnt find any command which will help me to simplify this procedure, i ll try to find similar lisp, but i didnt find it. 

 

So can someone please help me and make me a lisp for this. to choose points in a row like point 1, 2, 3, 4, 5, etc and when i choose the last one the lisp made me a table in Autocad which will look like this bellow.

 

point                X                       Y                            Z

1             positionX1           positionY1            position Z1

2             positionX2           positionY2            position Z2

.                      .                          .                              .

.                      .                          .                              .

.                      .                          .                              .

LAST      positionXLAST      positionYLAST     position ZLAST

 

Any help will be great thank you.

 

 

0 Likes
Accepted solutions (2)
1,474 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Points to Excel. This works for me.

 

(defun c:Points2CSV ( / *error* file txt pnt lst i)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if file (close file))
    (princ))

  (setq i 0)
  
  (while (setq pnt (getpoint (strcat "\nPick a point no " (itoa (setq i (1+ i))) ": ")))
    (setq lst (cons (cons i pnt) lst)))

  (if (and lst
           (setq file (open (strcat (getvar 'DWGPREFIX) (vl-string-right-trim ".dwg" (getvar 'DWGNAME)) "-TxtExport.csv") "a"))
           (write-line "n,x,y,z" file)
           )
    (foreach e lst 
      (setq txt (strcat (itoa (car e))
                        ";"
                        (rtos (cadr e) 2 8)
                        ";"
                        (rtos (caddr e) 2 8)
                        ";"
                        (rtos (last e) 2 8)))
      (write-line txt file)))
  (*error* "end")
)
0 Likes
Message 3 of 7

miroslav.pristov
Advocate
Advocate

actually it wont work

 

i dont know how to stop choosing points. When i stop it by clicking enter or esc nothing happens. the CAD is just ready for new command

 

 

0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant
Accepted solution

Stop it usual way, hit enter. You can change this line....

 

(while (setq pnt (getpoint (strcat "\nPick a point no " (itoa (setq i (1+ i))) "<done>: ")))

 

It creates a csv at the place where is your dwg file saved.

I assumed that csv uses semicolons in your country, but change that to comma if I am wrong. - you'll find where.

0 Likes
Message 5 of 7

miroslav.pristov
Advocate
Advocate

it work just what i need but i have problem with excel file. nxyz are in diferent cells in first row and its ok, but values bellow are not. they are in form n;valuex;valuey;valuez in first cell of next row

 

i try to change ";" as you say to "," but nothing happens, everything the same. 

0 Likes
Message 6 of 7

miroslav.pristov
Advocate
Advocate

sorry my fault it works perfect i miss parenthesis

Message 7 of 7

ВeekeeCZ
Consultant
Consultant

Good you found it! Posting the final code for the record. I added one more thing to reverse the list to make it start from the beginning...

 

(defun c:Points2CSV ( / *error* file txt pnt lst i)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (if file (close file))
    (princ))

  (setq i 0)
  
  (while (setq pnt (getpoint (strcat "\nPick a point no " (itoa (setq i (1+ i))) " <done>: ")))
    (setq lst (cons (cons i pnt) lst)))

  (if (and lst
           (setq lst (reverse lst))
           (setq file (open (strcat (getvar 'DWGPREFIX) (vl-string-right-trim ".dwg" (getvar 'DWGNAME)) "-TxtExport.csv") "a"))
           (write-line "n,x,y,z" file)
           )
    (foreach e lst 
      (setq txt (strcat (itoa (car e))
                        ","
                        (rtos (cadr e) 2 8)
                        ","
                        (rtos (caddr e) 2 8)
                        ","
                        (rtos (last e) 2 8)))
      (write-line txt file)))
  (*error* "end")
)
0 Likes