Jump to content

The simplest things seem to get me stuck..


Hardeight

Recommended Posts

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.

Link to comment
Share on other sites

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:

 

(setq strlst (cons *newstring* strlst))

Link to comment
Share on other sites

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 (

(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:?
Link to comment
Share on other sites

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

 

(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))
     )
 ) 			 		

Link to comment
Share on other sites

Another variation, untested.

(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))
  )
)

Link to comment
Share on other sites

Thanks for the help guys,

 

This is what I finally got to work.

(while (

(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....

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...