PDA

View Full Version : Edit dawing property based on file name?


keelay711
2006-02-14, 12:59 AM
The problem:
I have a couple hundred drawings to update, but several other higher-priority projects consuming my time.

The parameters:
AutoCAD 2006
The drawings all x-reference their relative borders. The border has a field pointing to the drawing properties. I need to update this drawing property (keyword) based on the file name of the drawing as follows:

Filename: Drawing-SH3.dwg
Keyword Value: -S.H. 3-

I need to go into each drawing anyway for various reasons, so a routine that goes through multiple drawings at once is viable but not needed. I just want to automate the process of updating the drawing number without having to go through the pull down menu-> drawing properties, etc.

The VERY basic outline:
Retrieve current filename "Sample-SH3.dwg"
Set to variable
Truncate variable to "SH3"
Format variable to "-S.H. 3-"
Insert variable into keyword drawing property
End

The pathetic begging and pleading paragraph:
I know this is the lazy way of doing it... essential asking someone to do it for me with a lisp via these forums. I am praying that someone out there wants the challenge. I just don't have the time to sort through the routine, with all these projects pending. Same story everywhere, right?

T.Willey
2006-02-14, 01:34 AM
(defun c:UpDateSummary (/ DefineName)

(defun DefineName (/ DwgName Pos-)

(setq DwgName (vl-filename-base (getvar "dwgname")))
(setq Pos- (vl-string-search "-" DwgName))
(strcat
(substr DwgName (1+ Pos-) 2)
"."
(substr DwgName (+ 3 Pos-) 1)
"."
(substr DwgName (+ 4 Pos-) 1)
"-"
)
)

(vlax-put
(vla-get-SummaryInfo
(vla-get-ActiveDocument
(vlax-get-Acad-Object)
)
)
'Keywords
(DefineName)
)
(princ)
)

keelay711
2006-02-14, 02:00 AM
You are my hero. 8) VLA code is way beyond my current level of lisping, and you just saved me tons of time. AND, based off this code, I can automate a few other things I was looking into.

Thank you

Doh! Is it possible to make the routine recognize if its double digits?

IE: Drawing-SH12 ---> -S.H. 12-

T.Willey
2006-02-14, 05:49 AM
Yea. This may work, replace this

(substr DwgName (1+ Pos-) 2)
"."
(substr DwgName (+ 3 Pos-) 1)
"."
(substr DwgName (+ 4 Pos-) 1)
"-"
)

with

(substr DwgName (1+ Pos-) 2)
"."
(substr DwgName (+ 3 Pos-) 1)
"."
(substr DwgName (+ 4 Pos-) 1)
(if (= (subst DwgName (+ 5 Pos-) 1) ".")
"-"
(strcat (substr DwgName (+ 5 Pos-) 1) "-")
)
)

keelay711
2006-02-15, 06:03 AM
I am getting the following error when invoking that last version. Note: the first, simpler version worked like a charm.

; error: bad argument type: consp 1

AutoCAD's help file seems to be of little to no use when it comes to the VLA. I have attempted to debug this myself, but to no avail. I just dont understand the core element. I have also tried to simplify this code more so that it directly reads anything after the "-" in the filename (excluding the .dwg) and put that into the Keywords. I thought I could just get rid of the Strcat section to do this, but then I get an undefined Definename.

T.Willey
2006-02-15, 05:12 PM
I missed a letter. The second code snippet should have been

(substr DwgName (1+ Pos-) 2)
"."
(substr DwgName (+ 3 Pos-) 1)
"."
(substr DwgName (+ 4 Pos-) 1)
(if (= (substr DwgName (+ 5 Pos-) 1) ".") ; Here I missed an "r"
"-"
(strcat (substr DwgName (+ 5 Pos-) 1) "-")
)
)

Should work now. If you only want the items after the "-", then all you need to do is.

(substr DwgName (+ 2 Pos-))

keelay711
2006-02-15, 08:30 PM
Thanks a bunch