TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Mike Solaris on July 03, 2017, 06:33:19 PM

Title: Filleting two splines with lisp
Post by: Mike Solaris on July 03, 2017, 06:33:19 PM
Hi all
I have a little issue with filletting two splines with code I am hoping to get some help with.

I have 2 Beizers (order 3 or 4) who's end points are joined (As part of an iteration through a series of pairs - about 2k in all)

After borrowing some code from LeeMac, Ajilal.Vijayan and others, I thought I had it nailed but it is giving intermittent results as far as the direction of the fillet goes, or actually filleting at all.
The fillet will always be performed on a pair of splines joining at an angle 15-165 degrees (tangents).

I try to select 2 points that are close to the ends of each respective spline, but the result is not always a fillet - if the point is too far off the spline it can miss the selection (at least I think that's what is happening)..
..or if it is selecting the end point of a spline it can fillet in the wrong direction (extension rather than trimming)
I put all objects in view at the time of selection...

I draw some check lines in the code below to show the selection point of each spline for passing to the fillet command
(osnaps are off)

The crux of the issue is I do not seem to be able to get the resultant point actually on the spline for selection (see
I use vlax-curve-getClosestPointTo   in an attempt to locate it after first getting close to the end I require filleted

So here's what I got...

Code: [Select]
(defun c:get_closest_points (name_subspline name_subspline2nd / w_pt w_pt2 w_pt_closest w_pt2_closest)
(setq curve (vlax-ename->vla-object name_subspline))
(setq w_pt
(vlax-curve-getPointAtDist
curve
(* (vlax-curve-getDistAtParam curve (vlax-curve-getEndParam curve))0.8)   ; a point 80% along length of spline [near end point selection]
)
)
(setq  w_pt_closest (vlax-curve-getClosestPointTo curve w_pt T))

(setq curve2 (vlax-ename->vla-object name_subspline2nd))
(setq w_pt2
(vlax-curve-getPointAtDist
curve2
(* (vlax-curve-getDistAtParam curve2 (vlax-curve-getEndParam curve2))0.2)   ; a point 20% along length of spline [near start point selection]
)
)
(setq  w_pt2_closest (vlax-curve-getClosestPointTo curve2 w_pt2 T))

(terpri)(command "line" (strcat (rtos (car w_pt_closest)) "," (rtos (cadr w_pt_closest))) (strcat(rtos (car w_pt2_closest)) "," (rtos (cadr w_pt2_closest)))  "")(princ)

Code: [Select]
(command  "fillet"   (list name_subspline w_pt_closest) (list name_subspline2nd w_pt2_closest) )
I'll try to upload an image of what I am talking about (if I can) shortly
Title: Re: Filleting two splines with lisp
Post by: roy_043 on July 04, 2017, 05:08:16 PM
3 remarks:
Title: Re: Filleting two splines with lisp
Post by: Mike Solaris on July 04, 2017, 08:20:53 PM
Thanks Roy

yes all splines are connected end pt to start of next.
direction of splines is always known - I calculate that elsewhere.

The vlax-curve-getPointAtDist seems to hit at a point between the vertices.
I included the extra step vlax-curve-getClosestPointTo in an attempt to get a point on the curve (no difference was observed).
!!! I should have mentioned the splines are all defined by control points, not fit.

perhaps this is the issue here ??  :idiot2:

Thanks for the heads up on fillet on WCS - both are the same at time of filleting
Title: Re: Filleting two splines with lisp
Post by: roy_043 on July 05, 2017, 03:58:44 AM
If you can post an example dwg.
Title: Re: Filleting two splines with lisp
Post by: Mike Solaris on July 06, 2017, 04:39:32 AM
Ok I got some progress as to why it is not filleting in every case / extension rather than trimming

Just have do a read up on 'How do I upload a picture/dwg' to this forum before I can demonstrate it.

The point locates correctly if the screen is not viewing the area that the points are.
If I select the splines with the intersection out of view it correctly calculates the point on the spline.

Now osnaps are off, and so is Object snap tracking, so I wonder why the intersection is in view is causing the point to 'snap' elsewhere ?


Code: [Select]
(defun c:Get_Closest_Points ()
  (terpri) (princ " IIIIIII Get_Closest_Points IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII") (terpri)
  (setq name_subspline (car (entsel)))
(setq curve (vlax-ename->vla-object name_subspline))
(setq w_pt
(vlax-curve-getPointAtDist
curve
(* (vlax-curve-getDistAtParam curve (vlax-curve-getEndParam curve))0.95)
)
)
 (setq  w_pt_closest (vlax-curve-getClosestPointTo curve w_pt T))

    (setq name_subspline2nd (car (entsel)))
(setq curve2 (vlax-ename->vla-object name_subspline2nd))
(setq w_pt2
(vlax-curve-getPointAtDist
curve2
(* (vlax-curve-getDistAtParam curve2 (vlax-curve-getEndParam curve2))0.95)
)
)
 (setq  w_pt2_closest (vlax-curve-getClosestPointTo curve2 w_pt2 T))

 (terpri)(command "line" (strcat (rtos (car w_pt)) "," (rtos (cadr w_pt))) (strcat(rtos (car w_pt2)) "," (rtos (cadr w_pt2)))  "")(princ)
 (command "list" "last" "")
(terpri)(command "line" (strcat (rtos (car w_pt_closest)) "," (rtos (cadr w_pt_closest))) (strcat(rtos (car w_pt2_closest)) "," (rtos (cadr w_pt2_closest)))  "")(princ)
(command "list" "last" "")

) ;