Results 1 to 9 of 9

Thread: Write usernames to text file

  1. #1
    Active Member
    Join Date
    2007-02
    Location
    Calgary, Alberta, Canada
    Posts
    73
    Login to Give a bone
    0

    Default Write usernames to text file

    I wrote some LISP that checks to see if everyone has a certain text file on their computer, and if it doesn't, to write their username to a text file. It runs this LISP everytime they open a new drawing.

    The problem is that it will write their username to the text file everytime they open a new drawing (which can make it very unorganized and messy).

    Does anyone know of a way to have their username only written once in the text file. I'm kinda thinking that the LISP needs to search the text file and find their name, and if it isn't there, then write it.

    Anyone?

  2. #2
    AUGI Addict
    Join Date
    2015-12
    Posts
    2,095
    Login to Give a bone
    0

    Default Re: Write usernames to text file

    Open the file, use (read-line...) and (cons...) or (append...) to put the contents into a list, close the file, then you can use (member...) to check the list for the user name. If the (member...) check returns nil, you can open the file in append mode and (write-line...) the users name.

    Or something along those lines...
    If you are going to fly by the seat of your pants, expect friction burns.
    Some say beauty is in the eye of the Beholder... perhaps so, but I've only seen the disintegration beam.
    Everyone else being wrong is not the same thing as being right.

  3. #3
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Write usernames to text file

    Something like this perhaps:
    Code:
    (defun AppendUser (fname / usr f str lst)
      (setq usr (getvar "LOGINNAME")) ;Get the user's login name
      (setq f (open fname "r")) ;Open the file for reading
      (setq lst nil) ;Initialize the list to empty
      (while (setq str (read-line f)) ;While a line is read from the file
        (setq lst (cons str lst)) ;Add the line to the list
      ) ;_ end of while
      (close f)
      (if (not (member usr lst)) ;Check if user is not already saved
        (progn
          (setq lst (cons usr lst)) ;Add the user name to the list
          (setq lst (acad_strlsort lst)) ;Sort the list
          ;; Write it back to the file
          (setq f (open fname "w"))
          ;; Step through the list
          (foreach usr lst
            (write-line usr f)
          )
          (close f)
        ) ;_ end of progn
      ) ;_ end of if
    ) ;_ end of defun
    Send the function the filename. If you use some other means of getting the "user name", move the usr declaration in the top line to just before the slash (to change it from a local variable to an argument). Then comment out the 1st line. Then when you use the function pass it the file name & user name you obtain elsewhere.
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  4. #4
    I could stop if I wanted to
    Join Date
    2005-09
    Location
    Canada
    Posts
    212
    Login to Give a bone
    0

    Default Re: Write usernames to text file

    If you'r routine run over a network..
    there is a little problem..

    if some user need to open the file and the fil is already open..(read-only)
    or if autoCAD crash or any other program stop and keep the file open...

    sure if you have 4 or 5 user..maybe it will run..

    In our office...I wrote a routine who put all information in a Username FOLDER.

    x:\Acad\Users\departement\username\AutoCADversion\....

    than....

    ...BackupFiles\(all cui pgp arg...)
    ...TimeProjectData.txt
    ...LispConfigFile.txt
    ...etc...

    This will allow to make sure that your routine run.
    and keep all information when time is come to change any PC or Upgrade..

  5. #5
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Write usernames to text file

    That's probably a good idea. But I prefer rather using a database to do this type of thing here ... I use a MySQL server and link to it using the ADOLisp libraries and ODCL. Then for extraction of data I've setup a few Excel spreadsheets which simply query the DB.

    I'm working on stuff like time spent on specific drawings / projects / per user, to help in project / resource management.
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  6. #6
    I could stop if I wanted to
    Join Date
    2005-09
    Location
    Canada
    Posts
    212
    Login to Give a bone
    0

    Default Re: Write usernames to text file

    I was using the mdb before doing this...

    but i've realized..that mdb have limited user access.

  7. #7
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Write usernames to text file

    Quote Originally Posted by andrea.andreetti View Post
    I was using the mdb before doing this...

    but i've realized..that mdb have limited user access.
    Yep, no more than 10 at once, and then you can get corruption. M$ Access (MDB) is not intended for multiple users. Similar to DBase / Foxpro DBF files or Paradox DB files.

    For more than 10 users you need a client-server DBMS like M$ SQL Server, Interbase, Oracle, IBM DB2, etc. Or one of the Open Source ones: MySQL, FireBird, PosGre, etc. I just use MySQL because it's free & easy to install & use ... it's also the DB most used for web applications such as Google's search engine ... so multiple users is not a problem . It doesn't have all the advanced features like the commercial ones, but if you want those FireBird / PosGre is very close, if not better than some of the commercial DB's.

    You could go for M$'s free SQL Express, but again that has limited user concurency. And you need a windows server to run it on for more than 10 users . The Open Source stuff can run on anything, win desktop, server, linux, mac, you name it .

    You install the DBMS on a server (or designated desktop). Then you need that DB's ODBC driver (installed on all the client machines) and the ADOLisp library to link from lisp through ODBC to the server.

    But this is getting a bit off topic, and I think a full fledged DBMS is a bit much unless you want to integrate several stuff into the same thing & get the info from a central source.
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  8. #8
    I could stop if I wanted to
    Join Date
    2005-09
    Location
    Canada
    Posts
    212
    Login to Give a bone
    0

    Default Re: Write usernames to text file

    Quote Originally Posted by irneb View Post
    Yep, no more than 10 at once, and then you can get corruption. M$ Access (MDB) is not intended for multiple users. Similar to DBase / Foxpro DBF files or Paradox DB files.

    For more than 10 users you need a client-server DBMS like M$ SQL Server, Interbase, Oracle, IBM DB2, etc. Or one of the Open Source ones: MySQL, FireBird, PosGre, etc. I just use MySQL because it's free & easy to install & use ... it's also the DB most used for web applications such as Google's search engine ... so multiple users is not a problem . It doesn't have all the advanced features like the commercial ones, but if you want those FireBird / PosGre is very close, if not better than some of the commercial DB's.

    You could go for M$'s free SQL Express, but again that has limited user concurency. And you need a windows server to run it on for more than 10 users . The Open Source stuff can run on anything, win desktop, server, linux, mac, you name it .

    You install the DBMS on a server (or designated desktop). Then you need that DB's ODBC driver (installed on all the client machines) and the ADOLisp library to link from lisp through ODBC to the server.

    But this is getting a bit off topic, and I think a full fledged DBMS is a bit much unless you want to integrate several stuff into the same thing & get the info from a central source.

    Thanks for all this info Irneb....i'm not that familar to DataBase.. but i'll take a look for sure.. Gracias !

  9. #9
    Active Member
    Join Date
    2008-06
    Location
    Australia
    Posts
    51
    Login to Give a bone
    0

    Default Re: Write usernames to text file

    Why not create a file with the the username as the file name. The lisp could check to see if the file exists before creating. You would then only have to check which files have been created and delete them when you fix the problem.

    You could even check for multiple items and list them in the file.

Similar Threads

  1. Create a list of drawings and write them to a text file
    By aaronic_abacus in forum AutoLISP
    Replies: 19
    Last Post: 2014-11-26, 07:36 AM
  2. Re-write log file
    By BeKirra in forum AutoLISP
    Replies: 18
    Last Post: 2013-01-22, 09:22 PM
  3. File write problem with NWD- /NWC-file type
    By bma in forum NavisWorks - General
    Replies: 3
    Last Post: 2010-08-31, 09:43 PM
  4. Read / Write To Text File
    By caddog71 in forum VBA/COM Interop
    Replies: 2
    Last Post: 2008-05-27, 06:40 PM
  5. Replies: 10
    Last Post: 2007-10-09, 01:11 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
  •