Page 1 of 6 12345 ... LastLast
Results 1 to 10 of 53

Thread: trying to write rev routine - need help with cond statement

  1. #1
    I could stop if I wanted to
    Join Date
    2007-05
    Location
    Brookfield WI
    Posts
    331
    Login to Give a bone
    0

    Default trying to write rev routine - need help with cond statement

    I can get it to ask the question but can't it to begin pline...not sure if my "if" is correct...


    Code:
    (defun C:rv (/ inp)
        (setq OldLayer (getvar "CLAYER" ) )        ; save current settings current layer
    
      (initget 0 "1 2 3" ) ; ask for input
      (setq Inp
        (cond 
          ((getkword "\nWhich Revision is this? [1/2/3] <1>: " ) );get keyword from user
          ( "1" ) ;default keyword
        )
    	)
        (if (= Inp "1" ) ; check the input and create/set layer
        (progn
          (if (not (tblsearch "LAYER" "rev1" )) ; if the layer does not exist, create it
            (command "_.layer" "n" "rev1" "c" "green" "rev1" "lt" "continuous" "rev1" "" )
            ( ) ; if the layer exist
          )
    ;;;      (setvar "CLAYER" rev1) ; set the layer current
        )
        (progn
          (if (not (tblsearch "LAYER" "rev2" )) ; if the layer does not exist, create it
            (command "_.layer" "n" "rev2" "c" "green" "rev2" "lt" "continuous" "rev2" "" )
            ( ) ; if the layer exist
          )
    ;;;      (setvar "CLAYER" rev2) ; set the layer current
        )
        (progn
          (if (else (tblsearch "LAYER" "rev3" )) ; if the layer does not exist, create it
            (command "_.layer" "n" "rev3" "c" "green" "rev3" "lt" "continuous" "rev3" "" )
            ( ) ; if the layer exist
          )
    ;;;      (setvar "CLAYER" rev3) ; set the layer current
        )
      );end of if
      
    
      (command "._pline") ; create objects draw pline

  2. #2
    AUGI Addict .T.'s Avatar
    Join Date
    2000-12
    Location
    Lost
    Posts
    1,473
    Login to Give a bone
    0

    Default Re: trying to write rev routine - need help with cond statement

    Maybe this would be easier and doesn't limit you to three revs?

    Code:
    (defun C:rv (/ Oldlayer Oldcmdecho inp layname)
      (setq OldLayer (getvar "CLAYER" ))         ; save current settings current layer
      (setq OldCmdecho (getvar "cmdecho"))   ; save current cmdecho
      (setq inp (getint "Revision Number: "))    ; get revision number as integer
      (setq layname (strcat "rev" (itoa inp)))   ; add the integer to rev
      (if (tblsearch "layer" layname)            ; if the layer exists...
        (setvar "clayer" layname)		     ; just set it	
        (progn                                   ; else create it, then set it
          (command "_.layer" "n" layname "c" "green" layname "lt" "continuous" layname "")
          (setvar "clayer" layname)
        )
      )
      (command "pline")                          ; start the pline command  
      (setvar "cmdecho" 1)                       ; turn on cmdecho so you can see the pline prompts
      (while (= 1 (logand (getvar "CMDACTIVE") 1))(command pause)) ;draw the pline
      (setvar "cmdecho" Oldcmdecho)              ; reset cmdecho
      (setvar "clayer" Oldlayer)                 ; reset layer
      (princ)
    )
    HTH

  3. #3
    I could stop if I wanted to
    Join Date
    2007-05
    Location
    Brookfield WI
    Posts
    331
    Login to Give a bone
    0

    Default Re: trying to write rev routine - need help with cond statement

    Quote Originally Posted by timcreary View Post
    Maybe this would be easier and doesn't limit you to three revs?

    Code:
    (defun C:rv (/ Oldlayer Oldcmdecho inp layname)
      (setq OldLayer (getvar "CLAYER" ))         ; save current settings current layer
      (setq OldCmdecho (getvar "cmdecho"))   ; save current cmdecho
      (setq inp (getint "Revision Number: "))    ; get revision number as integer
      (setq layname (strcat "rev" (itoa inp)))   ; add the integer to rev
      (if (tblsearch "layer" layname)            ; if the layer exists...
        (setvar "clayer" layname)		     ; just set it	
        (progn                                   ; else create it, then set it
          (command "_.layer" "n" layname "c" "green" layname "lt" "continuous" layname "")
          (setvar "clayer" layname)
        )
      )
      (command "pline")                          ; start the pline command  
      (setvar "cmdecho" 1)                       ; turn on cmdecho so you can see the pline prompts
      (while (= 1 (logand (getvar "CMDACTIVE") 1))(command pause)) ;draw the pline
      (setvar "cmdecho" Oldcmdecho)              ; reset cmdecho
      (setvar "clayer" Oldlayer)                 ; reset layer
      (princ)
    )
    HTH

    thats pretty cool code, but the reason I want to write it the way I had it is so that I can insert the rev sym per user input.

    I have stuff to add to it yet, to be continued later I guess
    Last edited by d_m_hopper; 2007-09-14 at 07:53 PM.

  4. #4
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: trying to write rev routine - need help with cond statement

    This should do it.
    Code:
     (defun C:rv (/ inp)
      (setq OldLayer (getvar "CLAYER" ) )        ; save current settings current layer
      (initget 0 "1 2 3" ) ; ask for input
      (setq Inp (getkword "\nWhich Revision is this? [1/2/3] <1>: " ) );get keyword from user
      (princ "\nInp = ")(princ Inp) 
      (cond 
        ((or(= Inp "1" )(= Inp nil)) ; check the input and create/set layer
          (if (tblsearch "LAYER" "rev1" )(command "_.layer" "t" "rev1" "")) ; can't set a frozen layer current
          (command "_.layer" "m" "rev1" "c" "green" "rev1" "lt" "continuous" "rev1" "" )
        )
        ((= Inp "2" ) ; check the input and create/set layer
          (if (tblsearch "LAYER" "rev2" )(command "_.layer" "t" "rev2" "")) ; can't set a frozen layer current
          (command "_.layer" "m" "rev2" "c" "green" "rev2" "lt" "continuous" "rev2" "" )
        )
        ((= Inp "3" ) ; check the input and create/set layer
          (if (tblsearch "LAYER" "rev3" )(command "_.layer" "t" "rev3" "")) ; can't set a frozen layer current
          (command "_.layer" "m" "rev3" "c" "green" "rev3" "lt" "continuous" "rev3" "" )
        )
        (T (princ "\nI give up!"))
      );end of cond
     
      (command "._pline") ; create objects draw pline
      (while (= 1 (logand 1 (getvar "cmdactive")))
        (command PAUSE)
      )
      (setvar "CLAYER" OldLayer)        ; restore current layer
      (princ "\nIt worked!")
      (princ)
    )

  5. #5
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: trying to write rev routine - need help with cond statement

    Stealing ideas from CAB2k and trying to avoid messy -layer command calls. This is better.
    Code:
    (defun C:rv (/ inp rev OldLayer)
      (setq OldLayer (getvar "CLAYER")) ; save current settings current layer
      (initget "1 2 3 4") ; ask for input
      (setq Inp (getkword "\nWhich Revision is this? [1/2/3/4] <1>: "))
      (or Inp (setq Inp "1"))
      (setq rev (strcat "rev" Inp))
      (setq doc  (vla-get-activeDocument (vlax-get-acad-object)) ;;;get current drawing
           lyrs  (vla-get-layers doc)                            ;;;get layer collection
           name (strcat "rev" Inp)
      )
      (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list lyrs name))) ;;;check to see if layer exists
        (setq lyr (vla-add lyrs name)) ;;;add new layer to layer collection and capture the new layer
        (setq lyr (vlax-ename->vla-object (tblobjname "layer" "rev1")))
      )
      (vla-put-Color lyr 3)      ;;;change the color of the new layer
      (vla-put-LineType lyr "Continuous")   ;;;change the linetype of the new layer
      (vla-put-Freeze lyr 0)      ;;;thaw the new layer
      (vla-put-LayerOn lyr -1)      ;;;turn the new layer on
      (vla-put-Lock lyr 0)      ;;;unlock the new layer
      (setvar "CLAYER" name) ; set the layer current
      (command "._pline") ; create objects draw pline
      (while (= 1 (logand 1 (getvar "cmdactive")))
        (command PAUSE)
      )
      (setvar "CLAYER" OldLayer) ; restore current layer
      (princ)
    )

  6. #6
    I could stop if I wanted to
    Join Date
    2007-05
    Location
    Brookfield WI
    Posts
    331
    Login to Give a bone
    0

    Default Re: trying to write rev routine - need help with cond statement

    how about this?

    I have a 3 routines...

    One for rev 1, one for rev 2, and one for rev 3

    each routine puts text on our TB REV 1 9/22/07 with a revision symbol next to the text, then you cloud what changed and the rev symbol comes in at the pointer and is placed by the user.

    How can I use a condition statement that would run the proper routine based on user input?

    If 1 run rev1 if 2 run rev2 if 3 run rev3......make sense?

    If I can figure out ifs I could do so much more, in the learning process so please bear with me.

  7. #7
    All AUGI, all the time CAB2k's Avatar
    Join Date
    2016-01
    Location
    Brandon, Florida
    Posts
    687
    Login to Give a bone
    0

    Default Re: trying to write rev routine - need help with cond statement

    Without seeing the other routine I can not guarantee this will work but the idea
    is as follows. Based on Tom's last routine.

    Code:
    (defun C:rv (/ inp rev OldLayer)
      (setq OldLayer (getvar "CLAYER")) ; save current settings current layer
      (initget "1 2 3 4") ; ask for input
      (setq Inp (getkword "\nWhich Revision is this? [1/2/3/4] <1>: "))
      (or Inp (setq Inp "1"))
      (setq rev (strcat "rev" Inp))
      (setq doc  (vla-get-activeDocument (vlax-get-acad-object)) ;;;get current drawing
           lyrs  (vla-get-layers doc)                            ;;;get layer collection
           name (strcat "rev" Inp)
      )
      (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list lyrs name))) ;;;check to see if layer exists
        (setq lyr (vla-add lyrs name)) ;;;add new layer to layer collection and capture the new layer
        (setq lyr (vlax-ename->vla-object (tblobjname "layer" "rev1")))
      )
      (vla-put-Color lyr 3)      ;;;change the color of the new layer
      (vla-put-LineType lyr "Continuous")   ;;;change the linetype of the new layer
      (vla-put-Freeze lyr 0)      ;;;thaw the new layer
      (vla-put-LayerOn lyr -1)      ;;;turn the new layer on
      (vla-put-Lock lyr 0)      ;;;unlock the new layer
      (setvar "CLAYER" name) ; set the layer current
    
      ;;  ==============
      (cond
        ((= inp "1")  (rev1_routine))
        ((= inp "2")  (rev2_routine))
        ((= inp "3")  (rev3_routine))
      )
      ;;  ==============
      
      
      (setvar "CLAYER" OldLayer) ; restore current layer
      (princ)
    )

    But note that you can alter the rev routines and make one routine out of them.
    If you post the routine someone will help you accomplish that.

  8. #8
    I could stop if I wanted to
    Join Date
    2007-05
    Location
    Brookfield WI
    Posts
    331
    Login to Give a bone
    0

    Default Re: trying to write rev routine - need help with cond statement

    thanks I will post the routines Monday, as they are stored on my PC at work

  9. #9
    I could stop if I wanted to
    Join Date
    2007-05
    Location
    Brookfield WI
    Posts
    331
    Login to Give a bone
    0

    Default Re: trying to write rev routine - need help with cond statement

    Quote Originally Posted by d_m_hopper View Post
    thanks I will post the routines Monday, as they are stored on my PC at work
    here are the three routines, currently in a pulldown menu....I would like to combine them based on user input..

    Code:
    **REV1**
    
    (defun triangle1 ()
       (command
          "polygon" "3" bp "c" "5"
       )
       (setq tr (list (car bp) (+ (cadr bp) 10)))
       (command
          "ortho" "off"
          "move" tr "" bp pause
       )
    (setvar "filedia" 0)
    (setq tx (getvar "lastpoint"))
       (command
          "color" "magenta"
          "text" "s" "dmt" "j" "m" tx "0" "1"
          "color" "green"
       )
       (setq tr (list (car (getvar "lastpoint")) (+ (cadr (getvar "lastpoint")) 10)))
       (command
          "copy" "c" tx tr "" tx "1598.7021,-997.0960"
       )
       (setq id (list '1610.7021 '-1002.0960))
       (command
          "text" "s" "dmt" "j" "bl" id 0
       )
       (prompt "\nInitials and Date, <ex. ABC - 4/16/93>: ")
    (setvar "filedia" 1)
    )
    
    (defun c:rev1 ()
       (princ)
       (setq sp nil)
       (setq bp nil)
       (setq ep nil)
       (setq sp (getpoint "Startpoint of Rev.1 Cloud: "))
       (setq bp sp)
       (while
          (not (equal ep bp))
          (command
             "arc" sp pause pause
          )
          (setq ep (getvar "lastpoint"))
          (setq sp ep)
       )
    (triangle1)
    )
    Code:
    **REV2**
    
    (defun triangle2 ()
       (command
          "polygon" "3" bp "c" "5"
       )
       (setq tr (list (car bp) (+ (cadr bp) 10)))
       (command
          "ortho" "off"
          "move" tr "" bp pause
       )
    (setvar "filedia" 0)
    (setq tx (getvar "lastpoint"))
       (command
          "color" "magenta"
          "text" "s" "dmt" "j" "m" tx "0" "2"
          "color" "green"
       )
       (setq tr (list (car (getvar "lastpoint")) (+ (cadr (getvar "lastpoint")) 10)))
       (command
          "copy" "c" tx tr "" tx "1598.7021,-1021.0960"
       )
       (setq id (list '1610.7021 '-1026.0960))
       (command
          "text" "s" "dmt" "j" "bl" id 0
       )
       (prompt "\nInitials and Date, <ex. ABC - 4/16/93>: ")
    (setvar "filedia" 1)
    )
    
    (defun c:rev2 ()
       (princ)
       (setq sp nil)
       (setq bp nil)
       (setq ep nil)
       (setq sp (getpoint "Startpoint of Rev.2 Cloud: "))
       (setq bp sp)
       (while
          (not (equal ep bp))
          (command
             "arc" sp pause pause
          )
          (setq ep (getvar "lastpoint"))
          (setq sp ep)
       )
    (triangle2)
    )
    Code:
    **REV3**
    
    (defun triangle3 ()
       (command
          "polygon" "3" bp "c" "5"
       )
       (setq tr (list (car bp) (+ (cadr bp) 10)))
       (command
          "ortho" "off"
          "move" tr "" bp pause
       )
    (setvar "filedia" 0)
    (setq tx (getvar "lastpoint"))
       (command
          "color" "magenta"
          "text" "s" "dmt" "j" "m" tx "0" "3"
          "color" "green"
       )
       (setq tr (list (car (getvar "lastpoint")) (+ (cadr (getvar "lastpoint")) 10)))
       (command
          "copy" "c" tx tr "" tx "1598.7021,-1045.0960"
       )
       (setq id (list '1610.7021 '-1050.0960))
       (command
          "text" "s" "dmt" "j" "bl" id 0
       )
       (prompt "\nInitials and Date, <ex. ABC - 4/16/93>: ")
    (setvar "filedia" 1)
    )
    
    (defun c:rev3 ()
       (princ)
       (setq sp nil)
       (setq bp nil)
       (setq ep nil)
       (setq sp (getpoint "Startpoint of Rev.3 Cloud: "))
       (setq bp sp)
       (while
          (not (equal ep bp))
          (command
             "arc" sp pause pause
          )
          (setq ep (getvar "lastpoint"))
          (setq sp ep)
       )
    (triangle3)
    )

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

    Default Re: trying to write rev routine - need help with cond statement

    Would this Revision Cloud routine work for you? You would need to create an attributed block for your numbered triangle.

    Most of the three routines are similar. There is a difference in each routine on the (command "copy"... and the (setq id.. lines. Other than that, they are the same routine.
    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

Page 1 of 6 12345 ... LastLast

Similar Threads

  1. Replies: 16
    Last Post: 2012-07-16, 07:41 PM
  2. COND Statement to Setq Variable
    By stusic in forum AutoLISP
    Replies: 9
    Last Post: 2012-04-05, 08:47 PM
  3. Routine skipping over cond. statement. . why?
    By M. Kubitza in forum AutoLISP
    Replies: 11
    Last Post: 2010-01-13, 11:04 PM
  4. Using commands in a cond statement
    By eleonard in forum AutoLISP
    Replies: 14
    Last Post: 2007-02-27, 06:07 PM
  5. Replies: 12
    Last Post: 2006-01-10, 09:38 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
  •