TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: civil.eng on June 13, 2021, 09:30:19 AM

Title: GetParamAtPoint Problem
Post by: civil.eng on June 13, 2021, 09:30:19 AM
Hello everyone,
There is a problem with vlax-curve functions with 3Dpolyline, the attached file I wanted to use GetParamAtPoint function but it gives nil for some points while there is no problem with polyline and it occurs only with 3Dpolyline :

Code: [Select]
(defun c:ff ()
  (setq obj (vlax-ename->vla-object (car (entsel))))
  (setq pt (getpoint))
  (vlax-curve-getparamatpoint obj pt)
)
Title: Re: GetParamAtPoint Problem
Post by: ribarm on June 13, 2021, 09:34:08 AM
Code: [Select]
(defun c:ff ()
  (setq obj (vlax-ename->vla-object (car (entsel))))
  (setq pt (getpoint))
  (vlax-curve-getparamatpoint obj (vlax-curve-getclosestpointto obj (trans pt 1 0)))
)

HTH., M.R.
Title: Re: GetParamAtPoint Problem
Post by: civil.eng on June 13, 2021, 09:40:40 AM
Thanks, but your codes didn't work. Did you try it on the file?
Title: Re: GetParamAtPoint Problem
Post by: ribarm on June 13, 2021, 10:01:41 AM
Indeed, sometimes CAD just won't work as expected... I moved 3dpoly, point at middle of segment, tried several times and at the end it worked... Sometime you just have to nudge things a bit to make it work - that's CAD (it happens from time to time, for ex. intersectwith method doesn't work if entity is far away from origin 0,0,0 - this isn't such a case, you just have to do something on entity that behaves buggy...)
Title: Re: GetParamAtPoint Problem
Post by: Tharwat on June 13, 2021, 10:40:29 AM
Also here returns nil
Work around it via retrieving the coordinates of that targeted polyline then sort them to nearest distance to pt with x and y only without Z.
Title: Re: GetParamAtPoint Problem
Post by: Lee Mac on June 13, 2021, 07:08:43 PM
This is a known bug with the vlax-curve-* functions when the target entity is far from the origin - the below presents a possible workaround for you to consider:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / b e o p v x )
  2.     (if
  3.         (and
  4.             (setq e (car (entsel)))
  5.             (setq p (getpoint "\nSpecify point to obtain param: "))
  6.         )
  7.         (progn
  8.             (setq v (vlax-ename->vla-object e)
  9.                   b (vlax-curve-getstartpoint e)
  10.                   p (mapcar '- (trans p 1 0) b)
  11.                   b (vlax-3D-point b)
  12.                   o (vlax-3D-point 0 0)
  13.             )
  14.             (vla-move v b o)
  15.             (vla-move v o b)
  16.             (princ "\nParameter: ")
  17.             (prin1 x)
  18.         )
  19.     )
  20.     (princ)
  21. )