+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 19
  1. #1
    Senior Member
    Using
    Map 3D 2007
    Join Date
    May 2011
    Location
    autocad
    Posts
    134

    Default Add list to existing list

    Registered forum members do not see this ad.

    Hi All,

    Please help me to solve this problem.
    I am trying to write a lisp routine in which it will read lines from txt file and go through the test expression and if it meets the condition it will add the lines to an existing list. Shown below is a part of the routine.

    Code:
    (setq lst '())
    (repeat (length Pdata)
      (setq Ppoint (nth cntr Pdata)
    	Vpoint (list (car Ppoint) (cadr Ppoint))
    	Xbat (caddr Ppoint))
    	  (setq chkoffst
    	       (distance (vlax-curve-getClosestPointTo Kproute Vpoint)
    			 Vpoint
    	       )
    	)
    	  (if (<= chkoffst gap)
    	    (setq batlst (append (list (car Vpoint) (cadr Vpoint) Xbat) lst)))
      (setq cntr (1+ cntr)))
    Am i doing it correctly or missing something. I am asking this because I know there should be more than 10 lines which should be added to new list but it contains only one. How?

    Thanks and Regards
    Aaryan

  2. #2
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,000

    Default

    Please pay attention to variables names:
    Code:
    (setq batlst '()
    ...
    (setq batlst (append (list (list (car Vpoint) (cadr Vpoint) Xbat)) batlst))
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  3. #3
    Senior Member
    Using
    Map 3D 2007
    Join Date
    May 2011
    Location
    autocad
    Posts
    134

    Default

    Thank You So much Mircea

  4. #4
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,000

    Default

    You're welcome, Aaryan!
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  5. #5
    Senior Member
    Using
    Map 3D 2007
    Join Date
    May 2011
    Location
    autocad
    Posts
    134

    Default

    Sorry Mircea I am back again with almost same problem. Am I missing something here because I am getting all list as nil.
    My file is something like this
    500,200,23.5,H1
    200,220,23.4,H2
    500,150,22.8,H3
    450,250,21.9,H4
    400,300,22.2,H5
    600,400,23.3,H6

    Please Reply.

    Code:
    (setq   Ref1lst '()
      	Ref2lst '()
      	Ref3lst '()
      	Ref4lst '()
      	Ref5lst '()
      	Ref6lst '())
      (repeat (length SBPdata)
      (setq SBPpoint (nth contr SBPdata);Easting, Northing and Elevation
    	SVPpoint (list (car SBPpoint) (cadr SBPpoint));Easting and Northing
    	SBPbat (caddr SBPpoint);Elevation
    	Reflect (cadddr SBPpoint);could be anyone from H1, H2, H3, H4, H5 ,H6
    	counter 0)
    (if (= Reflect "H1")
      (setq Ref1lst (append (list SBPpoint) Ref1lst)))
    (if (= Reflect "H2")
      (setq Ref2lst (append (list SBPpoint) Ref2lst)))
    (if (= Reflect "H3")
      (setq Ref3lst (append (list SBPpoint) Ref3lst)))
    (if (= Reflect "H4")
      (setq Ref4lst (append (list SBPpoint) Ref4lst)))
    (if (= Reflect "H5")
      (setq Ref5lst (append (list SBPpoint) Ref5lst)))
    (if (= Reflect "H6")
      (setq Ref6lst (append (list SBPpoint) Ref6lst)))
    (setq contr (1+ contr)))
    Regards
    Aaryan

  6. #6
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,000

    Default

    Again, please pay attention to the names of variables. Second, the counter should be defined when you use it, and also should be initiated outside cycle. If initiated inside cycle it will be reset each time and only the first item from list will be evaluated.
    Code:
    (setq counter 0)
    (repeat (length SBPdata)
      (setq SBPpoint (nth counter SBPdata);Easting, Northing and Elevation
     SVPpoint (list (car SBPpoint) (cadr SBPpoint));Easting and Northing
     SBPbat (caddr SBPpoint);Elevation
     Reflect (cadddr SBPpoint));could be anyone from H1, H2, H3, H4, H5 ,H6
     
    (if (= Reflect "H1")
      (setq Ref1lst (append (list SBPpoint) Ref1lst)))
    (if (= Reflect "H2")
      (setq Ref2lst (append (list SBPpoint) Ref2lst)))
    (if (= Reflect "H3")
      (setq Ref3lst (append (list SBPpoint) Ref3lst)))
    (if (= Reflect "H4")
      (setq Ref4lst (append (list SBPpoint) Ref4lst)))
    (if (= Reflect "H5")
      (setq Ref5lst (append (list SBPpoint) Ref5lst)))
    (if (= Reflect "H6")
      (setq Ref6lst (append (list SBPpoint) Ref6lst)))
    (setq counter (1+ counter)))
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  7. #7
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows XP
    Discipline
    Construction
    pBe's Discipline Details
    Discipline
    Construction
    Details
    Camp Construction planning and details
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Posts
    2,106

    Default

    Code:
    (setq SBPdata  '("500,200,23.5,H1"
                    "200,220,23.4,H2"
                    "500,150,22.8,H3"
                    "450,250,21.9,H4"
                    "400,300,22.2,H5"
                    "600,400,23.3,H6")
          Data    '((H1 "Ref1lst")
                    (H2 "Ref2lst")
                    (H3 "Ref3lst")
                    (H4 "Ref4lst")
                    (H5 "Ref5lst")
                    (H6 "Ref6lst")))
     
         (foreach
                 itm
                    SBPdata
                (if (setq fle (assoc (last
                                           (setq lst  (read (strcat
                                                                  "("
                                                                  (vl-string-translate "," " " itm)
                                                                  ")"))))
                                     Data))
                      (set (read (cadr fle))
                           (cons (list (car lst) (cadr lst))
                                 (eval (read (cadr fle)))
                                 ))))
    EDIT: includes building the point lis
    Last edited by pBe; 10th Jul 2012 at 07:57 am.

  8. #8
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,000

    Default

    Aaryan, you may optimize a little the above code:
    Code:
    (setq   Ref1lst '()
       Ref2lst '()
       Ref3lst '()
       Ref4lst '()
       Ref5lst '()
       Ref6lst '())
    (foreach SBPpoint SBPdata
      (setq SVPpoint (list (car SBPpoint) 
                           (cadr SBPpoint))   ;Easting and Northing
            SBPbat   (caddr SBPpoint)         ;Elevation
            Reflect  (cadddr SBPpoint))       ;could be anyone from H1, H2, H3, H4, H5 ,H6
     
     (cond
      ((= Reflect "H1")
       (setq Ref1lst (append (list SBPpoint) Ref1lst)))
      ((= Reflect "H2")
       (setq Ref2lst (append (list SBPpoint) Ref2lst)))
      ((= Reflect "H3")
       (setq Ref3lst (append (list SBPpoint) Ref3lst)))
      ((= Reflect "H4")
       (setq Ref4lst (append (list SBPpoint) Ref4lst)))
      ((= Reflect "H5")
       (setq Ref5lst (append (list SBPpoint) Ref5lst)))
      ((= Reflect "H6")
       (setq Ref6lst (append (list SBPpoint) Ref6lst)))
     )
    )
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  9. #9
    Senior Member
    Using
    Map 3D 2007
    Join Date
    May 2011
    Location
    autocad
    Posts
    134

    Default

    Thanks You both for your efforts.

    Regards
    Aaryan

  10. #10
    Senior Member
    Using
    Map 3D 2007
    Join Date
    May 2011
    Location
    autocad
    Posts
    134

    Default

    Registered forum members do not see this ad.

    @pBe Please tell me how will i create a list which contains all H1, H2..seperately.

    @Mircea I am still getting an empty lists.

    Please help me as i am stuck only at this point.

    Code:
    (while  (setq  SBPinfo (read-line opnSBP))
      (setq SBPdata
                              (cons (read (strcat "(" (vl-string-translate
                                                        ","  " " SBPinfo)
                                                  ")"))
                                    SBPdata)))
          (close opnSBP)
    
          (setq counter 0)
      (setq Ref1lst '()
      	Ref2lst '()
      	Ref3lst '()
      	Ref4lst '()
      	Ref5lst '()
      	Ref6lst '())
    Below Your codes
    I actually need to create seperate lists which contains easting,northing,elevation,tag.
    eg. Ref1lst should contains (500 200 23.5 H1)
    Ref2lst should contains (600 300 23.4 H2)
    etc..

    Regards
    Aaryan

Similar Threads

  1. generate part-list/order-list in autocad 2011LT
    By Borken in forum AutoCAD Beginners' Area
    Replies: 7
    Last Post: 12th Jul 2012, 09:39 am
  2. Replies: 0
    Last Post: 23rd Nov 2011, 03:16 am
  3. AutoCAD - Update Sheet List Table and Edit Sheet List Table Settings
    By Between the Lines in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 8th Feb 2011, 12:30 am
  4. write a list into text file and return back as list
    By muthu123 in forum AutoLISP, Visual LISP & DCL
    Replies: 14
    Last Post: 21st Dec 2009, 04:31 pm
  5. Change popup list contents from one list to another
    By The Buzzard in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 4th Mar 2009, 05:22 am

Bookmarks

Posting Permissions

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