TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Martin-Y on June 02, 2004, 10:37:59 AM

Title: Diesel question
Post by: Martin-Y on June 02, 2004, 10:37:59 AM
Could anyone explain the role of the numbers in the following, I'm OK with the words as it seems to return part of a string but thats the limit of my knowledge. I have been unable to find an explanation in any tutorials.
code:
$(upper,$(substr, $(getvar, "dwgprefix")$(getvar, "dwgname"), $(+, 5, $(*, 16, $(eq, $(substr, $(getvar, "dwgprefix"), 7, 1), "-")))))
Title: Diesel question
Post by: SpeedCAD on June 02, 2004, 11:03:06 AM
Hi...

What thing you not understand??
Title: Diesel question
Post by: Kerry on June 02, 2004, 11:05:52 AM
Returns the substring of string, starting at character start and extending for length characters.

$(substr, string, start [, length])
Characters in the string are numbered from 1. If length is omitted, it returns the entire remaining length of the string.
Title: Diesel question
Post by: Martin-Y on June 02, 2004, 11:15:32 AM
I understand it must control the length of the string but I'm being a bit thick as regards the formula (+ 5(* 16) 7, 1) what is it doing?
Title: Diesel question
Post by: Kerry on June 02, 2004, 11:37:46 AM
It's a LONG time since I've played with Diesel, so this is an old memory ::

(getvar "dwgname")   ;;--> "Drawing1.dwg"
(getvar "dwgprefix")  ;;--> "J:\\CONS\\"

(substr (getvar "dwgprefix") 7  1) ;;-- > "S"

(eq (substr (getvar "dwgprefix") 7 1) "-")  ;; is it equal to "-" ??
;;If the strings are identical, the $(eq ... returns 1; otherwise, it returns 0.

;; so :

(+, 5, $(*, 16, $(eq, $(substr, $(getvar, "dwgprefix"), 7, 1), "-")))))

will return either

(+ 5 ( * 16 0)) ;;--> 5
or
(+ 5 ( * 16 1)) ;;--> 21
So the Diesel expression will return a string,
converted to uppercase, the concatenation of path an drawing name, stripped to either char 5 or 21.
Title: Diesel question
Post by: Martin-Y on June 02, 2004, 12:09:56 PM
Kerry

Thanks for your patience, I have had a play and shortened it to
code:
$(upper,$(substr, $(getvar, "dwgprefix")$(getvar, "dwgname"), 5))

at least I understand this strips to the 5th character, could not get my head round the need for *16 and 7, 1

Thank you
Title: Diesel question
Post by: Kerry on June 02, 2004, 12:26:14 PM
Soungs to me as if the original was designed to suit a VERY regimented file and folder naming convention.