monk Posted February 28, 2012 Posted February 28, 2012 Quick one... Is it possible to stick a stored VAR into a path? i.e. I store (setq usr (getvar "LOGINNAME")) Later on i want to write a log file to a path: (setq f ("C:\\%usr%.txt")) Or something like this... Quote
Tharwat Posted February 28, 2012 Posted February 28, 2012 I think the function *strcat* would do the trick for you . e.g . (setq usr (getvar 'loginname)) (setq f (strcat "C:\\" usr ........ and so on Quote
monk Posted February 28, 2012 Author Posted February 28, 2012 Thank you, I was just reading up on some other examples and "strcat" jumped out. (Just writing my first lines of code.... eek!) Quote
Tharwat Posted February 28, 2012 Posted February 28, 2012 Happy to hear that , and just shut if you in need of any help . Quote
monk Posted February 28, 2012 Author Posted February 28, 2012 Just looking at how to remove the "." (period) from the username. I am outputting some text to a text file at a given location but the text files name is based on the LOGINNAME. But i dont want "monk.monk.txt"! Pointers appreciated. When i have it working i will post it up! Quote
monk Posted February 28, 2012 Author Posted February 28, 2012 Works so far! Will most likely have this as a subroutine somewhere. (defun C:saveSupportPaths (/ usr files paths f) (vl-load-com) (setq files (vla-get-files (vla-get-preferences (vlax-get-acad-object)))) (setq paths (vla-get-supportpath files)) (setq f (open (strcat "C:\\Users\\monk.monk\\Desktop\\"(getvar "LOGINNAME")".txt")"w")) (write-line paths f) (close f) (princ) ) Quote
Lee Mac Posted February 28, 2012 Posted February 28, 2012 There are many ways this could be accomplished, here is just one: (vl-list->string (vl-remove 46 (vl-string->list (getvar 'LOGINNAME)))) Here is another: (vl-string-translate "." " " (getvar 'LOGINNAME)) Quote
monk Posted February 28, 2012 Author Posted February 28, 2012 Thanks Lee. (I am using your site a lot right now!) I will have a butchers at what you have suggested. My only thought on my code above is what happens if the path does not exist or is not available? Will the program hang or will it just stop? Do i need to add an error section? Quote
Lee Mac Posted February 28, 2012 Posted February 28, 2012 My only thought on my code above is what happens if the path does not exist or is not available? Will the program hang or will it just stop? Do i need to add an error section? If the path: "C:\\Users\\monk.monk\\Desktop" doesn't exist, the open function will return nil when attempting to create a text file at a path that doesn't exist. Now, since the variable 'f' is nil, write-line is passed a null file descriptor argument and will consequently write the string to the command-line, rather than the file (since the file descriptor argument is optional). However, the close function will error when passed a null file descriptor: _$ (close nil) ; error: bad argument type: streamp nil To avoid these errors, include a simple conditional statement: (defun C:saveSupportPaths ( / files paths f ) (setq files (vla-get-files (vla-get-preferences (vlax-get-acad-object)))) (setq paths (vla-get-supportpath files)) (if (setq f (open (strcat "C:\\Users\\monk.monk\\Desktop\\" (getvar "LOGINNAME") ".txt") "w")) (progn (write-line paths f) (close f) ) (princ "\nUnable to Create File.") ) (princ) ) (vl-load-com) Of course, this doesn't include the code to remove invalid characters from the filepath string. Quote
monk Posted February 28, 2012 Author Posted February 28, 2012 That sir is perfect. I am trying to read up on as much as i can. I am using your site, afralisp, visual lisp developers bible. Any other resources you can think of? Hard copies are good. I would like a reference / dictionary for all the functions etc but that would be huge! Quote
Lee Mac Posted February 28, 2012 Posted February 28, 2012 You're very welcome. Any other resources you can think of? Hard copies are good. I would like a reference / dictionary for all the functions etc but that would be huge! IMO, the very best reference that you can use is the Visual LISP IDE (VLIDE) Help Documentation (and I strongly recommend that you use the VLIDE to write your code if you are not already doing so); this includes the AutoLISP Developer's Guide and a complete AutoLISP reference. In versions pre AutoCAD 2011, it also included an ActiveX COM Reference for all the Properties and Methods derived from the AutoCAD Object Model, this was removed when Autodesk [stupidly] migrated to use online help, though the original acadauto.chm file can still be found under: C:\Program Files\Common Files\Autodesk Shared I've written a handful of short tutorials about the VLIDE on my site: http://lee-mac.com/tutorials.html#vlide And there is also a lot of information on AfraLISP: http://www.afralisp.net/visual-lisp/tutorials/visual-lisp-editor-part-1.php Hard copies are good. I would very much disagree with you there - soft copies have many advantages over hard copies, (aside from saving the rainforests), Try Ctrl+F'ing a book and you'll get the picture Quote
monk Posted February 28, 2012 Author Posted February 28, 2012 Ta very much. Using all the above so I am hopefully on the right tracks! I agree on the soft copy point, but it is nice to thumb through something when you are learning! But maybe that is just me! Quote
Recommended Posts
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.