Jump to content
janwillem89

Lisp: coordinates of points to excel sheet (+point number)

Recommended Posts

leo321

coordanetes still fail

(defun c:pline-coor ( / *error* data-lst sorted-lst str-lst top-str polys
                                data cnt obj file-nm tmp item tmp-str fl)

 (defun *error* (msg)
   (if(= msg "quit / exit abort")
     (princ "\nNo output file was selected")
     (princ msg)
   )
 )
 
 (setq top-str ""
       file-nm (getfiled "Output File" "" "doc" 1)
 )
 (if(null file-nm)(exit))
 (if(setq polys(ssget '((0 . "*POLYLINE"))))
   (repeat(setq cnt(sslength polys))
     (setq obj      (vlax-ename->vla-object
                      (ssname polys 
                        (setq cnt(1- cnt))
                      )
                    )
           data-lst (cons
                      (list(vlax-get obj 'Layer) 
                      (vlax-get-property obj 'Coordinates) [color=red]THIS PART IS WORNG!![/color]
                      
                      )           
                      data-lst
                    ) 
     )
   )
 )
 (while data-lst
   (setq data     (car data-lst)
         data-lst (cdr data-lst)
         tmp      (list data)
   )
   (foreach item data-lst
     (if(=(car item)(car data))
       (setq tmp      (cons item tmp)
             data-lst (vl-remove item data-lst)
       )
     )
   )
   (setq sorted-lst(cons tmp sorted-lst))
 )
 (setq sorted-lst
   (vl-sort sorted-lst '(lambda(a b)(<(caar a)(caar b))))
 )
 (foreach item (reverse sorted-lst)
   (setq top-str
     (strcat(caar item)"," top-str)
   )
 )
 (setq str-lst (cons top-str str-lst)
       cnt     0
 )
 (repeat(apply 'max(mapcar 'length sorted-lst))
   (setq tmp-str "")
   (foreach item (reverse sorted-lst)
     (setq tmp-str
       (if(setq tmp(nth cnt item))
         (strcat(rtos(cadr tmp)) "," tmp-str)
         (strcat "," tmp-str)
       )
     )
   )
   (setq cnt     (1+ cnt)
         str-lst (cons tmp-str str-lst)
   )
 )
 (if(setq fl(open file-nm "w"))
   (progn
     (foreach str (reverse str-lst)
       (write-line str fl)
     )
     (close fl)
     (alert(strcat file-nm " was created"))
   )
   (alert "Unable to create file")
 )
 (princ)
) 						

Share this post


Link to post
Share on other sites
JoshKing

Thanks so much for this code VVA, absolutely brilliant. Now my question is whether anyone is able to rewrite this in Autocad VBA? I'm trying to learn VBA, and want to include this code as part of a routine.

 

Even if you have just a segment or two of this code written for VBA, I would appreciate it, as I'm trying to piece it all together. I have looked everywhere for examples on how to create polylines from any shape (circle, spline, ellipse, arc etc..), and/or divide shape boundaries into points as can easily be done with the divide command, but can't seem to find examples anywhere for VBA.

 

Likewise, it is difficult to find any info regarding how to simply select a shape and hatch it without having already created the shape with the code (typically storing X Y coordinate data in an array using methods like LWpolyline). Surely there must be a way to reverse this, by turn any existing closed shape (drawn freehand) into a polyline, then extracting the coordinates to build an array (or arrays for multiple shapes) and then hatch them using VBA.

 

Again any help would be great.

Thanks,

Josh

Share this post


Link to post
Share on other sites
ajazraj

thanks a lot...

 

>janwillem89 Try it

If something will be not clear, I shall try to comment later.

In the text in the basic comment in Russian. It is possible to take advantage Online translator: http://www.online-translator.com/Default.aspx?prmtlang=en

 

Export of coordinates of the specified points, the chosen objects: points, blocks, polylines, splines in a text file or Excel.

Text file — txt, or csv.

A rounding off of coordinates according to current adjustments of a command _UNITS (LUPREC system variable)

 

3 commands Are certain

COOR - export of coordinates

COORN-export of coordinates with numbering. Numbers of points are drawn by the text on the current layer, the current style, current height (TEXTSIZE)

COORT-export of coordinates with numbering where number considers the text nearest to a point

New version see post #12

Share this post


Link to post
Share on other sites
leo321

other pretty good one

 

XY + layer name in excel each columm like a lot :):thumbsup::geek:

 


;; Polyline Vertex Exporter ~ by Lee McDonnell ~ 26.11.2009
(defun c:pExp2 (/ ss tmp i j ent tot dis pt)
(vl-load-com)
(if (and (setq ss (ssget '((0 . "*POLYLINE"))))
(setq tmp (getfiled "Output File" (cond (*load) ("")) "txt;csv" 9)))
(progn
(setq *load tmp tmp (open tmp "a") i -1)
(write-line "X,Y,Layer" tmp)
(while (setq ent (ssname ss (setq i (1+ i))))
(setq tot 0. j (1- (vlax-curve-getStartParam ent)))
(while (<= (setq j (1+ j)) (vlax-curve-getEndParam ent))
(setq pt (mapcar 'rtos (vlax-curve-getPointatParam ent j))) 
(write-line
(strcat (car pt) (chr 44) (cadr pt) (chr 44) (vla-get-layer (vlax-ename->vla-object ent)))
tmp))
(write-line "" tmp))
(close tmp)))
(princ))

Share this post


Link to post
Share on other sites
gS7

My Version ...

: Export Polyline Coordinates to CSV

:Ganesh Shetty 27.03.2013

(defun c:Pl_export(/ *error* file sset  ename lst)

    (vl-load-com)
    (defun *error* (s)
         (if file (close file))
         (cond
      ( ( not s ) )
      ( (member s '("Function cancelled" "quit / exit abort") ) )
      ( (princ (strcat "\n---->Error:" s) ) )
  )
      (princ))
      (if (setq sset (ssget "_:L" '((0 . "*POLYLINE"))))
   (progn
        (if (setq file (open (strcat (getvar 'dwgprefix) "Polyline Vertex List.csv") "w"))
     (progn
          (write-line (strcat "X" "," "Y" "," "Z" "," "Layer") file)
          (repeat (setq i (sslength sset))
        (setq ename (vlax-ename->vla-object (ssname sset (setq i (1- i)))))
 (setq layname (vla-get-layer ename))
        (setq lst (vlax-safearray->list
      (vlax-variant-value
        (vla-get-coordinates ename)
      )
    )
        )
        (repeat (/ (length lst) 3)
      (write-line (strcat (rtos (car lst)) "," (rtos (cadr lst)) "," (rtos (caddr lst)) "," layname) file)
      (setq lst (cdddr lst))
        )
   )
          (close file)
          (alert "\nVertex Points exported to csv file.")
          (alert (strcat "File saved in - "(getvar 'dwgprefix) "Polyline Vertex List.csv"))
     )
     (alert "\nCSV file Currenty running, Close it first.")
 )
    )
    (*error* "Nothing Selected.")
)
       (*error* nil)
       (princ)
)

Share this post


Link to post
Share on other sites
ajc

Is it possible to generate a line having x,y and radius....this is used for creating curved entities.

Thank you,

ACosme

Share this post


Link to post
Share on other sites
sshukoor

its amazing (coort) it saves almost 5hrs of my entire team

Share this post


Link to post
Share on other sites
pzr27

Question for VVA. I really liked your Coor.lsp Can you add a column for layer please?

Thanks

pzr27

Share this post


Link to post
Share on other sites
VVA

I do not understand what you need to add a column layer. Need more in detail and describe the problem and attach the example file

Share this post


Link to post
Share on other sites
pzr27

Need Header to read: X Y Z LayerName

If you could add in another column the dimension of the object, right of the layername COLUMN, THAT WOULD BE GREAT!

Appreciate your time!

pzr

Share this post


Link to post
Share on other sites
calion

sir vva

can u help me on how to encrypt my lisp file

thank's a lot sir

Share this post


Link to post
Share on other sites
frederick_1989

sir VVA

 

i really like your lips ECoorE rev6 from your post #12

can you please make some changes on the output like changing the X Y Z to Y X Z

and make the decimal point only good for 3

 

make it like this sir even in notepad and hvacrep

Picture1.png

Share this post


Link to post
Share on other sites
Snownut
sir VVA

 

i really like your lips ECoorE rev6 from your post #12

can you please make some changes on the output like changing the X Y Z to Y X Z

and make the decimal point only good for 3

 

make it like this sir even in notepad and hvacrep

This is not that difficult to achieve, you should be able to open the lsp file and make the necessary changes (re-order the write to file line by moving a couple of variables around).

 

This site is not a custom lisp order site, but contains training exercises....

Share this post


Link to post
Share on other sites
frederick_1989

im sorry, im no good at this but i already tried to change and failed, i already guess and change xyz to yxz but the point and text goes to reverse coordinates and cant follow the codes

 

can you help me please

Share this post


Link to post
Share on other sites
VVA

Export coordinates as XYZ and YXZ often used in geodesy. Added export coordinates as XYZ and YXZ, rounding.

Try ECoorE rev.9 from #12

Share this post


Link to post
Share on other sites
frederick_1989
Export coordinates as XYZ and YXZ often used in geodesy. Added export coordinates as XYZ and YXZ, rounding.

Try ECoorE rev.9 from #12

 

sir how can i change xyz to yxz? i type any posible word it says invalid option keyword and in coor it appears that the x coordinates goes to the column of n

Share this post


Link to post
Share on other sites
VVA

I added the "Settings" to the request "Save coordinates ..."

 

Save coordinates (type=YXZ round=LUPREC variable) to [Text file/Csv

file/Excel/Not save/Settings] : S

setting.png

Share this post


Link to post
Share on other sites
frederick_1989

sir VVA your really the best

but one more thing to make it perfect sir

in doing the Coor command, the coordinates/value of the following was in the other column, it appear like this

Picture1.png

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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