zyborgmonkey Posted December 9, 2020 Posted December 9, 2020 (edited) Apologies with all the notes and junk. First ever attempt at piecing my own routine together. I'm trying to make it so I can pick a point anywhere on a line then a second point perpendicular on another line. Then plot the Z values of both as text aligned and most readable at consistent offsets from the second pick point. (yet to be figured out, I'm thinking use the orientation of the two points and calculate offset co-ordinates) The application is to plot top of kerb and bottom of kerb z values anywhere in front of a kerb run The problem I seem to be getting while using it at this stage is for some reason after a few uses the base point pt1 may not be correct. I find that clicking on the line using nearest snap and opposite with perpendicular the values, text and points are sometimes placed elsewhere along the line instead much like if an off screen snap point is picked up by mistake. Although doesn't make sense as pt1 and pt2 are stored values which at the time looked to be picked correctly. Restarting the command or reloading the lisp doesn't seem to fix it. Randomly clicking in the void seems to work fine. Re opening the drawing also works until it happens again. Any help would be much appreciated ;Load Command Name (defun c:NWKZ ( / nwp1 nwp2 ori1 ori2 os1 os2 p1z p2z osm *error*) ;;;;;;;;;;;; Error Handler stuff ;;;;;;;;;;;;;;; (defun *error* ( msg ) (if osm (setvar 'osmode osm)) (if (not (member msg '("Function cancelled" "quit / exit abort"))) (princ (strcat "\nError: " msg)) ) (princ) ) ;Set osm to current snap mode (setq osm (getvar 'osmode)) (while ;Change current snap mode to nearest or end point and pick point (setvar 'osmode 513) (setq pt1 (getpoint "\ntop of kerb: ")) ;Change snap mode to perp only and pick point (setvar 'osmode 128) (setq pt2 (getpoint pt1 "\nbottom of kerb: ")) ;pull out z values (caddr) to precision (rtos,point,unitstype,precision) (setq p1z (rtos (caddr pt1)2 2)) (setq p2z (rtos (caddr pt2)2 2)) (setq ori1 (angle pt1 pt2)) (if (and(> (-(/ (* ori1 180) pi ) 90) 270) (< (-(/ (* ori1 180) pi ) 90) 90) ) (setq ori2 (-(/ (* ori1 180) pi ) 90)) (setq ori2 (-(/ (* ori1 180) pi ) 270)) ) (command "point" pt1) (command "point" pt2) (command "text" pt1 "0.3" ori2 p1z) (command "text" pt2 "0.3" ori2 p2z) ;Restore osm (setvar 'osmode osm) ) (princ) ) ;next needs offsets setting ;needs text height default setting Edited December 9, 2020 by SLW210 Added Code Tags Quote
pkenewell Posted December 9, 2020 Posted December 9, 2020 (edited) Try Changing this: (command "point" pt1) (command "point" pt2) (command "text" pt1 "0.3" ori2 p1z) (command "text" pt2 "0.3" ori2 p2z) to this: (command "._point" "_non" pt1) (command "._point" "_non" pt2) (command "._text" "_non" pt1 "0.3" ori2 p1z) (command "._text" "_non" pt2 "0.3" ori2 p2z) Adding the "non" to the command overrides any object snaps when placing the points and text. Since you are changing object snap settings to "perpendicular" before placing the point and text items, the object snap is active when the command is called. The "non" eliminates that problem. The pt1 and pt2 variables are already set using object snaps so it is not needed to have the object snaps active while placing the points and text. that usually alters the points instead to whatever osnap is active. Also Note: FYI - the "." before the commands make sure the actual AutoCAD command is used, even if someone re-defines the command. The "_" will make the commands work in any language AutoCAD. Alternatively, you could add (setvar "osmode" 0) before starting the commands to turn off the last "Perpendicular" object snap setting. Edited December 9, 2020 by pkenewell Quote
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.