See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Adjust revision number

  1. #1
    Member
    Join Date
    2020-03
    Posts
    7
    Login to Give a bone
    0

    Default Adjust revision number

    Hi Peter, I just came across this thread and it's just what I need right now. I've been searching in vain for a code sample for a loop construct that will do what I need. LISP is a new language to me and I'm finding that it's difficult to make a loop do what I need. It doesn't help that I can't understand a lot of the examples put out there on loops. At this point in my LISP education I need a more robust example. Anyway on to my question.

    Background:
    I am writing a utility to automatically increment the rev letter or number of legacy title blocks that are still used at our company.

    The section of code:
    I am building this routine a section at a time. The section I am working on involves a loop that takes the current rev (if it's a letter) and increments it by 1.
    Having found no code samples I can understand to use as a template, my idea was to set up a list of the possible values. In our case that would be A-Z and AA-ZZ. I then loop through this list comparing the current rev letter value. As I loop I am counting. Once I have a match I capture the count and add 1 which is then used to get the nth letter of my list as the new letter rev. The code, which follows, is just the initial matching section and it does work. However, the failure is that once I have the match I am setting the condition that should end the while loop but it appears that the while condition is not evaluated. I am sure it's because of the structure of my loop but am at a loss as to how to correct it. I'm betting the foreach loop nested inside the while is just going to keep running. I tried to find a way to break out of the foreach loop but can't find anything that works in LISP. Sorry for the juvenile effort but I have to start somewhere.

    Variables used:
    arrLetters (the list of letters to compare to)
    strLetter (the current rev level)
    letter (the current member of arrLetters)
    haveMatch (my trigger to supposedly exit the loop)
    cntLetter (the counter to actually increment the rev letter)
    lstLetter (the last count at the time of match)

    I also have some alerts in there to make sure things are happening the way I hoped these will be removed.

    Code:
    (while (/= 1 haveMatch)
    	(foreach letter arrLetters
                    ;; Just making sure my count and letters are changing correctly TBR
    		(alert (strcat (itoa cntLetter) " Letter is " letter))
    		(if (equal letter strLetter)
    			(progn
                                    ;; Verify that I actually find a match TBR
    				(alert "We have a match!")
    				(setq lstLetter letter)
    				(setq haveMatch 1)
    				(setq cntMatch cntLetter)
    				(setq cntLetter (1+ cntLetter))	
    			);end progn	
    			(setq cntLetter (1+ cntLetter))
    		);end if
    	);end foreach		
    );end while

  2. #2
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    555
    Login to Give a bone
    1

    Default Re: Adjust revision number

    If your max is A-Z then its easy as (ascii "A") will return 65 so (chr 66) = B. Again can look up the 0-9 (ascii "0") = 48. If you have "AB" can use a slightly different method pulling the string apart so get 65 & 66.

    So just need a (if (= strlen txt) 1) means a single character, then use (asscii the issue is once you get to Z = 90 you need to add "A" do you really get to "AA" ?

    Ps would have been better starting a new post.

    (setq x (ascii txt))
    (princ (chr (+ x 1)))

  3. #3
    Member
    Join Date
    2020-03
    Posts
    7
    Login to Give a bone
    1

    Default Re: Adjust revision number

    Oh man, talk about slow on the uptake. At first I was confused because I was asking about looping and I thought this was a situation that required one. But after thinking about the information you provided, BIG-AL, I realized I was looking at the problem all wrong. Your answer is pure gold and elegantly solves my dilema. Realisticly we should never need the AA-ZZ but when dealing with a ton of legacy drawings I wanted to be prepared. Believe it or not I have worked on drawings that have gone quite deep into the double alpha characters.

    Thank you so much for taking the time to help out!

  4. #4
    Member
    Join Date
    2020-03
    Posts
    7
    Login to Give a bone
    0

    Default Re: Adjust revision number

    Quote Originally Posted by BIG-AL View Post
    So just need a (if (= strlen txt) 1) means a single character
    Ok, I'm missing something here. Using (strlen txt) I do indeed get the length of the string. But when I try to use it in the 'if' statement and compare it as shown I keep getting a syntax error. I thought it might be because I needed an opening paren on strlen txt like
    Code:
     (if (= (strlen txt) 1)
    but that gave me a syntax error as well.

    I also tried setting strlen txt to a variable then using that in the comparison but no dice.

  5. #5
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,096
    Login to Give a bone
    0

    Default Re: Adjust revision number

    Is the value of the variable "txt" a string? Is a value even assigned to this variable? What is the error given?
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  6. #6
    Member
    Join Date
    2020-03
    Posts
    7
    Login to Give a bone
    0

    Default Re: Adjust revision number

    txt in this case is a revision character it could be a number 0-9 or a letter A-Z or AA-AZ. The trouble I am having is deciding if it's a letter or a number. If there was a way to determine if a variable is a number or string like there is in other programming languages it would be a lot easier. In LISP if I can do numberp but if it's a letter (string) it will error out. If I do an (ascii txt) and it's a number then it will error out. If I do (ascii (itoa txt)) and it's a string it will error out. I'm missing a big part of the picture here. The piece of the puzzle that will allow me to look at any character number or letter and determine whether it's a number or a letter without crashing.

  7. #7
    Member
    Join Date
    2020-03
    Posts
    7
    Login to Give a bone
    0

    Default Re: Adjust revision number

    I've tried using
    Code:
    (type txt)
    which seems to work for either.

    I can do:
    Code:
    (setq txt "A")
    (type txt)
    STR
    or

    Code:
    (setq txt 9)
    (type txt)
    INT
    And no matter what the txt is (string or number) this works. However, I again get a syntax error if I try to do a comparison with the type results.

    Code:
    (setq txt 9)
    (if (= (type txt) INT)
        ;if true
        ;if false
    )
    error: syntax error
    I suppose now I've departed completely from the loop question and should actually follow BIG-AL's advice and start a new thread but I'm not sure how to do that and preserve this one? Any thoughts?

  8. #8
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,658
    Login to Give a bone
    1

    Default Re: Adjust revision number

    Quote Originally Posted by lxmichels788340 View Post
    txt The trouble I am having is deciding if it's a letter or a number. If there was a way to determine if a variable is a number or string like there is in other programming languages it would be a lot easier.
    Not sure what you mean by numberp erroring out.

    Both
    Code:
    (numberp  "revision character")
    and
    Code:
    (< 47 (ascii "revision character") 58)
    will return T if it's a number or nil otherwise.
    So (if (numberp "revision character") "Then whatever you want to do if it's a number" "or what to do if it's not")

  9. #9
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,096
    Login to Give a bone
    0

    Default Re: Adjust revision number

    Quote Originally Posted by lxmichels788340 View Post
    Code:
    (setq txt 9)
    (if (= (type txt) INT)
        ;if true
        ;if false
    )
    error: syntax error
    I suppose now I've departed completely from the loop question and should actually follow BIG-AL's advice and start a new thread but I'm not sure how to do that and preserve this one? Any thoughts?

    You will need to add a single quote before the INT. Otherwise, the INT will be considered a variable and not the type you think you are comparing it to.
    Code:
    (if (= (type txt) 'INT)
      ;if true
      ;if false
    )
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  10. #10
    Member
    Join Date
    2020-03
    Posts
    7
    Login to Give a bone
    0

    Default Re: Adjust revision number

    Thank you Opie, That not only did the trick but pointed out something I was unaware of. I do very much appreciate all the answers so far since they are helping me a great deal!
    I am learning a great deal more from this one post than just my original question.

    That being said, I would like to get back to the original question of my post which is Why is the While condition not exiting the loop when the haveMatch variable is set to 1?
    That was supposed to be my trigger to exit the while loop but even after haveMatch has been set the loop continues for all of the letters in my list (52).

Page 1 of 2 12 LastLast

Similar Threads

  1. Internal Revision VS External Revision
    By darthyoga in forum CAD Management - General
    Replies: 6
    Last Post: 2012-03-21, 04:47 PM
  2. Halftone option for showing revision clouds within revision manager.
    By Wish List System in forum Revit Architecture - Wish List
    Replies: 0
    Last Post: 2011-12-02, 04:22 PM
  3. Revision Clouds line weight different per Revision
    By billy007nh in forum Revit Architecture - General
    Replies: 7
    Last Post: 2010-11-18, 05:55 PM
  4. How do I delete a revision from the revision schedule?
    By Blakester122 in forum Revit MEP - General
    Replies: 2
    Last Post: 2009-10-20, 02:24 PM
  5. Revision Delta in Revision Schedule.
    By doh in forum Revit Architecture - General
    Replies: 6
    Last Post: 2009-08-13, 06:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •