Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
dwk1204
Posts: 194
Registered: ‎03-30-2007
Message 1 of 10 (194 Views)
Accepted Solution

Lisp Routine Help

194 Views, 9 Replies
05-15-2013 09:50 AM
I was wondering if I could get some assistance. I have pieced this lisp together from a few I have come across here in the groups, but am now stuck with the final pieces. Once the pline is drawn I would like the lisp routine to select the pline (last ?) instead of the user doing so. I would then like to offset the line 1 (foot) and then erase the original line drawn, so the user does not have to.
 
Any assistance would be GREATLY appreciated..Thanks
 
(defun c:Test ( / *error* of undo doc ss )
  (vl-load-com)
 
  (command "pline")
(while (> (getvar "cmdactive") 0) (command pause))
 
  (defun *error* ( msg )
    (and undo (vla-EndUndomark doc))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
   )
 
  (if (and (ssget '((0 . "ARC,CIRCLE,ELLIPSE,*LINE")))
           (setq of (getdist "\nSpecify Offset Distance: ")))
    (progn
      (setq undo
        (not
          (vla-StartUndomark
            (setq doc
              (vla-get-ActiveDocument
                (vlax-get-acad-object)
              )
            )
          )
        )
      )
      
      (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))
        (mapcar
          (function
            (lambda ( o )
              (vl-catch-all-apply
                (function vla-offset) (list obj o)
              )
            )
          )
          (list of (- of))
        )
      )
      (vla-delete ss)
 
      (setq undo (vla-EndUndoMark doc))
    )
  )
  (princ)
)
Valued Mentor
alanjt_
Posts: 469
Registered: ‎08-25-2008
Message 2 of 10 (186 Views)

Re: Lisp Routine Help

