avenger9mm Posted July 26, 2012 Posted July 26, 2012 (edited) Hi i know a little bit of autolisp but now im trying to study vlisp im currently using an autolisp program to calculate station and offset but the offset was all positive. I would like the program to know if the offset was at left or right of the polyline. It should show negative offset values if point is on the left side and positive on the right. heres the code ( i cant remember which forum i copied this code but the credit goes to Jeff Mishler as mentioned inside the func. (defun c:sta-off (/ endpt ent off offpt onpt ss sta startpt) ;; Marker for point location on the screen ;; Oct. 2004 by Jeff Mishler (defun Xmarksthespot (x y / leglen start) (setq start (list x y) leglen (* 0.03 (getvar "viewsize")) ) (grdraw (polar start (angtof "135" 1) leglen) (polar start (angtof "315" 1) leglen) 7) (grdraw (polar start (angtof "45" 1) leglen) (polar start (angtof "225" 1) leglen) 7) ) (while (setq ss (ssget "[img=http://autodesk.i.lithium.com/i/smilies/16x16_smiley-frustrated.gif]" '((0 . "LINE,*POLYLINE,SPLINE,ARC")))) (setq ent (ssname ss 0)) (setq startpt (vlax-curve-getstartpoint ent) endpt (vlax-curve-getendpoint ent) ) (xmarksthespot (car startpt)(cadr startpt)) (while (setq offpt (getpoint "\nOffset point: ")) (setq onPt (vlax-curve-getclosestpointto ent offpt) sta (vlax-curve-getdistatpoint ent onpt) off (distance onpt offpt) ) (princ (strcat "Station: " (rtos sta 2 2) " - Offset: " (rtos off 2 2))) ) (redraw) ) (princ) ) help anyone? Thanks, Ger Aven Edited July 26, 2012 by avenger9mm formatting code Quote
Lee Mac Posted July 26, 2012 Posted July 26, 2012 Welcome to CADTutor Firstly, please read the instructions regarding formatting code in your posts and edit your post accordingly. Quote
avenger9mm Posted July 26, 2012 Author Posted July 26, 2012 Welcome to CADTutor Firstly, please read the instructions regarding formatting code in your posts and edit your post accordingly. My bad, I didnt read the instructions, Thanks Lee Mac here's a sample output from the code above, Offset point: Station: 5.2397 - Offset: 4.8319 Offset point: Station: 7.4596 - Offset: 4.4995 I picked a point on the left side of the polyline giving a value of positive 4.8319 then i picked the right side giving a value of positive 4.4995 Id like the program to give negative offset values for points picked at left side of the alignment polyline Thanks Quote
BIGAL Posted July 27, 2012 Posted July 27, 2012 You will probably need to look at the two points of the pline either side of the pick point and compare say the angles to work out if its left or right, the distance is returned as just that a +ve value. All sorts of stuff creeps in here to do with quadrants where your angle is on either side of the zero angle. ang1 is pt1-pt2 ang2 pt1-pick pt if ang2 is greater than ang1 -ve ? Remember plines can be drawn in any direction but returning points is in direction of creation. A last thought check out some of the Chainage label lisps they may have a answer. Quote
avenger9mm Posted July 27, 2012 Author Posted July 27, 2012 Thanks Bigal i was looking at this piece of code and see where i can start from here, (defun AT:AngleAtPoint (e p) ;; Return angle along curve, at specified point (on curve) ;; e - valid curve (ENAME or VLA-OBJECT) ;; p - point on curve ;; Alan J. Thompson, 11.04.10 (angle '(0. 0. 0.) (vlax-curve-getFirstDeriv e (vlax-curve-getParamAtPoint e p))) ) Quote
BIGAL Posted July 28, 2012 Posted July 28, 2012 Just the way I do things a couple of suggestions saves some typing rather than (angtof "45" 1) use just 45ang in autoload lisp have the common values all preset 45 90 270 etc (setq 45ang (/ pi() 4.0)) If only selecting one object maybe use entsel rather than ssget can still check if its line arc pline Also check out RTD & DTR very common lisps 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.