See the top rated post in this thread. Click here

Results 1 to 4 of 4

Thread: LISP routine skips line 1 of CSV

  1. #1
    Member
    Join Date
    2019-06
    Posts
    2
    Login to Give a bone
    0

    Default LISP routine skips line 1 of CSV

    I have a lisp routine that reads points from a CSV file and then adds a block at each point.
    The problem is that this routine keeps skipping the first line of the CSV file.
    Any idea what part of this code is doing that?
    Thank you.

    Code:
    (defun C:IMPNT2 (/ str:list read:block a b c cm d s)
      (defun str:list (str / b)
        (foreach x (reverse (vl-string->list str))
          (cond ((eq x 44) (setq b (cons (list x) b)))
    	    (t
    	     (if (not b)
    	       (setq b (cons (list x) b))
    	       (setq b (cons (cons x (car b)) (cdr b)))
    	     )
    	    )
          )
        )
        (mapcar '(lambda (x) (vl-list->string (vl-remove 44 x))) b)
      )
      (defun read:block (s / e f)
        (while (not f)
          (if (setq e (entsel s))
    	(cond
    	  ((wcmatch (cdr (assoc 0 (entget (car e)))) "INSERT")
    	   (setq f t)
    	  )
    	  (t (alert "Please select BLOCK object."))
    	)
    	(alert "Nothing selected, please try again.")
          )
        )
        (vlax-ename->vla-object (car e))
      )
      (if (not SR:PATH)
        (setq SR:PATH (getvar "dwgprefix"))
      )
      (if
        (and (setq
    	   a (getfiled "Select CSV File" SR:PATH "csv" 16)
    	 )
    	 (setq SR:PATH (strcat (vl-filename-directory a) ""))
    	 (setq a (open a))
    	 (setq c (while	(setq b (read-line a))
    		   (setq c (cons (str:list b) c))
    		 )
    	 )
    	 (setq s (read:block "\nSelect Source Block : "))
        )
         (progn
           (close a)
           (setq cm (getvar 'cmdecho))
           (setvar 'cmdecho 0)
           (setq d (ssadd))
           (foreach	x (cdr (reverse c))
    	 (if (and (> (length x) 1)
    		  (numberp (read (cadr x)))
    		  (numberp (read (caddr x)))
    		  (numberp (read (cadddr x)))
    		  (setq	bk (SR:INBLOCK
    			     (list (* (atof (cadr x)) 1000.)
    				   (* (atof (caddr x)) 1000.)
    				   (* (atof (cadddr x)) 1000.)
    			     )
    			     (vla-get-effectivename s)
    			     1
    			     1
    			     1
    			     0
    			   )
    		  )
    	     )
    	   (ssadd (vlax-vla-object->ename bk) d)
    	 )
           )
           (command "_.zoom" "_o" d "")
           (setvar 'cmdecho cm)
           (sssetfirst nil d)
         )
      )
      (princ)
    )
    (SETQ SR:ACAD  (VLAX-GET-ACAD-OBJECT)
          SR:ACDOC (VLA-GET-ACTIVEDOCUMENT SR:ACAD)
          SR:MODEL (VLA-GET-MODELSPACE SR:ACDOC)
    )
    (DEFUN SR:INBLOCK (POINT BLOCKNAME XSCALE YSCALE ZSCALE ROTATION)
      (VLA-INSERTBLOCK
        SR:MODEL
        (VLAX-3D-POINT POINT)
        BLOCKNAME
        XSCALE
        YSCALE
        ZSCALE
        ROTATION
      )
    )
    (VL-LOAD-COM)
    (PRINC)
    (PRINC
      (STRCAT
        "\n:: Import Point Data.lsp ::"
        "\n:: Created by Satish Rajdev | "
        (MENUCMD "M=$(edtime,$(getvar,date),DDDD"," D MONTH YYYY)"
        )
        " ::"
        "\n:: Type "IMPNT" to Import CSV ::"
      )
    )
    (PRINC)
    Last edited by Ed Jobe; 2019-06-04 at 03:27 PM. Reason: Added CODE tags

  2. #2
    Programming Moderator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,464
    Login to Give a bone
    0

    Default Re: LISP routine skips line 1 of CSV

    Consider your use of CDR here:

    Code:
    ;;<snip>
    
           (foreach	x (cdr (reverse c))
    
    ;;<snip>
    Last edited by BlackBox; 2019-06-04 at 07:05 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  3. #3
    Member
    Join Date
    2019-06
    Posts
    2
    Login to Give a bone
    0

    Default Re: LISP routine skips line 1 of CSV

    CDR is already in that line of code.
    Do you mean remove it??

  4. #4
    Programming Moderator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,464
    Login to Give a bone
    1

    Default Re: LISP routine skips line 1 of CSV

    Quote Originally Posted by mdumais24782845 View Post
    CDR is already in that line of code.
    Do you mean remove it??
    The top line of a CSV often represents the column headers only, so skipping the first line using CDR makes sense, if that is the format of your CSV files.

    However, you're wanting to include the first line of the CSV file you've selected, indicating that is not the format of the CSV file you're attempting to cull... Therefore consider your usage of CDR.

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

Similar Threads

  1. Lisp routine in a Lisp routine
    By jayhay35365091 in forum AutoLISP
    Replies: 8
    Last Post: 2013-10-09, 02:30 PM
  2. Run Lisp Routine From Another Lisp Routine
    By mwilson in forum AutoLISP
    Replies: 7
    Last Post: 2013-07-25, 02:46 PM
  3. 2011: Express Tools Auto Number - Skips Number in Multi-line Mtext
    By stusic in forum AutoCAD General
    Replies: 3
    Last Post: 2013-01-29, 02:38 PM
  4. Revision schedule skips a line
    By matt__w in forum Revit MEP - General
    Replies: 1
    Last Post: 2010-01-07, 04:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •