CadFrank Posted October 24, 2012 Posted October 24, 2012 Hi, I'm using (setq Cfilepath (getvar 'DWGPREFIX)) to get my current filepath and i would like to get a specific string from it. Filepath : "L:\\ECHAFAUDAGES (L2)\\CLIENTS\\Name of client\\Project name\\ingénierie\\PlanCad\\" Thing is i'm not sure what to use since Name of client never has the same lenght, and same for project name. So i can't use substr. What function should I be looking for ? Quote
MSasu Posted October 24, 2012 Posted October 24, 2012 What are you looking in fact to achive? To check if a given string (i.e. client name) is present or to retrive the name of client (the third folder from root)? Quote
Lee Mac Posted October 24, 2012 Posted October 24, 2012 Look into: vl-string-search vl-string-position wcmatch String to List Quote
CadFrank Posted October 24, 2012 Author Posted October 24, 2012 Well Client name will always be present. I just want to retrieve the project name to print it in a .txt file Quote
MSasu Posted October 24, 2012 Posted October 24, 2012 Then you may use this function: ;;++++++++++++++++++ ;; parser by CAB ;;++++++++++++++++++ (defun sparser (str delim / ptr lst) (while (setq ptr (vl-string-search delim str)) (setq lst (cons (substr str 1 ptr) lst)) (setq str (substr str (+ ptr 2))) ) (reverse (cons str lst)) ) Use it like: (nth 4 (SPARSER (getvar "DWGPREFIX") "\\")) For sure this presume that project name will be always the 4th folder from root. Quote
MSasu Posted October 24, 2012 Posted October 24, 2012 @Tharwat, I'm afraid that SUBSTR cannot help in OP's case. Name of client never has the same lenght, and same for project name. Quote
Tharwat Posted October 24, 2012 Posted October 24, 2012 @Tharwat, I'm afraid that SUBSTR cannot help in OP's case. I was preparing the post when the OP posted that more clarification . so I will take it back if it is not helpful at all . Quote
CadFrank Posted October 24, 2012 Author Posted October 24, 2012 For sure this presume that project name will be always the 4th folder from root. Well actually the fifth But indeed it works Quote
CadFrank Posted October 24, 2012 Author Posted October 24, 2012 (edited) So i can't use substr. Naw it's ok Tharwat i just think you didn't read my post fully Edited October 24, 2012 by CadFrank Quote
MSasu Posted October 24, 2012 Posted October 24, 2012 You said "project name", right? It may be the 5th item in the list, but please don't miss that the first index in a list is always 0; so the 5th entry correspond in fact to index 4. Quote
CadFrank Posted October 24, 2012 Author Posted October 24, 2012 Well I entered 5 in the code (nth 5 (SPARSER (getvar "DWGPREFIX") "\\")) And it game me the project name ?? Quote
MSasu Posted October 24, 2012 Posted October 24, 2012 I have based my comments on the example path from first post; to see how the path is divided in items call only: (SPARSER (getvar "DWGPREFIX") "\\") Anyway, I just wanted to ensure that you got the principle right; for sure should use 5 if that is the apropriate index. Quote
CadFrank Posted October 24, 2012 Author Posted October 24, 2012 where does the argument delim get his information.. can't seem to understand the code... Quote
BlackBox Posted October 24, 2012 Posted October 24, 2012 where does the argument delim get his information.. can't seem to understand the code... I've just stumbled upon this thread, but as I understand it, you supply the delim value as an argument of the Sparser function. FWIW - I offered this adaptation over at AUGI some time ago: (vl-load-com) (defun _FilePath->List (filePath / i folder folders) (setq filePath (vl-string-translate "\\" "/" filePath)) (while (setq i (vl-string-search "/" filePath)) (setq folders (cons (setq folder (substr filePath 1 i)) folders)) (setq filePath (substr filePath (+ 2 i))) ) (reverse folders) ) Example: _$ (_FilePath->List "G:\\745 The name of the Project\\74534\\drawings\\") ("G:" "745 The name of the Project" "74534" "drawings") _$ The biggest difference is that it (my offering) will accept both double back-slashes "\\" and / or single forward-slash "/" for the file path string as an argument, and returns a list of strings, where each string represents a folder in the supplied path. HTH Quote
CadFrank Posted October 24, 2012 Author Posted October 24, 2012 Waaaa! this is so complicated !!! lol Well I'm just trying to evaluate how you got to think of writting that code.. I'm basicly trying to make a login log out code to know the amount of time i spend on a projet hehe!! Quote
BlackBox Posted October 24, 2012 Posted October 24, 2012 Waaaa! this is so complicated !!! lol Well I'm just trying to evaluate how you got to think of writting that code.. Removing the learning curve, it's really simple code at it's root... The limited use for adding the feature to accept both delimiters while applicable to this situation specifically, was certainly not intended to confuse anyone. I'm basicly trying to make a login log out code to know the amount of time i spend on a projet hehe!! If only needing to account for what drawings are opened, at what time they were opened, and when they were closed... And the built-in log system is insufficient... You could use a simple DocManager Reactor, with the :vlr-DocumentCreated, and :vlr-DocumentToBeDestroyed Events respectively. If you're more adept at coding .NET, then look into using a similar concept, with a static DocumentCollection Event handler. If you require context... Meaning was anything actually done... That's another layer of complexity, but doable. If you're wanting to add a filter for what commands were performed, and how one would quantify was deleting that line, or drawing those three circles beneficial to the project... That's a whole different level of complexity entirely, and perhaps one that is impossible to identify by consensus. Quote
CadFrank Posted October 25, 2012 Author Posted October 25, 2012 Yeah, I guess it's not meant to be a hard code. The only coding I know a little of is Autolisp. Think is I'm writting codes and sometimes I ask for help and I get answer in witch I do not know the meaning or even how to read the code. That's like my problem, I'm trying to learn Autolisp but I'm not sure how to approach the coding for me to understand it. Or maybe I'm looking at it a little to close hehe !! and the answer is in my face who knows. I'm just trying to figure it out ! 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.