PDA

View Full Version : Manipulate the drawing path and drawing name


stephen.coff
2007-06-18, 01:14 AM
Guys any suggestions or assistance would be grately appreciated,
I am try to write a LISP routine that prepares an Architectural drawing. Usually it works relatively smoothly though today I had a glitch and them an error on the routines behalf. It really doesn't allow for any differences and most likely can be done best by using wildcards though I have no idea how to approach it.

I attempted using the following portion of the routine to "save as" the incoming file from the incoming folder to the drawing folder and add "-XR-A-" in front of the file name.

Being that the only thing that changes in the filing process from job to job is two things:
The project name & the folder name of the folder in the "Incoming". By this I mean that this name always starts with an itial followed by the date, backwards.
eg: "a070618" representing, a folder of Architecturals that came into the office on the 18.06.07.
I Wasn't very good with using wildcards so opted to remove by number of characters as the number of characters should always be the same. This isn't working consistantly which is now causing a problem.
Could someone please assist me as the best way to do this.
Below is the current portion of Lisp to remove the characters.

(setvar "cmdecho" 0)
(setq drawprefix (getvar "dwgprefix"))
(setq drawname (getvar "dwgname"))
(setq currentdirectory
(strcat (getvar "dwgprefix") (getvar "dwgname"))
)
(setq newdrawname (strcat "XR-A-" (getvar "dwgname")))
(setq num 17)
(setq strlength (strlen drawprefix))
(setq newnum (- strlength num))
(setq ammenddrawprefix1
(strcat (vl-string-right-trim
(substr drawprefix newnum strlength)
drawprefix
)
"\\"
)
)
(setq newdirectpath (strcat ammenddrawprefix1 newdrawname))
(command "saveas" "r14" newdirectpath)Any assist would be greatly appreciated

Stephen

[ Moderator Action = ON ] What are [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code) [ Moderator Action = OFF ]

Opie
2007-06-19, 09:24 PM
Could you elaborate on the folder and file names? What does it look like originally? What do you want it to look like when you are done?

stephen.coff
2007-06-20, 01:15 AM
Opie,
Thank you for the reply.

I will give you two examples of initial files and their locations and the the attempted end results, see below.

Example 1.

The initial file location:
"S:\#project\21 ROGER ST\DRAWINGS\INCOMING\a060821\2002-06-CC100-A"

The file name being:
"2002-06-CC100-A"

My aim is to use the "save as" command and place the file always in this drawing folder though with an extended name, see below for the aimed result.

The new location:
"S:\#project\21 ROGER ST\DRAWINGS\" (need to remove the "INCOMING\a060821\" from the folder location)

The new file name:
"XR-A-2002-06-CC100-A" (the "XR-A-" being added to the start of the file name)


Example 2.

The initial file location:
"S:\#project\smith st 18\Drawings\Incoming\A061212\A11L3"

The file name being:
"A11L3"

My aim is to use the "save as" command and place the file always in this drawing folder though with an extended name, see below for the aimed result.

The new location:
"S:\#project\smith st 18\Drawings\" (need to remove the "Incoming\A061212\" from the folder location)

The new file name:
"XR-A-A11L3" (the "XR-A-" being added to the start of the file name).


As you can see there are some minor differences, one has the location in partial capital letters whilst the other isn't and the only real change is the project name eg. smith st 18
and the name of the folder that the incoming file is saved in eg. A061212.

Your assistance is greatly appreciated Opie.

Stephen

abdulhuck
2007-06-20, 04:50 PM
Stephen,

With your details to Opie's question, things are more clear. Can you try the following function within your code?


(defun trimfolder (path level / len newstr)
(setq teststr "")
(repeat level
(setq len (+ (vl-string-position (ascii "\\") path 0) 1))
(setq newstr (substr path 1 len))
(setq teststr (strcat teststr newstr))
(setq path (substr path (+ 1 len) (- (strlen path) len)))
)
teststr
)


This will trim your folder to the required level. You have to input the folder name and level as below:

(trimfolder (getvar "dwgprefix") 2)


Solution for your code:


(setq newDwg (strcat (trimfolder (getvar "dwgprefix") 4) "XR-A-" (GETVAR "DWGNAME")))


will output "S:\#project\smith st 18\Drawings\XR-A-A11L3.DWG" if your original drawing was "S:\#project\smith st 18\Drawings\Incoming\A061212\A11L3"

I did not include any error check.

HTH
AbdulHuck

Opie
2007-06-20, 11:58 PM
Opie,
Thank you for the reply.

I will give you two examples of initial files and their locations and the the attempted end results, see below.

...

Your assistance is greatly appreciated Opie.

Stephen
Hopefully, AbdulHuck's code is a viable solution to your problem. It's always helpful to provide as much information to your code issues as you can.

Opie

stephen.coff
2007-06-25, 02:27 AM
Thank you both. I will give that a go and expect it will resolve my poor attempt.

Stephen

abdulhuck
2007-06-25, 09:25 AM
Let us know if you face any problem.

Regards
AH