+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 25
  1. #1
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jul 2011
    Posts
    222

    Default Getting a specific string from a file path

    Registered forum members do not see this ad.

    Hi,

    I'm using
    Code:
    (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 ?

  2. #2
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,005

    Default

    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)?
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  3. #3
    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,743
    Lee Mac Programming

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

    Just another Swamper

  4. #4
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jul 2011
    Posts
    222

    Default

    Well Client name will always be present. I just want to retrieve the project name to print it in a .txt file

  5. #5
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,005

    Default

    Then you may use this function:
    Code:
    ;;++++++++++++++++++
    ;; 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:
    Code:
    (nth 4 (SPARSER (getvar "DWGPREFIX") "\\"))
    For sure this presume that project name will be always the 4th folder from root.
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  6. #6
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,631

    Default

    Maybe also .

    substr
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  7. #7
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,005

    Default

    @Tharwat, I'm afraid that SUBSTR cannot help in OP's case.
    Quote Originally Posted by CadFrank View Post
    Name of client never has the same lenght, and same for project name.
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  8. #8
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,631

    Default

    Quote Originally Posted by MSasu View Post
    @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 .
    - When aim is being settled in my mind , I have to reach it and get it in hand whatever it costs and wherever it is and will never give up . Tharwat said

  9. #9
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jul 2011
    Posts
    222

    Default

    Quote Originally Posted by MSasu View Post
    For sure this presume that project name will be always the 4th folder from root.
    Well actually the fifth :p

    But indeed it works

  10. #10
    Senior Member
    Using
    AutoCAD 2010
    Join Date
    Jul 2011
    Posts
    222

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by CadFrank View Post

    So i can't use substr.
    Naw it's ok Tharwat i just think you didn't read my post fully :p
    Last edited by CadFrank; 24th Oct 2012 at 08:20 pm.

Similar Threads

  1. Search a string on the the file name....
    By shakuhachi in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 22nd Apr 2011, 06:07 pm
  2. Replacing a specific character from a string
    By Michaels in forum AutoLISP, Visual LISP & DCL
    Replies: 25
    Last Post: 5th Jan 2011, 12:46 pm
  3. Conver text string into file.txt
    By HelloWorld in forum AutoLISP, Visual LISP & DCL
    Replies: 19
    Last Post: 4th Feb 2008, 09:03 am
  4. Open CAD drawing at specific path
    By MadMax in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 11th May 2007, 11:28 am
  5. Finding file path of specified support file
    By Autodesk in forum AutoCAD RSS Feeds
    Replies: 0
    Last Post: 9th Nov 2006, 01:40 am

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