Results 1 to 7 of 7

Thread: draw polyline on selected layer; help

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

    Default draw polyline on selected layer; help

    Hello all,
    I have created a lisp that will begin a ployline on a certain layer depending on the point selected. Since my lisping skills leave something to be desired, I ask you all to take a look at this and let me know if you see a way of improving the function.

    Thanks all,
    Andre

    Code:
    ;Draw polyline on selected layer
    (defun drawpolyline (/ sp)
      (setq prevlay (getvar "clayer"))
      (setq sp (getpoint "\nSpecify start point: "))
      (command "_ai_molc" sp)
      (if
        (= (strcase (getvar "clayer")) "X-ANNO-BASE")
        (setvar "clayer" prevlay)
        )
    
      (if
        (= (strcase (getvar "clayer")) "M-SUPP-DIFF")
        (setvar "clayer" "M-SUPP-DUCT")
        )
    
      (if
        (= (strcase (getvar "clayer")) "M-RETN-DIFF")
        (setvar "clayer" "M-RETN-DUCT")
        )
    
      (if
        (= (strcase (getvar "clayer")) "M-EXHS-DIFF")
        (setvar "clayer" "M-EXHS-DUCT")
        )
      
      (command ".pline" sp)
      (princ)
      )
    (defun c:dr () (drawpolyline))
    Last edited by Opie; 2007-10-02 at 09:02 PM. Reason: [CODE] tags added

  2. #2
    The Silent Type RobertB's Avatar
    Join Date
    2000-01
    Location
    Seattle WA USA
    Posts
    5,859
    Login to Give a bone
    0

    Default Re: draw polyline on selected layer; help

    Yes. Use (cond) instead of multiple (if) statements.
    R. Robert Bell
    Design Technology Manager
    Stantec
    Opinions expressed are mine alone and do not reflect the views of Stantec.

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

    Default Re: draw polyline on selected layer; help

    Hey, thats pretty useful for lisp clean up
    Thank you =)

    Code:
    ;Version II
    ;Draw polyline on selected layer
    (defun drawpolyline (/ sp)
      (setq prevlay (getvar "clayer"))
      (setq sp (getpoint "\nSpecify start point: "))
      (command "_ai_molc" sp)
    
      (cond
        ((= (strcase (getvar "clayer")) "X-ANNO-BASE")
         (setvar "clayer" prevlay))    
        ((= (strcase (getvar "clayer")) "M-SUPP-DIFF")
         (setvar "clayer" "M-SUPP-DUCT"))
        ((= (strcase (getvar "clayer")) "M-RETN-DIFF")
         (setvar "clayer" "M-RETN-DUCT"))
        ((= (strcase (getvar "clayer")) "M-EXHS-DIFF")
         (setvar "clayer" "M-EXHS-DUCT"))
        )
      (command ".pline" sp)
      (princ)
      )
    
    (defun c:dr () (drawpolyline))
    Last edited by Opie; 2007-10-02 at 09:01 PM. Reason: [CODE] tags added

  4. #4
    Super Moderator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,693
    Login to Give a bone
    0

    Lightbulb Re: draw polyline on selected layer; help

    Quote Originally Posted by ReachAndre View Post
    Code:
      (cond
        ((= (strcase (getvar "clayer")) "X-ANNO-BASE")
         (setvar "clayer" prevlay))    
        ((= (strcase (getvar "clayer")) "M-SUPP-DIFF")
         (setvar "clayer" "M-SUPP-DUCT"))
        ((= (strcase (getvar "clayer")) "M-RETN-DIFF")
         (setvar "clayer" "M-RETN-DUCT"))
        ((= (strcase (getvar "clayer")) "M-EXHS-DIFF")
         (setvar "clayer" "M-EXHS-DUCT"))
    Another thing....
    Set a variable for (strcase (getvar "clayer")) instead of calling it multiple times.
    R.K. McSwain | CAD Panacea |

  5. #5
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    383
    Login to Give a bone
    0

    Default Re: draw polyline on selected layer; help

    Are you suggesting I do something like this?


    Code:
    ;Draw polyline on selected layer Version III
    (defun drawpolyline (/ sp)
      (setq prevlay (getvar "clayer"))
      (setq sp (getpoint "\nSpecify start point: "))
      (command "_ai_molc" sp)
      (setq runlay (strcase (getvar "clayer")))
      (cond
        ((= runlay "X-ANNO-BASE")
         (setvar "clayer" prevlay))
        
        ((= runlay "M-SUPP-DIFF")
         (setvar "clayer" "M-SUPP-DUCT"))
    
        ((= runlay "M-RETN-DIFF")
         (setvar "clayer" "M-RETN-DUCT"))
    
        ((= runlay "M-EXHS-DIFF")
         (setvar "clayer" "M-EXHS-DUCT"))
        )
      (command ".pline" sp)
      (princ)
      )
    (defun c:DR    () (drawpolyline))
    Last edited by Opie; 2007-10-02 at 09:01 PM. Reason: [CODE] tags added

  6. #6
    Super Moderator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,693
    Login to Give a bone
    0

    Default Re: draw polyline on selected layer; help

    Quote Originally Posted by ReachAndre View Post
    Are you suggesting I do something like this?
    Yes. It's not a big deal in this small routine, but in large programs you typically want to avoid making the same call more than once if you can save it to a variable.

    R.K. McSwain | CAD Panacea |

  7. #7
    I could stop if I wanted to
    Join Date
    2015-12
    Posts
    383
    Login to Give a bone
    0

    Default Re: draw polyline on selected layer; help

    I agree, that helps clean up my prgramming, I plan to rewrite a few of my lisps that are larger so that they may be as simple.

Similar Threads

  1. Draw polyline on pointed layer
    By ReachAndre in forum AutoLISP
    Replies: 0
    Last Post: 2014-08-06, 08:07 PM
  2. Replies: 3
    Last Post: 2014-04-04, 08:17 PM
  3. Replies: 0
    Last Post: 2010-06-09, 01:16 PM
  4. Get Layer Name of selected polyline
    By wbreedveld in forum AutoLISP
    Replies: 7
    Last Post: 2007-05-30, 06:59 PM
  5. Replies: 3
    Last Post: 2007-03-14, 01:33 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
  •