Jump to content

Recommended Posts

Posted (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 by avenger9mm
formatting code
Posted

Welcome to CADTutor :)

 

Firstly, please read the instructions regarding formatting code in your posts and edit your post accordingly.

Posted
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

Posted

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.

Posted

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)))
 )

Posted

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

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...