Filtering out all but lines & conditional help...

Discussion in 'AutoCAD' started by akdrafter, Dec 16, 2003.

  1. akdrafter

    akdrafter Guest

    Hello, I have attatched a routine that I wrote. What it does is ask a user for a line to offset, and then change the layer of the offset line. Trouble is, it does not work if you select anything but a line. So, can someone help me with the code to alert the user that you can only select a line and nothing else. Basically if anything other than a line is selected alert the user and ask them to select again. Thanks in advance. Apparently you can not attatch lisp files. So I am pasting the code in here.
    ;;;
    ;;; By Timothy J. Jaronik Sr.
    ;;; December, 2003
    ;;
    ;;
    ;;;;;;;;;;;;;;;ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;

    (defun *ERROR* (msg)
    (princ "\nerror: ")
    (if msg (princ msg))
    (setvar "CMDECHO" CMDECHO)
    (setvar "CLAYER" CLAYER)
    (setvar "OSMODE" OSMODE)
    (setvar "SNAPMODE" SNAPMODE)
    (command "._undo" "end")
    (princ "\nType \"u\" to undo")
    (princ)
    );ERROR

    ;;;;;;;;;;;;;;;END ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;

    (defun c:SWW ( / clayer cmdecho osmode snapmode L1 L2)
    (setq CMDECHO(getvar "CMDECHO"))
    (setq CLAYER(getvar "CLAYER"))
    (setvar "CMDECHO" 0)
    (setq OSMODE(getvar "OSMODE"))
    (setvar "OSMODE" 0)
    (setq SNAPMODE(getvar "SNAPMODE"))
    (setvar "SNAPMODE" 0)
    (command "._undo" "begin")
    (command "-layer" "thaw" "S-SHEAR" "on" "LAY1" "make" "LAY1" "color" "1" "LAY1" "lt" "hidden" "LAY1" "")
    (setq L1(entsel "\n Select Line: "))
    (command "offset" "3" L1 pause "")
    (setq L2(entlast))
    (command "change" L2 "" "p" "layer" "LAY1" "color" "bylayer" "lt" "bylayer" "")
    (command "pedit" L2 "Y" "w" "1.00000000" "")
    (setvar "CMDECHO" CMDECHO)
    (setvar "CLAYER" CLAYER)
    (setvar "OSMODE" OSMODE)
    (setvar "SNAPMODE" SNAPMODE)
    (command "._undo" "end")
    (princ)
    );end of function
     
    akdrafter, Dec 16, 2003
    #1
  2. akdrafter

    ECCAD Guest

    Akdrafter,
    Try the following:
    ;;;
    ;;; By Timothy J. Jaronik Sr.
    ;;; December, 2003
    ;;
    ;;
    ;;;;;;;;;;;;;;;ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;

    (defun *ERROR* (msg)
    (princ "\nerror: ")
    (if msg (princ msg))
    (setvar "CMDECHO" CMDECHO)
    (setvar "CLAYER" CLAYER)
    (setvar "OSMODE" OSMODE)
    (setvar "SNAPMODE" SNAPMODE)
    (command "._undo" "end")
    (princ "\nType \"u\" to undo")
    (princ)
    );ERROR

    ;;;;;;;;;;;;;;;END ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;

    (defun c:SWW ( / clayer cmdecho osmode snapmode L1 L2 ent ty_ent)
    (setq CMDECHO(getvar "CMDECHO"))
    (setq CLAYER(getvar "CLAYER"))
    (setvar "CMDECHO" 0)
    (setq OSMODE(getvar "OSMODE"))
    (setvar "OSMODE" 0)
    (setq SNAPMODE(getvar "SNAPMODE"))
    (setvar "SNAPMODE" 0)
    (command "._undo" "begin")
    (command "-layer" "thaw" "S-SHEAR" "on" "LAY1" "make" "LAY1" "color" "1" "LAY1" "lt" "hidden" "LAY1" "")
    ;; Modified..
    (setq L1 (entsel "\nSelect Line: "))
    (setq ent (entget (car L1))); get entity List
    (setq ty_ent (cdr (assoc 0 ent))); get type
    (if (= ty_ent "LINE")
    (progn
    (command "offset" "3" L1 pause "")
    (setq L2(entlast))
    (command "change" L2 "" "p" "layer" "LAY1" "color" "bylayer" "lt" "bylayer" "")
    (command "pedit" L2 "Y" "w" "1.00000000" "")
    ); end progn
    ); end if
    (if (/= ty_ent "LINE")
    (progn
    (Prompt "\nItem selected was not a LINE ")
    ); end progn
    ); end if
    ;; End Modifications..
    (setvar "CMDECHO" CMDECHO)
    (setvar "CLAYER" CLAYER)
    (setvar "OSMODE" OSMODE)
    (setvar "SNAPMODE" SNAPMODE)
    (command "._undo" "end")
    (princ)
    );end of function

    ;; Bob Shaw (EC-CAD)
     
    ECCAD, Dec 16, 2003
    #2
  3. akdrafter

    Joe Burke Guest

    Timothy,

    Try replacing this line (setq L1(entsel "\n Select Line: ")) as follows:

    (while
    (or
    (not (setq L1 (entsel "\nSelect Line: "))) ;missed pick
    (/= "LINE" (cdr (assoc 0 (entget (car L1))))) ;wrong object type
    )
    (princ "\nMissed pick or wrong object type" )
    ) ;while

    Joe Burke


    a line to offset, and then change the layer of the offset line. Trouble is, it
    does not work if you select anything but a line. So, can someone help me with
    the code to alert the user that you can only select a line and nothing else.
    Basically if anything other than a line is selected alert the user and ask them
    to select again. Thanks in advance. Apparently you can not attatch lisp files.
    So I am pasting the code in here.
    "LAY1" "lt" "hidden" "LAY1" "")
     
    Joe Burke, Dec 17, 2003
    #3
  4. akdrafter

    TCEBob Guest

    Here's a revised version. There are many ways to skin this cat. My
    comments are in ; fields. You are probably right to set up error
    handling etc; for my part that adds a lot of baggage to a small routine.
    Again, I dispense with the undo stuff; undo will work anyway.

    Hope it works.

    rs;

    |(defun ERROR (msg)
    (princ "\nerror: ")
    (if msg (princ msg))
    (setvar "CMDECHO" CMDEC)
    ;(setvar "CLAYER" CLAY)
    (setvar "OSMODE" OSMO)
    (setvar "SNAPMODE" SNAPMO)
    (command "._undo" "end")
    (princ "\nType \"u\" to undo")
    (princ)
    )|;;ERROR

    ;;;;;;;;;;;;;;;END ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;
    ;; Offset a line from one layer to another. ONLY LINES!
    (defun c:SWW ( / clay cmdec osmo snapmo L1 L2 lobj sid doitagain) ;rs
    ;Not a good idea to name variables
    ;same as system variables
    (setq CMDEC(getvar "CMDECHO"))
    ;(setq CLAY(getvar "CLAYER")) ;rs don't need
    (setvar "CMDECHO" 0)
    (setq OSMO(getvar "OSMODE"))
    (setvar "OSMODE" 0)
    (setq SNAPMO(getvar "SNAPMODE"))
    (setvar "SNAPMODE" 0)
    (command "._undo" "begin")
    (command "-layer" "thaw" "S-SHEAR" "on" "LAY1" "new" "LAY1" ;rs make
    ;puts you in the new layer
    "color" "1" "LAY1" "lt" "hidden" "LAY1" "") ; rs um, what does
    ;s-shear have to do with this?
    (setq doitagain "yes")

    (while (= doitagain "yes")
    (setq lobj(car(entsel "\n Select Line: ")))
    (redraw lobj 3) ;rs highlight the line
    (setq sid(getpoint "\nSide to offset to: ")) ;rs Offset will not ask
    ;for a point during pause.
    (if (= (cdr (assoc 0 (entget lobj))) "LINE") ;rs
    (progn ;rs
    (command "offset" "3" lobj sid "") ;rs
    (setq L2(entlast))
    (command "change" L2 "" "p" "layer" "LAY1" "color" "bylayer" "lt"
    "bylayer" "")
    (command "pedit" L2 "Y" "w" "1.00000000" "")
    (redraw lobj 4) ;rs unhighlight the line
    (setvar "CMDECHO" CMDEC)
    ;;(setvar "CLAYER" CLAY) ;rs you haven't changed the layer
    (setvar "OSMODE" OSMO)
    (setvar "SNAPMODE" SNAPMO)
    (setq doitagain "no")
    (command "._undo" "end")
    ) ;progn
    (Progn
    (princ "\nSorry, object is not a line. Try again: ")
    (setq doitagain "yes")
    ) ;progn
    ) ;if
    ) ;while
    (princ)
    );end of function
     
    TCEBob, Dec 17, 2003
    #4
  5. akdrafter

    akdrafter Guest

    Gentlemen,

    Thank you all for your help. I am constantly learning new things. I have taken all of the suggestions you have made and combined them to produce the final attatched lisp routine. To answer a question "What does s-shear have to do with this routine?". I work for a structural engineering firm and S-SHEAR is a layer we use for shear walls. Before I posted this code I changed that layer name to alleviate any questions to the name of the layer. Apparently I forgot one. My bad. Please see the attatched final routine. It does exactly what I want it to and I have listed the 3 gentlemen in the code with credit for helping me with the routine. I do not know TCEBob's real name so I could not credit him with his real name. Anyway, The code is attatched and it works great.

    Again, Thank you for all your help.

    "Catch" Ya Later,
    Timothy J. Jaronik Sr.
    akdrafter

    P.S. Again, I can not attatch the actual lisp file. So, here is the cut & pasted code.

    ;;;
    ;;; Timothy J. Jaronik Sr.
    ;;; December, 2003
    ;;;
    ;;; Credit goes to the following people
    ;;; from the Auotdesk Discussion Groups(ADG)
    ;;; for their help with this routine
    ;;;
    ;;; Joe Burke
    ;;; Bob Shaw
    ;;; TCEBob <<<<ADG Handle Not sure what his real name is
    ;;
    ;;
    ;;;;;;;;;;;;;;;BEGIN ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;
    ;;
    (defun *ERROR* (msg)
    (princ "\nerror: ")
    (if msg (princ msg))
    (setvar "CMDECHO" CME)
    (setvar "OSMODE" OSM)
    (setvar "SNAPMODE" SNM)
    (princ)
    )
    ;;
    ;;;;;;;;;;;;;;;END ERROR HANDLING FUNCTION;;;;;;;;;;;;;;;
    ;;
    (defun c:SW ( / CME OSM SNM L1 L2 SID)
    (setq CME(getvar "CMDECHO"))
    (setvar "CMDECHO" 0)
    (setq OSM(getvar "OSMODE"))
    (setvar "OSMODE" 0)
    (setq SNM(getvar "SNAPMODE"))
    (setvar "SNAPMODE" 0)
    (command "-layer" "thaw" "S-SHEAR" "on" "S-SHEAR" "color" "1" "S-SHEAR" "lt" "hidden" "S-SHEAR" "")
    (while
    (or
    (not (setq L1 (entsel "\nSelect Line: ")))
    (/= "LINE" (cdr (assoc 0 (entget (car L1)))))
    )
    (princ "\nMissed Pick or Wrong Object Type" )
    )
    (setq SID(getpoint "\nSide To Offset To: "))
    (command "offset" "3" L1 SID "")
    (setq L2(entlast))
    (command "change" L2 "" "p" "layer" "S-SHEAR" "color" "bylayer" "lt" "bylayer" "")
    (command "pedit" L2 "Y" "w" "1.00000000" "")
    (setvar "CMDECHO" CME)
    (setvar "OSMODE" OSM)
    (setvar "SNAPMODE" SNM)
    (princ)
    )
     
    akdrafter, Dec 18, 2003
    #5
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.