+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Full Member
    Using
    AutoCAD 2008
    Join Date
    Jan 2009
    Posts
    31

    Default The simplest things seem to get me stuck..

    Registered forum members do not see this ad.

    I have a list, and I am trying to loop trough the list, change each string in the list and add the new string to a new list. I cant get the result to the bottom or the top of the list. It seems like whatever I try it creates a 2 item list, the first item is the last edited string, and the last item is a string of every other previously altered string. How do I get it to put a new line on the string? I have tried append, multiple variations of cons and everything else I can find. I know this is really simple but for some reason, I seem to get hung up on the easy things.

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,709

    Default

    Not sure exactly what you are trying to do (a piece of sample code would help), but I would just use "cons" to put the new string in a list:

    Code:
    (setq strlst (cons *newstring* strlst))
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  3. #3
    Full Member
    Using
    AutoCAD 2008
    Join Date
    Jan 2009
    Posts
    31

    Default

    Thanks for the help Lee.
    I had been trying this and all sorts of variations with CONS but it still isnt creating my list in the desired format.
    Here is a sample

    (setq user (dos_username))
    (cond ((= user "BLockhart")
    (setq userp "Ben"))
    ((= user "CBearden")
    (setq userp "Chris"))
    ((= user "LBrown")
    (setq userp "Lavon"))
    ((= user "RChambers")
    (setq userp "Ronnie"))
    ((= user "JMitchell")
    (setq userp "Justin"))
    ((= user "JPrice")
    (setq userp "Joe"))
    ((= user "LCooper")
    (setq userp "Lonny"))
    (setq userp (getstring "\n Please enter your first name: "))
    );cond end
    (setq maindir (dos_getdir "Select directory you wish to print:" (strcat "W:\\"userp"\\New Projects")))
    (setq sublist (dos_subdir maindir))
    (setq subnum (length sublist))
    (setq cnt 0)
    (setq dwglist "")
    (while (< cnt subnum)
    (setq fldr (nth cnt sublist))
    (setq dwglist (cons (strcat maindir fldr) dwglist))
    (setq cnt (+ cnt 1))
    )
    )
    This somewhat works, but my list comes out looking like this.

    LOG ("W:\\Ben\\New Projects\\Solvay\\test\\109487" "W:\\Ben\\New Projects\\Solvay\\test\\109478" "W:\\Ben\\New Projects\\Solvay\\test\\109476" "W:\\Ben\\New Projects\\Solvay\\test\\109455" "W:\\Ben\\New Projects\\Solvay\\test\\109452" "W:\\Ben\\New Project...
    [car] "W:\\Ben\\New Projects\\Solvay\\test\\109487"
    [cdr] ("W:\\Ben\\New Projects\\Solvay\\test\\109478" "W:\\Ben\\New Projects\\Solvay\\test\\109476" "W:\\Ben\\New Projects\\Solvay\\test\\109455" "W:\\Ben\\New Projects\\Solvay\\test\\109452" "W:\\Ben\\New Projects\\Solvay\\test\\109438" "W:\\Ben\\New Project...
    Like I said, I know there is something amazingly simple I am missing, but it's driving me batty

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,709

    Default

    I can't really test it because it uses those "dos" functions... but give this a shot:

    Code:
    (setq user (dos_username))
          (cond     ((= user "BLockhart")
                 (setq userp "Ben"))
            ((= user "CBearden")
                 (setq userp "Chris"))
            ((= user "LBrown")
                 (setq userp "Lavon"))
            ((= user "RChambers")
                 (setq userp "Ronnie"))
            ((= user "JMitchell")
                 (setq userp "Justin"))
            ((= user "JPrice")
                 (setq userp "Joe"))
            ((= user "LCooper")
                 (setq userp "Lonny"))      
        (setq userp (getstring "\n Please enter your first name: "))
        );cond end
          (setq maindir (dos_getdir "Select directory you wish to print:" (strcat "W:\\"userp"\\New Projects")))
        (setq sublist (dos_subdir maindir) subnum (length sublist) cnt 0)
          (while (< cnt subnum)
              (setq fldr (nth cnt sublist))
              (setq dwglist (cons (strcat maindir fldr) dwglist) cnt (+ cnt 1))
          )
      )
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  5. #5
    Super Member CAB's Avatar
    Using
    AutoCAD 2000
    Join Date
    May 2004
    Location
    Tampa, Florida
    Posts
    801

    Default

    Another variation, untested.
    Code:
    (setq user (dos_username))
    (setq userp (cadr (assoc user
                            '(("BLockhart" "Ben")
                              ("CBearden"  "Chris")
                              ("LBrown"    "Lavon")
                              ("RChambers" "Ronnie")
                              ("JMitchell" "Justin")
                              ("JPrice"    "Joe")
                              ("LCooper"   "Lonny")
                             )
                     )
                )
    )
    (if (null userp)
      (setq userp (getstring "\n Please enter your first name: "))
    )
    (if
      (and
        (/= userp "")
        (setq maindir (dos_getdir "Select directory you wish to print:"
                                  (strcat "W:\\" userp "\\New Projects")))
        (setq sublist (dos_subdir maindir))
        (setq subnum (length sublist))
        (setq cnt -1)
      )
       (while (< (setq cnt (+ cnt 1)) subnum)
         (setq fldr (nth cnt sublist))
         (setq dwglist (cons (strcat maindir fldr) dwglist))
       )
    )
    Last edited by CAB; 13th Mar 2009 at 05:01 am. Reason: Changed cdr to cadr

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    15,709

    Default

    Ahh nice one CAB, good use of associative lists - I should have looked at this one a bit more.
    Lee Mac Programming

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

    Just another Swamper

  7. #7
    Full Member
    Using
    AutoCAD 2008
    Join Date
    Jan 2009
    Posts
    31

    Default

    Registered forum members do not see this ad.

    Thanks for the help guys,

    This is what I finally got to work.
    (while (< cnt subnum)
    (setq fldr (nth cnt sublist))
    (setq dwglist (append dwglist (list (strcat maindir fldr))))
    (setq cnt (+ cnt 1))
    )
    Everything else made my list look funny. and I was dreading having to pull info from it.

    In case you're curious, I am working on a Batchplot lisp that searches a directory for files that match a certain criteria, writes a script with the info and plots all of them.
    So basically, all the user has to do to plot off a job, is select a directory with all the part folders in it and it goes through the folders and pulls out the relevant files, (ignoring files used for xrefs and reference drawings) and plots them based on Border size. Let you know how it comes along....

Similar Threads

  1. Replies: 8
    Last Post: 22nd Dec 2008, 01:42 pm
  2. Everything is stuck
    By NUBBZ143 in forum Autodesk Inventor
    Replies: 4
    Last Post: 26th Oct 2008, 03:44 am
  3. Capitals Stuck
    By DODGE in forum AutoCAD General
    Replies: 3
    Last Post: 15th Sep 2008, 01:08 am
  4. Viewport stuck on top
    By PEIBG in forum AutoCAD Drawing Management & Output
    Replies: 8
    Last Post: 29th Apr 2008, 07:52 pm
  5. Getting stuck in my layout tab :(
    By Rooster in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 6
    Last Post: 25th Apr 2008, 01:23 pm

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