Jump to content

Import multiple unique blocks from csv


Robert89

Recommended Posts

I want to rewrite the code supplied by satishrajdev to this csv format that is very 'Qgis friendly'

 

blockatt;x;y; [hyperlink_name]

blockatt;x;y; [hyperlink_name]

blockatt;x;y; [hyperlink_name]

 

See attached csv sample

 

First i have indentify the fields in to code.

Than i can swap them..

 

 

locatie1.csv

fields in code.jpg

Edited by halam
Link to comment
Share on other sites

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • BIGAL

    7

  • Robert89

    7

  • pBe

    5

  • halam

    3

Top Posters In This Topic

Posted Images

I tried some few thing with it but in the end I decided to use the lisp pointsin.lsp coming from

http://www.hawsedc.com/gnu/pointsin.php

 

This code was more easy to tweak for my purposes.

Here it is, i turned it into GEFIN.lsp (GEF are dutch files for phrobing)

 

Maybe somebody can use this in the future 😉

 

;;; This is the AutoLISP source file for
;;; ============
;;; GEFIN.LSP
;;; ============
;;; for importing CSV data into AutoCAD
;;; original code manipulated by Hans Lammerts - for ABT The Netherlands
;;; 
;;; Every line that begins with a semi-colon (;) is a comment,
;;; not part of the program.
;;; Read the comments below to learn how to enable, disable,
;;; and change parts of the program.
;;;
;;; HOW TO ADD, CHANGE, OR REMOVE ATTRIBUTES FROM BLOCK OR FILE
;;; 1. Edit the GEFPOINT.DWG block to meet your needs.
;;; 2. Edit the list of TAGNAMES in the PI:GETPOINTFORMAT function to include all the block attributes you want to fill from your file.
;;; 3. Make sure there is a format in the PI:GETFORMAT function that includes all the block attributes you want to import from your file.
;;;   a. Edit the menu to describe your format correctly.
;;;   b. Edit the list of tag/field names for the appropriate option for your format.
;;;
;;; Copyright 2015 Thomas Gail Haws
;;; This program is free software under the terms of the
;;; GNU (GNU--acronym for Gnu's Not Unix--sounds like canoe)
;;; General Public License as published by the Free Software Foundation,
;;; version 2 of the License.
;;;
;;; You can redistribute this software for any fee or no fee and/or
;;; modify it in any way, but it and ANY MODIFICATIONS OR DERIVATIONS
;;; continue to be governed by the license, which protects the perpetual
;;; availability of the software for free distribution and modification.
;;;
;;; You CAN'T put this code into any proprietary package.  Read the license.
;;;
;;; If you improve this software, please make a revision submittal to the
;;; copyright owner at www.hawsedc.com.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License on the World Wide Web for more details.
;;;
;;; DESCRIPTION
;;;
;;; POINTSIN is a civil engineering and survey tool that reads point data
;;; (ID, North, East, Elevation, Description) from a file
;;; and inserts a 2D attributed Softdesk-style GEFPOINT block
;;; and a 3d point in AutoCAD for every point in the file.
;;;
;;; You can change the GEFPOINT block if you prefer.  The order and graphical arrangement
;;; of the attributes doesn't matter. The default POINT block attributes are one unit high.
;;; POINTSIN scales the POINT block to default annotative height
;;; (dimscale * dimtext), so the default GEFPOINT block will look as big as the current
;;; dimension text height.
;;;
;;; You can delete or comment out the lines that insert a 3d point or the GEFPOINT block.
;;; You can also comment out the lines that create and set layers.
;;;
;;; Revisions (latest first)
(setq *PI:VERSION* "1.0.15")
;;; 20060928  TGH  0.5 hr.  Fixed problem with comment handling.
;;; 20060915  TGH  2   hr.  Version 1.0PR released.
;;; 20060915  TGH  1   hr.  Added error trapper and comment delimeters.
;;; (ALERT "Please see the command line for notes about changing the behavior of POINTSIN.")


(Steal "Y:\\Constructies\\INFRA\\software\\GEF2CSV\\template-GEO-m.dwg" '(("Blocks" ("GEFPOINT"))))


(DEFUN
   PI:GETPOINTFORMAT ()
  ;; This function defines the rules for using file field values for GEFPOINT block 
  ;; coordinates (in the XYZNAMES list)
  ;; and attributes (in the TAGNAMES list).
  ;; Caution: The file format definitions in (PI:GETFILEFORMAT) use these same names to describe
  ;; the order of fields in the input file formats.
  ;; So you have to change both this function and that one when you change the attributes in GEFPOINT.DWG
  ;; ========================================================================
  ;; The XYZNAMES list names the file fields used for x, y, and z insertion point coordinates
  ;; They can have any names, but if you want to put them into an attribute of the block,
  ;; their names must match the attribute tag, which is given next in the attributes list.
  ;; If you don't want an insertion coordinate (like elevation/z) to come from the file,
  ;; just use nil, and a 0.0 value will be used.
  ;; '("XYZNAMES" xname yname zname)
  ;;(PROMPT "\nOption to fill in NORTH and EAST attributes is not active.  Search this text in the source code to change behavior.")
  (PROMPT "\nOption to fill in NORTH and EAST attributes is active.  Search this text in the source code to deactivate.")
  ;; Examples: 
  '(
    ;; This line tells POINTSIN to put all points (not 2D blocks) at their correct elevation.
    ("XYZNAMES" "X" "Y" "Z")
    ;; This line tells POINTSIN to put all points (not 2D blocks) at 0 elevation
    ;; '("XYZNAMES" "EAST" "NORTH" nil)
    ;; ========================================================================
    ;; The DESCNAME list names the point description (for use in constructing description-specific layer names)
    ;; If you don't have a description attribute and aren't using description-specific layer names, this is ignored.  Just leave it alone.
    ("DESCNAME" . "DESC")
    ;; ========================================================================
    ;; The TAGNAMES list tells POINTSIN which block attribute tags
    ;; need to receive the data in the file fields.
    ;; The order of the attribute fields in the list doesn't matter.
    ;; If any of the attributes are to receive coordinate values (x, y, or z),
    ;; the coordinate names in the XYZNAMES list must also match the attribute tag.
    ;; Examples:
    ;; This list tells POINTSIN to fill in the "POINT", "DESC", and "ELEV" attributes of each block insertion.
    ;;("TAGNAMES" "POINT" "DESC" "ELEV")
    ;; This list tells POINTSIN to fill in the "NORTH", "EAST", "POINT", "DESC", and "ELEV" attributes of each block insertion.
    ("TAGNAMES" "Y" "X" "POINT" "DESC" "Z")
   )
  ;; ========================================================================
)

(DEFUN
   PI:GETBLOCKLAYERFORMAT (POINTFORMAT / LAYERFORMATSTRING)
  ;; Set up the point block layer scheme.  
  ;; 1. If you want each block to go on a layer whose name includes the point description,
  ;; use the code "/d" where you want the point description included (NCS/AIA/US example on next line).
  ;;  (SETQ LAYERFORMATSTRING '("V-NODE-/d" "cyan"))(PROMPT "\nBlock layer names by description is activated.  All descriptions must be legal layer names.  Search this text in the source code to deactivate.")
  ;; 2. If you want all point blocks to be put on the same layer, take out the /d.
  (SETQ LAYERFORMATSTRING '("V-NODE-IMPT" "cyan"))(PROMPT "\nOption to put all point blocks on same layer is active.  Search this text in the source code to change behavior.")
  ;; 3. If you want all point blocks to be put on the current layer, comment out both lines above as well as the following line.
  (PI:LAYERPARSE LAYERFORMATSTRING)
)

(DEFUN
   PI:GETNODELAYERFORMAT (POINTFORMAT / LAYERFORMATSTRING)
  ;; Set up the point node layer scheme.  
  ;; 1. If you want each node to go on a layer whose name includes the point description,
  ;; use the code "/d" where you want the point description included (NCS/AIA/US example on next line).
  ;;  (SETQ LAYERFORMATSTRING '("V-NODE-3D~~-/d" "yellow"))(PROMPT "\nNode layer names by description is activated.  All descriptions must be legal layer names.  Search this text in the source code to deactivate.")
  ;; 2. If you want all point nodes to be put on the same layer, take out the /d.
  (SETQ LAYERFORMATSTRING '("V-NODE-3D~~-IMPT" "yellow"))
  ;; 3. If you want all point blocks to be put on the current layer, comment out both lines above as well as the following line.
  (PI:LAYERPARSE LAYERFORMATSTRING)
)

(DEFUN C:GEFIN () (PI:GEFIN))

(DEFUN
   PI:GEFIN (/ 3DPLAYERHASDESCRIPTION FILEFORMAT FNAME
                NODELAYERFORMAT PBLAYERHASDESCRIPTION
                POINTBLOCKLAYERFORMAT POINTFORMAT POINTSLIST
               )
  (PI:ERRORTRAP)
  (SETQ POINTFORMAT (PI:GETPOINTFORMAT))
  (SETQ FILEFORMAT (PI:GETFILEFORMAT))
  (SETQ FNAME (GETFILED "Points data file" (PI:GETDNPATH) "" 0))
  (SETQ POINTSLIST (PI:GETPOINTSLIST FNAME FILEFORMAT POINTFORMAT))
  ;; Insert point blocks.  Comment out the following line if you don't want point blocks.
  (PI:INSERTPOINTBLOCKS POINTSLIST POINTFORMAT)
  ;; Insert 3d points.  Comment out the following line if you don't want 3d points.
  ;; (PI:INSERT3DPOINTS POINTSLIST POINTFORMAT)(PROMPT "\nOption to insert AutoCAD Point objects is activated.  Search this text in the source code to deactivate.")
  (PI:ERRORRESTORE)
)

;; Command for a user to insert points into a drawing manually.
(DEFUN C:INSPT () (PI:USERINSERTPOINT))
(DEFUN
   PI:USERINSERTPOINT (/ 
                     INSPT POINTBLOCKLAYERFORMAT POINTFORMAT POINTLIST PTDESC PTDESC-DEFAULT PTZ PTZ-DEFAULT PTNUM PTNUM-DEFAULT)
  (SETQ POINTFORMAT (PI:GETPOINTFORMAT))
  (SETQ POINTBLOCKLAYERFORMAT (PI:GETBLOCKLAYERFORMAT POINTFORMAT))
  (SETQ INSPT (GETPOINT "\nInsertion Point : "))
  ;; Get point number
  (SETQ PTNUM-DEFAULT (1+ (PI:GETVAR "number")))
  (SETQ
    PTNUM
     (GETINT
       (STRCAT "\nNode number <" (ITOA PTNUM-DEFAULT) ">: ")
     )
  )
  (IF (NOT PTNUM)
    (SETQ PTNUM PTNUM-DEFAULT)
  )
  (PI:SETVAR "number" PTNUM)
  ;; Get point description
  (SETQ PTDESC-DEFAULT (PI:GETVAR "description"))
  (SETQ
    PTDESC
     (GETSTRING (STRCAT "\nDescription <" PTDESC-DEFAULT ">: "))
  )
  (IF (NOT PTDESC)
    (SETQ PTDESC PTDESC-DEFAULT)
  )
  (PI:SETVAR "description" PTDESC)
  ;; Get point elevation and store as a string
  (SETQ PTZ-DEFAULT (RTOS (CADDR INSPT) 2))
  (SETQ PTZ (GETREAL (STRCAT "\nElevation <" PTZ-DEFAULT ">: ")))
  (IF (NOT PTZ)
    (SETQ PTZ PTZ-DEFAULT)
    (SETQ PTZ (RTOS PTZ 2))
  )
  (PI:SETVAR "elevation" PTZ)
  ;; Insert a point block
  ;; The format of pointlist is defined in GETPOINTSLIST
  (SETQ
    POINTLIST
     (LIST
       ;; '(x y z)
       (LIST (CAR INSPT) (CADR INSPT) 0.0)
       ;;North string
       (RTOS (CADR INSPT) 2 2)
       ;;East string
       (RTOS (CAR INSPT) 2 2)
       (ITOA PTNUM)
       PTDESC
       PTZ
     )
  )
  (PI:INSERTPOINTBLOCK
    POINTLIST
    POINTFORMAT
    POINTBLOCKLAYERFORMAT
  )
)

;; Get a global setting for the current session
;; A common standard for global variables is encasement in *asterisks*
(DEFUN
   PI:GETVAR (VAR-NAME / PI:DEFAULTS)
  (SETQ
    PI:DEFAULTS
     '(("number" . 0)
       ("elevation" . "0.00")
       ("description" . "")
      )
  )
  ;;If the settings don't exist, create them.
  ;;This statement is our official definition of our settings and defaults
  (IF (NOT *PI:SETTINGS*)
    (SETQ *PI:SETTINGS* PI:DEFAULTS)
  )
  ;; Now that we know the settings exist, return the requested setting's current value or an error message.
  (COND
    ((CDR (ASSOC VAR-NAME *PI:SETTINGS*)))
    ((CDR (ASSOC VAR-NAME PI:DEFAULTS)))
    (T
     (ALERT
       (PRINC
         (STRCAT
           "\n\""
           VAR-NAME
           "\" isn't a known setting for the points application."
         )
       )
     )
     ""
    )
  )
)

;; Set a global setting for the current session
(DEFUN
   PI:SETVAR (VAR-NAME VAR-VAL)
  ;; Populate the settings list so it's complete and we know we are not setting an unknown (maverick) setting.
  (PI:GETVAR VAR-NAME)
  ;; Put the requested value in the settings list
  (SETQ
    *PI:SETTINGS*
     (SUBST
       (CONS VAR-NAME VAR-VAL)
       (ASSOC VAR-NAME *PI:SETTINGS*)
       *PI:SETTINGS*
     )
  )
)

(DEFUN
   PI:ERRORTRAP ()
  (SETQ
    *PI:OLDERROR* *ERROR*
    *ERROR* *PI:ERROR*
  )
)

(DEFUN
   *PI:ERROR* (MESSAGE)
  (COND
    ((/= MESSAGE "Function cancelled")
     (PRINC (STRCAT "\nTrapped error: " MESSAGE))
    )
  )
  (COMMAND)
  (IF (= (TYPE F1) (QUOTE FILE))
    (SETQ F1 (CLOSE F1))
  )
  (IF *PI:OLDERR*
    (SETQ
      *ERROR* *PI:OLDERR*
      *PI:OLDERR* NIL
    )
  )
  (PRINC)
)

(DEFUN
   PI:ERRORRESTORE ()
  (SETQ
    F1 NIL
    *ERROR* *PI:OLDERR*
    *PI:OLDERR* NIL
  )
)


(DEFUN
   PI:GETFILEFORMAT (/ STDCOMMENT OPTION)
  (TEXTPAGE)
  ;; Menu
  ;; Show the various formats
  (PROMPT
    "\nSelect a file format:
	4. Punt XY (comma delimited)
	5. Punt XY (tab delimited)
	6. Punt XY (white-space delimited)
	7. Punt XY (puntcomma delimited)
" )
  ;;Set the allowed inputs and get one from user.
  (INITGET "4 5 6 7")
  (SETQ OPTION (GETKWORD "\n\n4/5/6/7: "))
  ;; Define the various formats by calling out the fields in order,
  ;; then specifying the field delimiter and the comment delimiter(s)
  ;; The field delimiter is a one-character string.
  ;; The comment delimiter is an AutoCAD style wild card string
  (SETQ STDCOMMENT ":,`#,;,'")
  (COND
    ((= OPTION "1")
     (LIST
       (LIST "POINT" "Y" "X" "Z" "DESC")
       ","
       STDCOMMENT
     )
    )
    ((= OPTION "2")
     (LIST
       (LIST "POINT" "Y" "X" "Z" "DESC")
       "\t"
       STDCOMMENT
     )
    )
    ((= OPTION "3")
     (LIST
       (LIST "POINT" "Y" "X" "Z" "DESC")
       "W"
       STDCOMMENT
     )
    )
    ((= OPTION "4")
     (LIST
       (LIST "POINT" "X" "Y" "Z" "DESC")
       ","
       STDCOMMENT
     )
    )
    ((= OPTION "5")
     (LIST
       (LIST "POINT" "X" "Y" "Z" "DESC")
       "\t"
       STDCOMMENT
     )
    )
    ((= OPTION "6")
     (LIST
       (LIST "POINT" "X" "Y" "Z" "DESC")
       "W"
       STDCOMMENT
     )
    )
    ((= OPTION "7")
     (LIST
       (LIST "POINT" "X" "Y" "Z" "DESC")
       ";"
       STDCOMMENT
     )
    )
  )
)

;;; PI:LAYERPARSE
;;; Returns a LAYERLIST with the name (first element) parsed into
;;; part before /d and part after /d.  If no /d, returns only one element.
(DEFUN
   PI:LAYERPARSE
   (LAYERLIST / NAMELIST NAMESTRING GROWINGSTRING COUNTER)
  (SETQ
    NAMESTRING
     (CAR LAYERLIST)
    GROWINGSTRING ""
    COUNTER 0
  )
  (WHILE (< COUNTER (STRLEN NAMESTRING))
    (SETQ COUNTER (1+ COUNTER))
    (IF (= (STRCASE (SUBSTR NAMESTRING COUNTER 2)) "/D")
      (SETQ
        NAMELIST
         (CONS GROWINGSTRING NAMELIST)
        GROWINGSTRING ""
        COUNTER
         (1+ COUNTER)
      )
      (SETQ
        GROWINGSTRING
         (STRCAT
           GROWINGSTRING
           (SUBSTR NAMESTRING COUNTER 1)
         )
      )
    )
  )
  (CONS
    (REVERSE (CONS GROWINGSTRING NAMELIST))
    (CDR LAYERLIST)
  )
)

;;; PI:MAKELAYER
;;; Sets current layer.  Makes layer if required.
;;; The format of layerlist is '(([NAME BEFORE DESC] [NAME AFTER DESC OR NIL IF NOT USING DESC]) COLOR)
;;; The format of pointlist is '((XX YY) POINT DESC Z)
(DEFUN
   PI:MAKELAYER (LAYERFORMAT POINTLIST POINTFORMAT / DWGLAYER LAYERNAME
                 NAMELIST LAYERCOLOR
                )
  (COND
    (LAYERFORMAT
     (SETQ
       NAMELIST
        (CAR LAYERFORMAT)
       LAYERNAME
        (STRCAT
          (CAR NAMELIST)
          (IF (CADR NAMELIST)
            (STRCAT
              (NTH
                ;; Calculate the position of the description in the pointlist
                (LENGTH
                  (MEMBER
                    ;; Name of point description
                    (CDR (ASSOC "DESCNAME" POINTFORMAT))
                    (REVERSE
                      (CDR (ASSOC "TAGNAMES" POINTFORMAT))
                    )
                  )
                )
                POINTLIST
              )
              (CADR NAMELIST)
            )
            ""
          )
        )
       LAYERCOLOR
        (CADR LAYERFORMAT)
     )
     (COND
       ((AND
          ;; Layer exists in drawing
          (SETQ DWGLAYER (TBLSEARCH "LAYER" LAYERNAME))
          ;; Layer is already proper color
          (= (CDR (ASSOC 62 DWGLAYER)) (CADR LAYERFORMAT))
          ;; Layer isn't frozen
          (/= 1 (LOGAND (CDR (ASSOC 70 DWGLAYER)) 1))
        )
        ;; Set that layer current without using command interpreter
        (SETVAR "CLAYER" LAYERNAME)
       )
       (T
        ;; Else make layer using (command)
        (COMMAND
          "._layer" "_thaw" LAYERNAME "_make" LAYERNAME "_on" ""
          "_color" LAYERCOLOR "" ""
         )
       )
     )
    )
  )
)

;; Format of list for each point is:
;; The first member is the point list (list x y z)
;; The other members are attribute value strings as defined by the GETPOINTFORMAT function
(DEFUN
   PI:GETPOINTSLIST (FNAME FILEFORMAT POINTFORMAT / ATTVALUES COORD
                     FIELDNAME I INSPOINT POINTLIST POINTSLIST RDLIN
                    )
  (SETQ F1 (OPEN FNAME "r"))
  (WHILE (SETQ RDLIN (READ-LINE F1))
    (SETQ
      I 0
      POINTLIST NIL
    )
    ;;Create a point list for the line if it's not a comment.
    (COND
      ((NOT (WCMATCH (SUBSTR RDLIN 1 1) (CADDR FILEFORMAT)))
       ;; Read and label the fields in the order specified by FILEFORMAT
       (FOREACH
          FIELD (CAR FILEFORMAT)
         (SETQ I (1+ I))
         (SETQ
           POINTLIST
            (CONS
              (CONS
                FIELD
                (PI:RDFLD I RDLIN (CADR FILEFORMAT) 1)
              )
              POINTLIST
            )
         )
       )
       ;; Strip the labels from the fields and put them into internal order
       ;; specified by POINTFORMAT.
       (SETQ
         ;; Get insertion coordinates
         INSPOINT
          (MAPCAR
            '(LAMBDA (FIELDNAME / COORD)
               (COND
                 ((AND
                    ;; If the coordinate is defined
                    (SETQ
                      COORD
                       (CDR (ASSOC FIELDNAME POINTLIST))
                    )
                    ;; and if the file gave a value
                    (SETQ COORD (DISTOF COORD))
                  )
                  ;; use it.
                  COORD
                 )
                 ;; Use 0.0 for any missing or undefined coordinates.
                 (0.0)
               )
             )
            (CDR (ASSOC "XYZNAMES" POINTFORMAT))
          )
         ;; Get attribute values.
         ATTVALUES
          (MAPCAR
            '(LAMBDA (FIELDNAME / COORD)
               (CDR (ASSOC FIELDNAME POINTLIST))
             )
            (CDR (ASSOC "TAGNAMES" POINTFORMAT))
          )
       )
       ;; Add point to list.
       (SETQ POINTSLIST (CONS (CONS INSPOINT ATTVALUES) POINTSLIST))
      )
    )
  )
  (SETQ F1 (CLOSE F1))
  POINTSLIST
)

(DEFUN
   PI:INSERTPOINTBLOCKS
   (POINTSLIST POINTFORMAT / AROLD POINTBLOCKLAYERFORMAT)
  (SETQ POINTBLOCKLAYERFORMAT (PI:GETBLOCKLAYERFORMAT POINTFORMAT))
  (COMMAND "._undo" "_group")
  (SETQ AROLD (GETVAR "attreq"))
  (SETVAR "attreq" 0)
  ;;Insert a Softdesk style block
  (FOREACH
     ;; The format of pointlist is defined in GETPOINTSLIST
     POINTLIST POINTSLIST
    (PI:INSERTPOINTBLOCK
      POINTLIST
      POINTFORMAT
      POINTBLOCKLAYERFORMAT
    )
  )
  (SETVAR "attreq" AROLD)
  (COMMAND "._undo" "_end")
)

(DEFUN
   PI:INSERTPOINTBLOCK (POINTLIST POINTFORMAT POINTBLOCKLAYERFORMAT / AT
                        AV EL EN ET N NEWVALUE SHORTLIST
                       )
  (PI:MAKELAYER POINTBLOCKLAYERFORMAT POINTLIST POINTFORMAT)
  (COMMAND
    "._insert"
    "GEFPOINT"
    "_none"
    ;; Chop off the z coordinate for 2D block insertion.
    (REVERSE (CDR (REVERSE (CAR POINTLIST))))
    ;; Or keep the z coordinate for 3D block insertion.
    ;;(CAR POINTLIST)
    "" ; (* (GETVAR "dimscale") (GETVAR "dimtxt")) ; weglaten , annoscale gebruiken
    ""
    "0"
  )
  (SETQ EN (ENTLAST))
  ;;Fill in attributes
  (WHILE (AND
           (SETQ EN (ENTNEXT EN))
           (/= "SEQEND"
               (SETQ ET (CDR (ASSOC 0 (SETQ EL (ENTGET EN)))))
           ) ;_ end of /=
         ) ;_ end of and
    (COND
      ((= ET "ATTRIB")
       (SETQ
         AT (CDR (ASSOC 2 EL))
         AV (CDR (ASSOC 1 EL))
       ) ;_ end of setq
       (COND
         ((SETQ
            SHORTLIST
             (MEMBER
               AT
               (REVERSE (CDR (ASSOC "TAGNAMES" POINTFORMAT)))
             )
          )
          (SETQ
            N (LENGTH SHORTLIST)
            NEWVALUE (NTH N POINTLIST)
          )
          ;; Round elevation attribute to current drawing LUPREC value
          ;;(IF
          ;;  (= AT "Z")
          ;;  (SETQ NEWVALUE (RTOS (ATOF NEWVALUE) 2))
          ;;)
          (ENTMOD
            (SUBST (CONS 1 NEWVALUE) (ASSOC 1 EL) EL) ;_ end of SUBST
          ) ;_ end of ENTMOD
         )
       ) ;_ end of cond
       (ENTUPD EN)
      )
    ) ;_ end of cond
  ) ;_ end of while
)
(DEFUN
   PI:INSERT3DPOINTS
   (POINTSLIST POINTFORMAT / NODELAYERFORMAT POINTLIST)
  (SETQ NODELAYERFORMAT (PI:GETNODELAYERFORMAT POINTFORMAT))
  (COMMAND "._undo" "_group")
  (FOREACH
     POINTLIST POINTSLIST
    (PI:MAKELAYER NODELAYERFORMAT POINTLIST POINTFORMAT)
    (COMMAND "._point" (CAR POINTLIST))
  )
  (COMMAND "._undo" "_end")
)

;;Read fields from a text string delimited by a field width or a delimiter
;;character.
;;Usage: (PI:RDFLD
;;         [field number]
;;         [string containing fields]
;;         [uniform field width, field delimiter character, or "W" for words separated by one or more spaces]
;;         [sum of options: 1 (non-numerical character field)
;;                          2 (unlimited length field at end of string)
;;         ]
;;       )
(DEFUN
   PI:RDFLD (FLDNO STRING FLDWID OPT / ISCHR ISLONG I J ATOMX CHAR
             CHARPREV LITERAL FIRSTQUOTE
            )
  (SETQ
    ISCHR
     (= 1 (LOGAND 1 OPT))
    ISLONG
     (= 2 (LOGAND 2 OPT))
  ) ;_ end of setq
  (COND
    ((= FLDWID "W")
     (SETQ
       I 0
       J 0
       ATOMX ""
       CHAR " "
     ) ;_ end of setq
     (WHILE (AND (/= I FLDNO) (< J (STRLEN STRING))) ;_ end of and
       ;;Save previous character unless it was literal
       (SETQ
         CHARPREV
          (IF LITERAL
            ""
            CHAR
          ) ;_ end of IF
         ;;Get new character
         CHAR
          (SUBSTR STRING (SETQ J (1+ J)) 1)
       ) ;_ end of setq
       ;;Find if new character is literal or a doublequote
       (COND
         ((= CHAR (SUBSTR STRING J 1) "\"")
          (IF (NOT LITERAL)
            (SETQ LITERAL T)
            (SETQ LITERAL NIL)
          ) ;_ end of if
          (IF (NOT FIRSTQUOTE)
            (SETQ FIRSTQUOTE T)
            (SETQ FIRSTQUOTE NIL)
          ) ;_ end of if
         )
         (T (SETQ FIRSTQUOTE NIL))
       ) ;_ end of cond
       (IF (AND
             (WCMATCH CHARPREV " ,\t")
             (NOT (WCMATCH CHAR " ,\t,\n"))
           )
         (SETQ I (1+ I))
       ) ;_ end of if
     ) ;_ end of while
     (WHILE (AND
              (OR ISLONG LITERAL (NOT (WCMATCH CHAR " ,\t,\n"))) ;_ end of or
              (<= J (STRLEN STRING))
            ) ;_ end of and
       (IF (NOT FIRSTQUOTE)
         (SETQ ATOMX (STRCAT ATOMX CHAR))
       ) ;_ end of if
       (SETQ CHAR (SUBSTR STRING (SETQ J (1+ J)) 1))
       (COND
         ((= CHAR "\"")
          (IF (NOT LITERAL)
            (SETQ LITERAL T)
            (SETQ LITERAL NIL)
          ) ;_ end of if
          (IF (NOT FIRSTQUOTE)
            (SETQ FIRSTQUOTE T)
            (SETQ FIRSTQUOTE NIL)
          ) ;_ end of if
         )
         (T (SETQ FIRSTQUOTE NIL))
       ) ;_ end of cond
     ) ;_ end of while
    )
    ((= (TYPE FLDWID) 'STR)
     (SETQ
       I 1
       J 0
       ATOMX ""
     ) ;_ end of setq
     (WHILE (AND
              (/= I FLDNO)
              (IF (> (SETQ J (1+ J)) 1000)
                (PROMPT (STRCAT "\nFields or delimiters missing in this line?" STRING))
                T
              ) ;_ end of if
            ) ;_ end of and
       (IF (= (SETQ CHAR (SUBSTR STRING J 1)) "\"")
         (IF (NOT LITERAL)
           (SETQ LITERAL T)
           (SETQ LITERAL NIL)
         ) ;_ end of if
       ) ;_ end of if
       (IF (AND (NOT LITERAL) (= (SUBSTR STRING J 1) FLDWID))
         (SETQ I (1+ I))
       ) ;_ end of if
     ) ;_ end of while
     (WHILE
       (AND
         (OR (/= (SETQ CHAR (SUBSTR STRING (SETQ J (1+ J)) 1)) FLDWID)
             LITERAL
         ) ;_ end of or
         (<= J (STRLEN STRING))
       ) ;_ end of and
        (COND
          ((= CHAR "\"")
           (IF (NOT LITERAL)
             (SETQ LITERAL T)
             (SETQ LITERAL NIL)
           ) ;_ end of if
           (IF (NOT FIRSTQUOTE)
             (SETQ FIRSTQUOTE T)
             (SETQ FIRSTQUOTE NIL)
           ) ;_ end of if
          )
          (T (SETQ FIRSTQUOTE NIL))
        ) ;_ end of cond
        (IF (NOT FIRSTQUOTE)
          (SETQ ATOMX (STRCAT ATOMX CHAR))
        ) ;_ end of if
     ) ;_ end of while
     (IF (AND ISCHR (NOT ISLONG))
       (SETQ ATOMX (PI:RDFLD-UNPAD ATOMX))
     )
    )
    (T
     (SETQ
       ATOMX
        (SUBSTR
          STRING
          (1+ (* (1- FLDNO) FLDWID))
          (IF ISLONG
            1000
            FLDWID
          ) ;_ end of if
        ) ;_ end of substr
     ) ;_ end of setq
     (IF (AND ISCHR (NOT ISLONG))
       (SETQ ATOMX (PI:RDFLD-UNPAD ATOMX))
     )
    )
  ) ;_ end of cond
  (SETQ
    ATOMX
     (IF ISCHR
       ATOMX
       (DISTOF ATOMX)
     ) ;_ end of if
  ) ;_ end of setq
) ;_ end of defun

;;Strip white space from beginning and end of a string
(DEFUN
   PI:RDFLD-UNPAD (STR)
  (WHILE (WCMATCH (SUBSTR STR 1 1) " ,\t")
    (SETQ STR (SUBSTR STR 2))
  ) ;_ end of while
  (IF (/= STR "")
    (WHILE (WCMATCH (SUBSTR STR (STRLEN STR)) " ,\t")
      (SETQ STR (SUBSTR STR 1 (1- (STRLEN STR))))
    ) ;_ end of while
  )
  STR
)


(DEFUN
   PI:GETDNPATH (/ DNPATH)
  (SETQ DNPATH (GETVAR "dwgname")) ;_ end of setq
  (IF (WCMATCH (STRCASE DNPATH) "*`.DWG")
    (SETQ
      DNPATH
       (STRCAT (GETVAR "dwgprefix") DNPATH)
      DNPATH
       (SUBSTR DNPATH 1 (- (STRLEN DNPATH) 4))
    ) ;_ end of setq
  ) ;_ end of if
  DNPATH
) ;_ end of defun



;(princ (strcat "\nLoaded POINTSIN.LSP version " *PI:VERSION* "."))
;|«Visual LISP© Format Options»
(72 2 40 2 nil "end of " 60 2 2 2 1 nil nil nil T)
;*** DO NOT add text below the comment! ***|;

 

 

 

block to use.dwg

BRO locaties.csv

101.gef

Edited by halam
Link to comment
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
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...