Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Lisp Routine Help

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
dwk1204
523 Views, 9 Replies

Lisp Routine Help

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)
)
9 REPLIES 9
Message 2 of 10
alanjt_
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)
)

 

Message 3 of 10
dwk1204
in reply to: alanjt_

Awesome...Thank you for the quick response!

Message 4 of 10
alanjt_
in reply to: dwk1204

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

Message 5 of 10
Kent1Cooper
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, AIA
Message 6 of 10
Kent1Cooper
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, AIA
Message 7 of 10
alanjt_
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.

Message 8 of 10
dwk1204
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...

Message 9 of 10
alanjt_
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")

 

Message 10 of 10
alanjt_
in reply to: alanjt_

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost