Exporting points or block to Excel

 Does anyone have a lisp that can export points or blocks to a excel spreadsheet? All I need is a list of X, Y, Z coordinates.

Comments

  • Hi James,

    perhaps this will help to get you started. The following function will return a list of 3D coords for the selected object (assuming it meets requirements):
    [code];------------------------------------------------------------------------------
    ; Copyright (C) 2012 CAD Concepts Limited.
    ;
    ; CCL:LISTCOORDS
    ;
    ; This work by CAD Concepts Ltd is licensed under a Creative Commons
    ; Attribution-ShareAlike 3.0 Unported License. Refer the following link:
    ; http://creativecommons.org/licenses/by-sa/3.0/nz/deed.en
    ; For options available to you under this license.
    ;
    ; PURPOSE
    ; Returns a list of 3D coordinates for a given entity
    ; Polylines returns a list with a point for each coordinate
    ; Lightweight Polylines uses the elevation for Z coordinate
    ; Closed polylines will have the start point appended to the end of the list
    ; all other objects checks whether a start and end point is available and returns a list of these points if available
    ;
    ; EXAMPLE
    ; (CCL:LISTCOORDS (car (entsel "\nSelect object (Polyline, Line) to return coords of:\n")))
    ; Select a 50 x 30 rectangular polyline shape drawn from 0,0
    ; if CLOSED returns something like
    ; ((0.0 0.0 0.0) (50.0 0.0 0.0) (50.0 30.0 0.0) (0.0 30.0 0.0) (0.0 0.0 0.0))
    ; if OPEN returns something like
    ; ((0.0 0.0 0.0) (50.0 0.0 0.0) (50.0 30.0 0.0) (0.0 30.0 0.0))
    ;
    ; This software is provided "as is". No liability is taken of
    ; FITNESS FOR ANY PARTICULAR PURPOSE.
    ;------------------------------------------------------------------------------


    (defun CCL:LISTCOORDS (ent / obj objtype objcoords coorList coordtype elevation numcoords num xval yval zval pointlst)
        ; Using visual lisp. Make sure the visual lisp extensions are available
        (vl-load-com) ; this isn't required by BricsCAD
        (setq obj (vlax-ename->vla-object ent)) ; convert to vl object
        (setq objType (vlax-get-property obj 'ObjectName)) ; find what type of object it is
        (cond
            ; CONDITION 1
            ; Object is a Lightweight, 2d, or 3d Polyline
            ; return a list of the coordinates
            ((or (= objtype "AcDbPolyline") (= objtype "AcDb2dPolyline") (= objtype "AcDb3dPolyline"))
                (setq objcoords (vla-get-coordinates obj)) ; retrieve the Coordinates
                ; (setq objcoords (vlax-get-property obj 'coordinates); Alternative method to retrieve these properties
                (setq coordList (vlax-safearray->list (vlax-variant-value objcoords))) ; convert coordinates from an array to a list
                (if    (= objtype "AcDbPolyline") ; If the object is a Lightweight Polyline
                        (setq
                            coordtype 2 ; THEN set number of coordinates to 2
                            elevation (vlax-get-property obj 'Elevation) ; and find the Polylines Elevation
                        )
                        (setq coordtype 3) ; ELSE set number of coordinates to 3
                ); end if
                (setq numcoords (/ (length CoordList) coordtype)) ; calculate the number off coordinates in the list
                ;(princ (strcat "\nNumber coords " (itoa numcoords) "\n"))
                (setq num 0); zero counter
                (repeat numcoords
                    (setq xval (nth num coordlist)) ; Get the X value
                    (setq num (1+ num)); Iterate counter to the Y value
                    (setq yval (nth num coordlist)) ; Get the Y value
                    (if (= coordtype 2) ; if this is a 2D coordinate list
                        (setq zval elevation) ; then set the Z to the given elevation
                        (setq num (1+ num) ; otherwise iterate the counter and get the Z from the coordinate list
                              zval (nth num coordlist)
                        )
                    )
                    (setq pointlst (cons (list xval yval zval) pointlst)) ; THEN add it to our points list
                (setq num (1+ num)); Iterate counter to the next X Value
                ); end Repeat
                (setq pointlst (reverse pointlst)) ; reverse our list
                (if (= ':VLAX-TRUE (vlax-get-property obj 'Closed)) ; If the polyline is closed
                    (setq pointlst (append pointlst (list (car pointlst)))) ; Then add the start point to the end of the list
                ); end if
            ) ; end CONDITION 1
            ; CONDITION 2
            ; For all other objects
            ; return a list of the start & end point if available
            (T
                (if (and (vlax-property-available-p obj 'StartPoint)(vlax-property-available-p obj 'EndPoint)) ; check if the object has a start point & end point
                    (setq pointlst
                        (mapcar
                            (function
                                (lambda (objPoint)
                                    (vlax-safearray->list (vlax-variant-value objPoint)) ; convert the point from an array to a list
                                )
                            )
                            (list (vlax-get-property obj 'StartPoint)(vlax-get-property obj 'EndPoint)) ; create a list of the two points
                        ) ;end mapcar
                    )
                ); end if
            ); end CONDITION 2
        ); end COND Statement
    ; return the points list
    pointlst
    ); end CCL:LISTCOORDS[/code]

    You could use the above to collect points for Polylines & Lines. Just need to create something to write it out to file, or send straight to excel.

    For blocks you can use the rather dated _ATTEXT command. Kinda clunky, but it works.

    Regards,

    Jason Bourhill

    CAD Concepts

    ccl-listcoords.lsp

  •  Awesome, thanks Jason.
  • Lee Mac has a function called PtManager that does just what you are looking for.  You may have to tweek it, to get it to run in Bricscad but it is a great utility.

    Google LeeMac Programming, he has about 100 utilities on his website fro free.

    Bruce
This discussion has been closed.