05-15-2013 10:21 AM in reply to: dwk1204
(defun c:Test (/ *error* cmd ent obj)

  (defun *error* (msg)
    (and cmd (setvar 'CMDECHO cmd))
    (and *AcadDoc* (vla-endundomark *AcadDoc*))
    (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
      (princ (strcat "\nError: " msg))
    )
  )

  (vla-startundomark
    (cond (*AcadDoc*)
          ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
    )
  )

  (setq ent (entlast)
        cmd (getvar 'CMDECHO)
  )

  (setvar 'CMDECHO 0)

  (princ "\nSpecify start point: ")

  (command "_.pline")
  (setvar 'CMDECHO 1)
  (while (eq (logand 1 (getvar 'CMDACTIVE)) 1) (command PAUSE))

  (if (not (equal ent (setq ent (entlast))))
    (progn
      (setq obj (vlax-ename->vla-object ent))

      (foreach off '(1. -1.) (vlax-invoke obj 'Offset off))
      (vla-delete obj)
    )
  )

  (*error* nil)
  (princ)
)

 

Distinguished Contributor
dwk1204
Posts: 194
Registered: ‎03-30-2007
Message 3 of 10 (183 Views)

Re: Lisp Routine Help

05-15-2013 10:26 AM in reply to: alanjt_

Awesome...Thank you for the quick response!

Valued Mentor
alanjt_
Posts: 469
Registered: ‎08-25-2008
Message 4 of 10 (178 Views)

Re: Lisp Routine Help

05-15-2013 10:31 AM in reply to: dwk1204

You're very welcome. Since it was easier than tweaking, I just wrote it from scratch. 

*Expert Elite*
Kent1Cooper
Posts: 5,242
Registered: ‎09-13-2004
Message 5 of 10 (169 Views)

Re: Lisp Routine Help

05-15-2013 10:59 AM in reply to: dwk1204

dwk1204 wrote:
.... Once the pline is drawn I would like the lisp routine to select the pline (last ?) instead of the user doing so. I would then like to offset the line 1 (foot) and then erase the original line drawn, so the user does not have to.
....

In simplest terms, it could be as little as this:

 

(defun c:Test (/ pl)
  (command "_.pline")
  (while (> (getvar "cmdactive") 0) (command pause))
  (setq pl (entlast))
  (command
    "_.offset" 12 pl pause "" ; [pause for User to pick on which side]
    "_.erase" pl ""
  ); command
); defun
 
For some reason, "_last" does not work for object selection in the Offset command, though either the pl variable here or (entlast) does.  But Offsetting does not turn the selected-to-Offset object into the "_previous" selection, which is the real reason for the pl variable.
 
If you want to turn off command echoing [which you would do only after drawing the Polyline], or wrap an Undo begin/end around the whole thing, you should include an error handler -- if you don't need those features, there's no need for one.
 
EDIT:  Oh, Offset to both sides....  That would make it only slightly longer, but it looks like you have a solution.
Kent Cooper
*Expert Elite*
Kent1Cooper
Posts: 5,242
Registered: ‎09-13-2004
Message 6 of 10 (166 Views)

Re: Lisp Routine Help

05-15-2013 11:07 AM in reply to: alanjt_

alanjt_ wrote:
....
  (setvar 'CMDECHO 0)

  (princ "\nSpecify start point: ")

  (command "_.pline")
  (setvar 'CMDECHO 1)
....

 


I'm just a little curious about the reason for turning off command echoing, spelling out a prompt to start the Polyline, and turning command echoing back on to finish it.  You could leave it on, and the Polyline command will provide its own starting prompt.  Then you wouldn't need to reset it, and that aspect of the error handler could be omitted.

Kent Cooper
Valued Mentor
alanjt_
Posts: 469
Registered: ‎08-25-2008
Message 7 of 10 (160 Views)

Re: Lisp Routine Help

05-15-2013 11:50 AM in reply to: Kent1Cooper

I do it to remove the display of "_.pline" on the command line. Plus, one shouldn't assume CMDECHO will be set to 1. I've worked at a few firms that set it ot 0 in their startup.

Distinguished Contributor
dwk1204
Posts: 194
Registered: ‎03-30-2007
Message 8 of 10 (125 Views)

Re: Lisp Routine Help

05-16-2013 10:45 AM in reply to: dwk1204

Thank you both for the help...

 

I do have a follow up question. The lisp routine allows the user to pick as many points as needed to create the pline, I was wondering if that is also possible while using the cui?

 

I made the folllowing command ^C^C_layer;s;c-sswr-pipe-x;;-linetype;s;san12'';;_pline;

 

after the pline is created I would like to set the linetype back to bylayer. I know the \ is a single pause for user input, but not sure if mulitple user input is possible. I can accomplish this easily with layers or with another lisp routine,but I am just trying to broaden my knowledge in the cui.

 

Thanks again for all the help...

Valued Mentor
alanjt_
Posts: 469
Registered: ‎08-25-2008
Message 9 of 10 (120 Views)

Re: Lisp Routine Help

05-16-2013 10:55 AM in reply to: dwk1204

Short answer is no. However the above routine could be convereted to a subfunction and you call it accordingly from the CUI, if you wanted.

 

 

 

(defun _pipeOnLayer (layer linetype / *error* cmd ent obj)

  (defun *error* (msg)
    (and cmd (setvar 'CMDECHO cmd))
    (and *AcadDoc* (vla-endundomark *AcadDoc*))
    (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*QUIT*,")))
      (princ (strcat "\nError: " msg))
    )
  )

  (vla-startundomark
    (cond (*AcadDoc*)
          ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
    )
  )

  (setq ent (entlast)
        cmd (getvar 'CMDECHO)
  )

  (setvar 'CMDECHO 0)

  (princ "\nSpecify start point: ")

  (command "_.pline")
  (setvar 'CMDECHO 1)
  (while (eq (logand 1 (getvar 'CMDACTIVE)) 1) (command PAUSE))

  (if (not (equal ent (setq ent (entlast))))
    (progn
      (setq obj (vlax-ename->vla-object ent))

      (and layer (vl-catch-all-apply 'vla-put-layer (list obj layer)))
      (and linetype (vl-catch-all-apply 'vla-put-linetype (list obj linetype)))

      (foreach off '(1. -1.) (vlax-invoke obj 'Offset off))
      (vla-delete obj)
    )
  )

  (*error* nil)
  (princ)
)


(_pipeOnLayer "C-SSWR-PIPE-X" "SAN12")

 

Valued Mentor
alanjt_
Posts: 469
Registered: ‎08-25-2008
Message 10 of 10 (118 Views)

Re: Lisp Routine Help

05-16-2013 10:56 AM in reply to: alanjt_

The program will not fail, but it is up to you for the layer/linetype to exist in the drawing. 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community