eimimitu Posted December 15, 2017 Share Posted December 15, 2017 (edited) 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 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 January 18, 2018 by SLW210 Added Code Tags Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 16, 2017 Share Posted December 16, 2017 I would add some force osnaps "_mid" or use osmode variables get existing osmode then set for MID & END Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 16, 2017 Share Posted December 16, 2017 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) ) Quote Link to comment Share on other sites More sharing options...
Grrr Posted December 16, 2017 Share Posted December 16, 2017 Note that the _EndUndoMark subfunction should be wrapped within a while loop, so substitute the if function with while - it was explained somewhere why (so I won't bother). Quote Link to comment Share on other sites More sharing options...
eimimitu Posted December 16, 2017 Author Share Posted December 16, 2017 Thanks for the responses... You got rid of the weird coordinates it was displaying... GREAT! Thank you!..... 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? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 16, 2017 Share Posted December 16, 2017 Thanks for the responses... You got rid of the weird coordinates it was displaying... GREAT! Thank you!..... 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? Quote Link to comment Share on other sites More sharing options...
eimimitu Posted December 16, 2017 Author Share Posted December 16, 2017 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 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 17, 2017 Share Posted December 17, 2017 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. Quote Link to comment Share on other sites More sharing options...
SLW210 Posted December 18, 2017 Share Posted December 18, 2017 Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[NOPARSE] Your Code Here[/NOPARSE] = Your Code Here Quote Link to comment Share on other sites More sharing options...
eimimitu Posted December 20, 2017 Author Share Posted December 20, 2017 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. Quote Link to comment Share on other sites More sharing options...
marko_ribar Posted December 26, 2017 Share Posted December 26, 2017 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 Quote Link to comment Share on other sites More sharing options...
eimimitu Posted January 18, 2018 Author Share Posted January 18, 2018 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? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted January 18, 2018 Share Posted January 18, 2018 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. Quote Link to comment Share on other sites More sharing options...
eimimitu Posted January 18, 2018 Author Share Posted January 18, 2018 Speak of the 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.. hanks again everyone Quote Link to comment Share on other sites More sharing options...
SLW210 Posted January 18, 2018 Share Posted January 18, 2018 I fixed the original post for you. Quote Link to comment Share on other sites More sharing options...
eimimitu Posted January 18, 2018 Author Share Posted January 18, 2018 Awesome ... Looks much cleaner Thanks! Sorry for the oversight Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.