Results 1 to 7 of 7

Thread: Help With Logic Syntax

  1. #1
    I could stop if I wanted to
    Join Date
    2015-09
    Posts
    420
    Login to Give a bone
    0

    Default Help With Logic Syntax

    Hello AUGI Members,

    I am trying to write some simple code and my mind went brain dead on me....!

    I have a lisp routine that counts the number of instances of a specific block (MYblock). Once I have that count I want to do the following:

    1) If the count is equal to and less than 9 do "X"
    2) If the count is equal to and greater than 10 but less than 100 do "Y"
    3) If the count is equal to and greater than 100 do "Z"


    Any assistance would be appreciated.....!


    Regards,
    Vince

  2. #2
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Help With Logic Syntax

    Code:
    (defun foo (c)
      (cond ((<= c 9) (alert "A"))
            ((< c 100) (alert "B"))
            ((>= c 100) (alert "C"))
      )
    )

  3. #3
    I could stop if I wanted to
    Join Date
    2015-09
    Posts
    420
    Login to Give a bone
    0

    Default Re: Help With Logic Syntax

    Alan,

    Thank you for your response however, I am having difficulty getting it to work properly. Here is the segnemt of the code:

    Code:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun DSETCNO ()
      (setvar "cmdecho" 0)
      (SETQ BLOCKSET NIL)
    
       (setq blockset (ssget "X" (list (cons 2 "Cord-Dot*"))))
    
       (if (= blockset nil)(CIBN))
       (if (/= blockset nil)(CGBN))
    )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;
    ;;;;;ZERO INITIAL BLOCKS SO INPUT COORDINATE NUMBER
    ;;;;;
    (defun CIBN ()
      (SETQ CON 1)
    
      (SETQ CNx (RTOS CON 2 0))
    
    (foo)
    
        (setq CN (getstring (strcat "\n...Enter Coordinate ID Number..." "<" CNx2 ">")))
          (if (= CN "") (setq CN CNx2) (setq CN CN) )
            (setq CON CN)   
    
    )
    
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;
    ;;;;;OBTAIN TOTAL FROM DRAWING
    ;;;;;
      (defun CGBN ()
     (setq total (sslength blockset))
     (setq CON (+ total 1))
     
        (SETQ CNx (RTOS CON 2 0))
    
    (foo)
    
        (Princ "...\n")
        (setq CN (getstring (strcat "\n...Enter Coordinate ID Number..." "<" CNx2 ">")))
          (if (= CN "") (setq CN CNx2) (SETQ CN CN) )
            (setq CON CN)
     )
    
    (defun foo (CON)
      (cond ((<= CON 9) (alert "A"))
            ((< CON 100) (alert "B"))
            ((>= CON 100) (alert "C"))
      )
    )

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

    Default Re: Help With Logic Syntax

    Are you trying to evaluate a string to an integer? They are different.
    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

  5. #5
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Help With Logic Syntax

    You have to evaluate the subroutine as such:

    Code:
    (foo 25)
    25 being whatever number you choose.

  6. #6
    I could stop if I wanted to
    Join Date
    2015-09
    Posts
    420
    Login to Give a bone
    0

    Default Re: Help With Logic Syntax

    What I am trying to do is basically simple.......count the number of block instances on a drawing and then based on that count add 1 or 2 zero's in front of the number:

    For example....

    1) If the count was equal to or less than 9................add two zero's = 009
    2) If the count was greater than 9 but less than 100.....add one zero = 099
    3) If the count was greater than 100..............leave the number as is = 100

    This value will then be placed into an attribute block on the drawing.

  7. #7
    AUGI Addict
    Join Date
    2008-02
    Posts
    1,141
    Login to Give a bone
    0

    Default Re: Help With Logic Syntax

    Here, use this (just convert the integer to a string first):

    Code:
    (defun AT:NumFix (s n)
      ;; Fix number string with leading zeros
      ;; s - Number string to fix
      ;; n - Number of characters for final string
      ;; Alan J. Thompson, 10.29.09
      (if (< (strlen s) n)
        (AT:NumFix (strcat "0" s) n)
        s
      )
    )
    Code:
    Command: (at:numfix "3" 3)
    "003"
    
    Command: (at:numfix "3" 2)
    "03"
    
    Command: (at:numfix "3" 5)
    "00003"

Similar Threads

  1. How To Find Blocks (Logic)
    By ettore_c in forum Dot Net API
    Replies: 25
    Last Post: 2015-02-20, 02:37 PM
  2. Help With Logic Options
    By CADdancer in forum AutoLISP
    Replies: 8
    Last Post: 2008-09-25, 10:56 PM
  3. Allow OR logic in filters
    By revit.wishlist1942 in forum Revit Architecture - Wish List
    Replies: 3
    Last Post: 2007-09-17, 11:38 AM
  4. Logic - Syntax to use Yes/No to control another Yes/No
    By christo4robin in forum Revit Architecture - Families
    Replies: 2
    Last Post: 2006-03-20, 02:53 PM
  5. Logic Statements
    By weston in forum Revit Architecture - Families
    Replies: 2
    Last Post: 2006-03-20, 02:39 AM

Posting Permissions

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