Jump to content

help with text string...


Recommended Posts

Posted

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

 

 

 

 

 

 

 

 

Posted (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 by leonucadomi
Posted

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

 

Posted

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

 

Posted

Why do I convert the dwg to pdf and send it to a folder called "pdf"

Posted

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)

Posted

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

 

 

Posted

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.

  • Thanks 1
Posted

Use this.

 

; check that pdf directory exists
(setq dwgpre (strcat (getvar "dwgprefix") "\pdf"))
(if (= (vl-file-directory-p dwgpre) nil)
(vl-mkdir dwgpre)
)

 

  • Thanks 1
Posted
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))

 

  • Thanks 1
Posted
50 minutes ago, leonucadomi said:

thanks

Don't even really need to check: 

(vl-mkdir (setq dwgpre (strcat (getvar "dwgprefix") "PDF")))

 

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