Jump to content

What's wrong with this LISP routine


eimimitu

Recommended Posts

I pieced together this routine which draws a line from its midpoint..

I added error handler and echo off...

 

The LISP executes fine but it gives me an "; error: AutoCAD variable setting rejected: CMDECHO nil" message... not sure how to fix it. It also spits out some coordinates at the end of the routine that I'd like to get rid of (which echo off should take care of right?)

 

Currently it allows me to pick a point and displays the default dashed rubber band/cursor tracer line. I would like for it to be dynamic where it shows the preview of the actual line in both directions from starting point and the rubber band/tracer line as well... Similar to when you draw a circle and type "D" for diameter: it shows a preview of said circle and the rubber band/tracer line extends past it the length of the radius...

 

Thanks in advance...

 

One last thing... I'm super new at LISPing so please be as detailed as possible... Thanks again :D

MidLine LISP:

(defun c:MidLine (/ *error* pt1 pt1w pt2 pt2w pt0 ang len ed)

(defun *error* ( msg )
       (if ocmd (setvar 'CMDECHO ocmd))
       (if acdoc (_EndUndoMark acdoc))
       (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )

   (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
   (_StartUndoMark acdoc)

   (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
   (_StartUndoMark acdoc)

   (setq ocmd (getvar 'CMDECHO))
   (setvar 'CMDECHO 0)

 (setq pt1 (getpoint "\nMIDLINE Specify midpoint of line: "))
   (setq pt1w (trans pt1 1 0)
         pt2  (getpoint pt1 "\nMIDLINE Specify endpoint of line: ")
         pt2w (trans pt2 1 0)
   )

   (setq ang (angle pt2w pt1w))
   (setq len (/ (distance pt1w pt2w) 2.0))
   (setq pt0 (polar pt1w ang len))

   (setq ang (angle pt1w pt2w))
   (setq pt2 (polar pt1w ang len))

   (setq ed (list '(0 . "LINE") (cons 10 pt0) (cons 11 pt2)))
   (entmake ed)
 )

(defun _StartUndoMark ( doc )
   (_EndUndoMark doc)
   (vla-StartUndoMark doc)
)

(defun _EndUndoMark ( doc )
   (if (= 8 (logand 8 (getvar 'UNDOCTL)))
       (vla-EndUndoMark doc)
   )
)

   (setvar 'CMDECHO ocmd)
   (_EndUndoMark acdoc)

(princ)

Edited by SLW210
Added Code Tags
Link to comment
Share on other sites

Hi,

Not sure if this goal if the program is what you are after but its as per your original codes.

 

Besides that, this is just for your learning and its more than enough.

 

(defun c:midline (/ pt1 pt1w pt2 pt2w pt0 ang len)
 (and (setq pt1 (getpoint "\nMIDLINE Specify midpoint of line: "))
      (setq pt2 (getpoint pt1 "\nMIDLINE Specify endpoint of line: "))
      (setq pt1w (trans pt1 1 0))
      (setq pt2w (trans pt2 1 0))
      (setq ang (angle pt2w pt1w))
      (setq len (/ (distance pt1w pt2w) 2.0))
      (setq pt0 (polar pt1w ang len))
      (setq ang (angle pt1w pt2w))
      (setq pt2 (polar pt1w ang len))
      (entmake (list '(0 . "LINE") (cons 10 pt0) (cons 11 pt2)))
      )
 (princ)
)

Link to comment
Share on other sites

Thanks for the responses...

 

You got rid of the weird coordinates it was displaying... GREAT! Thank you!:D.....

 

Now how do I properly add error handling and echo off? and how do i make it display a dynamic preview of the line to be drawn as described above?

Link to comment
Share on other sites

Thanks for the responses...

 

You got rid of the weird coordinates it was displaying... GREAT! Thank you!:D.....

 

You are welcome.

 

Now how do I properly add error handling and echo off? and how do i make it display a dynamic preview of the line to be drawn as described above?

 

Can you please answer the following questions?

 

1- Why do you want to use error handler function ?

2- What's the use of system variable 'CMDECHO and why do you want use it with that simple routine?

Link to comment
Share on other sites

I guess I don't need CMDECHO for your simplified version since it stopped displaying those weird coordinates... as for error handling: so that it won't display the "error; function cancelled" message if I press escape key mid command..

I was just under the impression that these two elements are standard procedure when LISPing... forgive my ignorance if that's completely false but...

Ultimately the routine works as intended... I'm just trying to fine tune it to my preference and to try to grasp some of the concepts of this awesome programming language

Link to comment
Share on other sites

I guess I don't need CMDECHO for your simplified version since it stopped displaying those weird coordinates...

 

If you add the princ function at the end then this should prevent that to happen.

 

as for error handling: so that it won't display the "error; function cancelled" message if I press escape key mid command..

I was just under the impression that these two elements are standard procedure when LISPing... forgive my ignorance if that's completely false but...

Ultimately the routine works as intended... I'm just trying to fine tune it to my preference and to try to grasp some of the concepts of this awesome programming language

 

Yes you can add the error handler but if you want to cancel the command from continuing then a sample hit on the space bar or enter should exit the command quietly and safely.

 

No worries, you are doing just well with your initial believes & thoughts about programming. ;)

Link to comment
Share on other sites

Upon further research I discovered that i need to add GRREAD to my code in order to get a dynamic preview of the line... I just don't have a clue how to incorporate it and have it display the line dynamically in both directions from starting mid-point. Any insight on this would be greatly appreciated.

Link to comment
Share on other sites

Upon further research I discovered that i need to add GRREAD to my code in order to get a dynamic preview of the line... I just don't have a clue how to incorporate it and have it display the line dynamically in both directions from starting mid-point. Any insight on this would be greatly appreciated.

 

You can use (grread) function, but you will loose osnap functionality unless you decide to code it further more... Have a look into subfunction Grsnap from here : http://www.lee-mac.com/grsnap.html

Link to comment
Share on other sites

  • 4 weeks later...

Thanks Marko... There's a lot to discover on Lee Mac's site :)... I'm slowly getting the hang of it... but grread has given me some trouble... Just gotta keep working at it... Thanks everyone for the input!

 

Side note: I cannot for the life of me figure out how to edit my original post to add (((

Code

=)))... Where do I go?

Link to comment
Share on other sites

There's a lot to discover on Lee Mac's site :)

 

Thanks! :)

 

Side note: I cannot for the life of me figure out how to edit my original post to add (((
Code

=)))... Where do I go?

 

I think there are a number of basic forum restrictions (such as editing posts) which apply to users with fewer than 10 posts.

Link to comment
Share on other sites

Speak of the :twisted::)

 

I see... All my following post will include the brackets Mr. Moderator:D

 

Thanks Mr. Mac... I've been using your custom ssget wrapper function for custom prompts.. It's pretty great... I hope you don't mind... and I will soon be using your grsnaps too from the looks of it..:P

 

hanks again everyone

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...