Dont understand Diesel

Discussion in 'AutoCAD' started by Rick Keller, Mar 10, 2005.

  1. Rick Keller

    Rick Keller Guest

    I am trying to place a field in a piece of text that gets the sheet number
    from the filename.

    My file name.... 05015-S4.dwg.

    $(SUBSTR,$(GETVAR,DWGNAME),7,2)

    Will return S4

    and if I have a filename of 05015-S15
    I know how to get S15

    $(SUBSTR,$(GETVAR,DWGNAME),7,3)

    I just cant figure out how to write an IF statement to work for both, here
    is what I have so far:

    $(IF,$(=,$(SUBSTR,$(GETVAR,DWGNAME),10,1),"."),$(SUBSTR,$(GETVAR,DWGNAME),7,2),$(SUBSTR,$(GETVAR,DWGNAME),7,3))

    it returns.... $(IF,??)



    Rick
     
    Rick Keller, Mar 10, 2005
    #1
  2. I haven't used Diesel much at all, but if "substr" works similarly to the
    way it does in Lisp, you can just omit the ",2" or ",3" at the end, and it
    will start with the seventh character, and give you the rest of the string,
    no matter how long that is.
     
    Kent Cooper, AIA, Mar 10, 2005
    #2
  3. Rick Keller

    Rick Keller Guest

    That would be fine but I only need 2 or 3 characters.

    The rest of the string would be S4.dwg etc. But I only want S4

    Rick
     
    Rick Keller, Mar 10, 2005
    #3
  4. (I should have thought of that.) Again, in Lisp terms that I hope translate
    easily enough into Diesel:

    (setq lengthwithfiletype (- (strlen (getvar "dwgname")) 4));; saves how many
    characters there are in the drawing name, without the ".dwg" at the end.
    (setq nameonly (substr (getvar "dwgname") 1 lengthwithfiletype);; saves that
    name only, without the filetype designation.
    (substr nameonly 7);; returns that shorter name with its first 6 characters
    removed, which should be what you're looking for.
     
    Kent Cooper, AIA, Mar 10, 2005
    #4
  5. Rick Keller

    Rick Keller Guest

    I understand but I am looking for the Diesel code not lisp code.

    Rick
     
    Rick Keller, Mar 10, 2005
    #5
  6. Rick Keller

    Jürg Menzi Guest

    Hi Rick

    How about:
    $(substr, $(getvar, DWGNAME), 7, $(-, $(strlen, $(getvar, DWGNAME)), 11))

    Cheers
     
    Jürg Menzi, Mar 10, 2005
    #6
  7. Try eq instead of =, from the help files,

    = (equal to)
    If the numbers val1 and val2 are equal, the string returns 1; otherwise, it returns 0.

    eq
    If the strings val1 and val2 are identical, the string returns 1; otherwise, it returns 0.

    So

    $(IF,$(eq,$(SUBSTR,$(GETVAR,DWGNAME),10,1),"."),$(SUBSTR,$(GETVAR,DWGNAME),7,2),$(SUBSTR,$(GETVAR,DWGNAME),7,3))

    should work
     
    Marco Jacinto, Mar 10, 2005
    #7
  8. Rick Keller

    Rick Keller Guest

    Almost worked.... I just had to tweak the number a little....

    I like the way this looks it is alot shorter than what I had.

    Once again Juerg you helped me out.

    Thanks,
    Rick
     
    Rick Keller, Mar 10, 2005
    #8
  9. Rick Keller

    Rick Keller Guest

    Thanks Marco,

    You did indeed fix my problem with what I had.
    I was looking in the help files and found this statement which is what I was trying to follow:

    $(if,$(=,$(getvar,cvport),1),mspace,pspace)

    But I will remember to use eq.

    Thanks
    Rick


    Try eq instead of =, from the help files,

    = (equal to)
    If the numbers val1 and val2 are equal, the string returns 1; otherwise, it returns 0.

    eq
    If the strings val1 and val2 are identical, the string returns 1; otherwise, it returns 0.

    So

    $(IF,$(eq,$(SUBSTR,$(GETVAR,DWGNAME),10,1),"."),$(SUBSTR,$(GETVAR,DWGNAME),7,2),$(SUBSTR,$(GETVAR,DWGNAME),7,3))

    should work
     
    Rick Keller, Mar 10, 2005
    #9
  10. Rick Keller

    Jürg Menzi Guest

    Glad to help you...¦-)

    Cheers
     
    Jürg Menzi, Mar 11, 2005
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.