leonucadomi Posted February 24, 2023 Posted February 24, 2023 hello all: I am doing trying to modify a text string I extract the dwgprefix variable and save it in a variable called "PATH1" (setq PATH1 (getvar "dwgprefix")) example: "C:\Users\user1\Desktop\DWG\" what i need is to modify this string and that I get this as a result... "C:\Users\user1\Desktop\PDF\" that is, search the string "DWG" and replace it with "PDF" and store it in a new variable called "PATH2" taking into account that the chain can grow in length but that the word "DWG" will always be found. any comment is welcomed thanks Quote
Steven P Posted February 24, 2023 Posted February 24, 2023 reckon this will help https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-8543549B-F0D7-43CD-87A3-F6B827FF0B88 Probably: vl-string-subst Worth noting that the backslash often denotes the next character is a special character (a tab \t, new line, \n and so on) so to make it useable you might need a double \\ (tell the LISP you want to use the special character \) 1 Quote
leonucadomi Posted February 24, 2023 Author Posted February 24, 2023 (edited) I thought I had made it but no Steven P how I do this? (tell the LISP you want to use the special character \) Edited February 24, 2023 by leonucadomi Quote
Steven P Posted February 25, 2023 Posted February 25, 2023 Use a double \\ instead of a single \ Try this both ways, once with singe \ and once with double \\ If you have a single \ in the string the last " will be seen as just text and not a closing " for example - and the LISP will fail. Put a space after the last \ and you'll see the difference better (DEFUN c:tt ( / mystring ) (setq mystring "C:\\Users\\user1\\Desktop\\DWG\\" ) (princ (vl-string-subst "PDF" "DWG" mystring)) ) Quote
leonucadomi Posted February 27, 2023 Author Posted February 27, 2023 The file is in a folder called "DWG" I want the string to change from "DWG" to "PDF" try this but it keeps showing double bar "\\" and I want it to only generate a bar "\" to use that string as a path. this is my code.. (defun c:test ( / prefix prefix2 path ) (setq prefix (getvar "dwgprefix")) (setq prefix2 (vl-prin1-to-string prefix)) (setq path (vl-string-subst "PDF" "DWG" prefix2)) (terpri) (princ path) (princ) ) Quote
Steven P Posted February 27, 2023 Posted February 27, 2023 What are you using the file path for? 1 Quote
leonucadomi Posted February 27, 2023 Author Posted February 27, 2023 Why do I convert the dwg to pdf and send it to a folder called "pdf" Quote
Steven P Posted February 27, 2023 Posted February 27, 2023 You are creating a text string with the new folder path, and I assume you are going to use that text string to do something else with it - which is what I was asking. After you have created the text string, what do you do with it? (might be a couple of solutions to what you want but which to use depends what the text string is going to be for) Quote
leonucadomi Posted February 27, 2023 Author Posted February 27, 2023 it's right I need to generate the text string with the new route Why do I print my dwg in pdf then with this new path the generated pdf file will be saved in the correct location. I use two folders folder calls DWG folder PDF which are located in "x" folder I can print my dwg in pdf and place it in the DWG folder what I want to do is print it and send it to the other folder called PDF that's why i need to manipulate the path i get with the variable DWGPREFIX Quote
Steven P Posted February 27, 2023 Posted February 27, 2023 OK, in this case you should need to use a double '\\' Try it and see perhaps with a test of the plotting routine you are making, at the plot stage type in the string in the LISP "C:\Users\user1\Desktop\PDF\" and see what it does.... If you type in the command line (getvar 'dwgprefix) it will show it with a double \\.... so in this case your code is OK at the moment, double \\s are good here. 1 Quote
BIGAL Posted February 27, 2023 Posted February 27, 2023 Use this. ; check that pdf directory exists (setq dwgpre (strcat (getvar "dwgprefix") "\pdf")) (if (= (vl-file-directory-p dwgpre) nil) (vl-mkdir dwgpre) ) 1 Quote
ronjonp Posted February 28, 2023 Posted February 28, 2023 15 hours ago, BIGAL said: Use this. ; check that pdf directory exists (setq dwgpre (strcat (getvar "dwgprefix") "\pdf")) (if (= (vl-file-directory-p dwgpre) nil) (vl-mkdir dwgpre) ) FINDFILE works too: (or (findfile (setq dwgpre (strcat (getvar "dwgprefix") "PDF"))) (vl-mkdir dwgpre)) 1 Quote
ronjonp Posted March 2, 2023 Posted March 2, 2023 50 minutes ago, leonucadomi said: thanks Don't even really need to check: (vl-mkdir (setq dwgpre (strcat (getvar "dwgprefix") "PDF"))) 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.