Author Topic: Filleting two splines with lisp  (Read 1715 times)

0 Members and 1 Guest are viewing this topic.

Mike Solaris

  • Guest
Filleting two splines with lisp
« 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

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Filleting two splines with lisp
« Reply #1 on: July 04, 2017, 05:08:16 PM »
3 remarks:
  • W_pt and w_pt2 are the result of vlax-curve-getpointatdist so these points are already on the curve. There is no need to use vlax-curve-getclosestpointto.
  • Your code assumes a fixed direction for the two curves. The end point of the first is connected to the start point of the second. Are you sure this is always the case?
  • The points in the code are in the WCS. The _Fillet command expects points in the current UCS. So your code can only work if the active UCS is the WCS.

Mike Solaris

  • Guest
Re: Filleting two splines with lisp
« Reply #2 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

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Filleting two splines with lisp
« Reply #3 on: July 05, 2017, 03:58:44 AM »
If you can post an example dwg.

Mike Solaris

  • Guest
Re: Filleting two splines with lisp
« Reply #4 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" "")

) ;