Jump to content

Using a wildcard to get file path informatin.


Dustin11

Recommended Posts

I'm a little new to wildcards and don't fully understand how they work andwhen you can use them. Right now I'm trying to use them in code that wouldallow me to get some additional information about a file path I'm trying todefine. The code below is the one I'm working on that I'm having trouble with:

 

[font=Times New Roman][size=3](defun c:insdat (/ bti jobnumb firstnumb secondnumb chngnumb filepth)
 (vl-load-com)
 (command "-layer" "m" "G-PLAN-DATM-____-____-N" "lo" "G-PLAN-DATM-____-____-N" "")
 (initget 1)
 (setq jobnumb (getstring "\nEnter The 7 didgit Job Number:"))
 (setq jobnumblen (strlen jobnumb))
 (cond ((/= jobnumblen 7)
 (print "The Job Number Must Be Exactly 7 Digits Long! Try Again.")
        (exit)
        );cond
);cond
 (initget 1)
 (setq chngord (getstring "\nEnter Change Order Number:"))
 (setq chngordlen (strlen chngord))
 (setq firstnumb (substr jobnumb 1 3)
secondnumb (substr jobnumb 4 7)
filepth (strcat "J:\\" firstnumb "\\" secondnumb "\\" chngord "[url="file://\\prod\\Sheet"]\\prod\\Sheet[/url] Metal\\")
);setq
 (if (vl-file-directory-p filepth)
   (progn
     (setq dept "prod")
     );progn
   (progn
     (setq dept "4-Detailing")
     );progn
   );if
 (setq filepth (strcat "J:\\" firstnumb "\\" secondnumb "\\" chngord "\\" dept "[url="file://\\Sheet"]\\Sheet[/url] Metal\\"))[/size][/font]
[font=Times New Roman][size=3]  (if
   (setq bti
   (getfiled "Select Block to Insert" filepth "dwg" 0)
  );if
   (progn
     (command "._-Insert" bti "_S" 1.0 "0,0,0" 0.00 "" "")
     (while
(/= 0 (getvar "CMDACTIVE"))
(command pause)
);while
     );progn
   (princ "\nNo File picked.")
   );if
 (princ)
 (setvar "CLAYER" "0")
 );defun[/size][/font]

 

Heres the issue that I'm having. How our file directory works is that wehave first we have to specify a 3 digit number in order to get into one folderthen next you need to specify a 4 digit number to get into the next folder butthats what I'm having a problem with. I can specify the 4 digit number justfine but that 4 digit number is sometimes (usually) followed by the job’s nameso it would look something like "4*** - Hyatt 4th Floor". Because ofthat, I'm wondering if there is a wildcard I could use to grab the job nameassociated with that 4 digit number and redefine the file path I'm trying togive to the “getfiled” function. The code is pretty sloppy right now as I'veyet to do any clean up or any kind of rewrite.

 

Thanks.

Link to comment
Share on other sites

You can't use a wildcard to extract the project name/description following the four digits, but due to your consistency of directory being prefixed by four digits, you can simply use SUBSTR, methinks. :thumbsup:

Link to comment
Share on other sites

I didn't think a wildcard would work but I was holding onto a little bit of hope that I could use it much in the same way you could wildcard layer or block names.

 

Just curious, how could I use substr to get the project name? I understand how I could use it to add to the job directory I'm defining, but I'm not sure how I could use it to pull information out from the file path I'm trying to define.

Link to comment
Share on other sites

Just curious, how could I use substr to get the project name? I understand how I could use it to add to the job directory I'm defining, but I'm not sure how I could use it to pull information out from the file path I'm trying to define.

 

I'm not sure you're understanding what SUBSTR[ing] does... Look it over in the developer documentation (I provided you a link in my earlier post).

 

As for how to get the project name, using your example, and presuming that there be a four digit prefix followed by space hyphen space " - " before the project name:

 

(substr "4*** - Hyatt 4th Floor" 

Link to comment
Share on other sites

Sorry, I wasn't being very clear on what I was looking for in my previous posts. the project name is always going to be different, it could be one of a few hundred different jobs and I was only using "Hyatt 4th Floor" as an example which I forgot to mention earlier. How my code works right now is it asks the user for the 7 digit number job number which then I use substr to split that up between the 3 digit and 4 digit file names.

 

[font=Times New Roman][size=3] (setq jobnumb (getstring "\nEnter The 7 didgit Job Number:"))[/size][/font]
[font=Times New Roman][size=3] (setq chngord (getstring "\nEnter Change Order Number:"))  [/size][/font]
[font=Times New Roman][size=3] (setq chngordlen (strlen chngord))  [/size][/font]
[font=Times New Roman][size=3] (setq firstnumb (substr jobnumb 1 3) [/size][/font]
[font=Times New Roman][size=3]          secondnumb (substr jobnumb 4 7))[/size][/font]
[font=Times New Roman][size=3]

[/size][/font]

 

The problem is that the project name extention is always going to be different and will cause the getfield function to not be able to read what I'm defining as a result beacuse it will only see , for example "4567" as the file name when the real file name would be "4567 - Hyatt 4th Floor" so it would need to look like this "J:\\789\\4567 - Hyatt 4th Floor\\" but would look like this instead J:\\789\\4567\\" which will cause the function to fail. I'm trying to find a way to go to that folder and be able to return its full name which then I can dice up and extract the information I need. So I guess what it breaks down to is that I'm looking for a way to get the project name for the job number the user specified.

 

Thanks for your help by the way, I appreciate it.

Link to comment
Share on other sites

Consider the Vl-Directory-Files function:

 

(vl-load-com)

(defun c:FindSubFolder (/ root prjNum primary secondary folders count)
 (if (and
       (setq root "[color="red"]C:\\_SomeFolder\\[/color]")
       (setq prjNum (getstring "\nEnter The 7 didgit Job Number:"))
       (= 7 (strlen prjNum))
       (setq primary (substr prjNum 1 3))
       (setq secondary (substr prjNum 4 7))
       (setq folders (vl-directory-files
                       (strcat root primary)
                       (strcat secondary "*")
                       -1
                     )
       )
     )
   (cond ((= 1 (setq count (length folders)))
          (prompt "\nOne directory found: ")
          (princ (car folders))
         )
         ((< 1 count)
          (prompt "\nMultiple directories found: ")
          (princ
            (vl-string-right-trim
              ", "
              (apply 'strcat
                     (mapcar (function (lambda (x) (strcat x ", ")))
                             folders
                     )
              )
            )
          )
         )
   )
   (prompt "\n** No matching folder found ** ")
 )
 (princ)
)

Link to comment
Share on other sites

It keeps coming up as "no matching folders found" regardless of what job number I enter. I deleted the variable scrubbing in the beginning of the code and ran it again to see which variables were being defined and the only one that came up "nil" was "folders", for some reason that one isn't being defined. The job number should have brought it to a folder called "6157 Bellevue Hyperbarics MB" which it did but it failed for one reason or another.

Link to comment
Share on other sites

The code works on my end... Perhaps you should debug it, following the change(s) you had to make to get it to work on your end?

 

I'd start with the string defining the root variable, and step through to the parameters being supplied to the vl-Directory-Files call.

Link to comment
Share on other sites

Whoops, big error on my part. I copy and pasted your code just as it was written without modifying the "C:\\_SomeFolder\\" part and thats why it was crashing. Code worked great after I changed that part to match our file structure. Thanks again for your help. Those VL, VLA, and VLAX functions are still new to me and I don't really know how to use more than 2 or 3 at the moment.

Link to comment
Share on other sites

Whoops, big error on my part. I copy and pasted your code just as it was written without modifying the "C:\\_SomeFolder\\" part and thats why it was crashing. Code worked great after I changed that part to match our file structure. Thanks again for your help.

 

No worries; glad you got it sorted.

 

Those VL, VLA, and VLAX functions are still new to me and I don't really know how to use more than 2 or 3 at the moment.

 

We all start somewhere, and there's always something to learn. :beer:

Link to comment
Share on other sites

I have a follow up questions. I was trying to add the piece of code you wrote for me with what I had before and I'm having an issue with the value of the "folders" variable in that I can't really do anything with it. I'm trying to use it to define a file directory path but when I use the variable I keep getting the error code "bad argument type: stringp ("6157 Bellevue Hyperbarics MB")". Would this be a result me trying to use strcat on both a list and string? Heres the line of code its failing on so there is a better idea of what is happenning:

 

 (setq filepth (strcat primary "\\" folders "\\" chngord "[url="file://prod//Sheet"]\\prod\\Sheet[/url] Metal\\")

 

I've tried to use that "folders" variable with quite a few different functions but it has failed every time

Link to comment
Share on other sites

You're receiving that error as 'folders' is actually a List data type, when Strcat is looking for String... Hence the Cond-itional statement in my example, which checks the List Length for one or more items.

 

Try this adaptation:

 

 (setq filepth (strcat primary "\\" [b][color="red"](car[/color][/b] folders[b][color="red"])[/color][/b] "\\" chngord "[url="file://prod//Sheet"]\\prod\\Sheet[/url] Metal\\")

Link to comment
Share on other sites

Oh ok that makes since as to why it wasn't working. I tried cdr on it earlier but that came back with an error as well but thats probably because I was using it with another function which was probably causing the issue. I just tied that in with the code I had earlier and it worked great even when I tried it on multiple different files. Thanks again for your help, it will be great assistance for if/when I need to do something like this again.

Link to comment
Share on other sites

I just tied that in with the code I had earlier and it worked great even when I tried it on multiple different files. Thanks again for your help, it will be great assistance for if/when I need to do something like this again.

 

Glad to hear it, Dustin11; I'm happy to help.

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