Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Defining points for spline command

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
2643 Views, 6 Replies

Defining points for spline command

Hi guys,

 

I am working on a litle lisp routine to draw splines, but can't get it working. The basic idea is that i first select a set of points that i can feed to my spline command.

 

(defun c:test2 ()
  (setq pt (getpoint "\n define point:"))
  (setq ptlist nil)
  (while (not (equal pt nil))
    (setq ptlist (cons pt ptlist))
    (setq pt (getpoint "\n define point:"))
    )
  )

 Now i need to draw a spline based on these points.

My plan whas to simply use the acad command itself

But this option didn't work.

 

(command
  "spline"
  ptlist
  ""
)

 Then i tried using the vla-addspline command.

But i can't even get this one working 😛

 

Can enybody help me whit this problem?

 

 

Regards

 

Thomas

6 REPLIES 6
Message 2 of 7
wayne.brill
in reply to: Anonymous

Hi Thomas,

 

Here is an example that uses vla-addSpline:

 

(defun c:spltest (/  acadapp       acaddoc
    *ModelSpace* ptStartTan    ptEndTan
    ptFit1 ptFit2       ptFit3
    ptFit4 FitPoints     ptlstlen
    FitPointsDataA       FitPointsData
    StartTanA StartTan      EndTanA
    EndTan mySplineObj
   )

 

  (vl-load-com)
  (setq acadapp      (vlax-get-Acad-Object)
 acaddoc      (vla-get-ActiveDocument acadapp)
 *ModelSpace* (vla-get-ModelSpace acaddoc)
  )

 

  ;;set start & end tangent values
  (setq ptStartTan (list 0.0 0.0 0.0)
 ptEndTan   (list 0.0 0.0 0.0)
  )

 

  ;;set fit point values
  (setq ptFit1 (list 1.5 3.5 0.0)
 ptFit2 (list 4.5 5.5 0.0)
        ptFit3 (list 6.5 1.5 0.0)
 ptFit4 (list 11.0 3.0 0.0)
  )

 

  ;;create list of the fit point values
  (setq FitPoints
  (apply 'append (list ptFit1 ptFit2 ptFit3 ptFit4))
  )

 

  ;;create a safearray to hold the fit points
  (setq ptlstlen (length FitPoints))

 

  (setq FitPointsDataA
  (vlax-make-safearray
    vlax-vbDouble
    (cons 0 (1- ptlstlen))
  )
  )

 

  ;;populate the safearray
  (vlax-safearray-fill FitPointsDataA FitPoints)

 

  ;;assign the safearray to a variant
  (setq FitPointsData
  (vlax-make-variant
    FitPointsDataA
    (logior
      vlax-vbarray
      vlax-vbDouble
    )
  )
  )

 

  ;;create a safearray to hold the start tangent points
  (setq StartTanA
  (vlax-make-safearray
           vlax-vbDouble
    (cons 0 2)
  )
  )

 

  ;;populate the safearray
  (vlax-safearray-fill StartTanA ptStartTan)

 

  ;;assign the safearray to a variant
  (setq StartTan
      (vlax-make-variant
    StartTanA
    (logior
      vlax-vbarray
      vlax-vbDouble
    )
  )
  )

 

  ;;create a safearray to hold the end tangent points
  (setq EndTanA
  (vlax-make-safearray
    vlax-vbDouble
    (cons 0 2)
  )
  )

 

  ;;populate the safearray
  (vlax-safearray-fill EndTanA ptEndTan)

 

  ;;assign the safearray to a variant
  (setq EndTan (vlax-make-variant
   EndTanA
   (logior
     vlax-vbarray
     vlax-vbDouble
   )
        )
  )

 

  ;;create the spline object
  (setq mySplineObj
  (vla-addSpline *ModelSpace* FitPointsData StartTan EndTan)
  )

 

  ;;change the color of the spline
  (vla-Put-Color mySplineObj acBlue)
  (vla-Update mySplineObj)
  (princ)

 

  ;; get the length of the spline
  (setq endSpline (vlax-curve-getEndParam mySplineObj))
  (princ "\nLength of Spline = ")
  (vlax-curve-getDistAtParam mySplineObj endSpline)

 

)

 

Cheers,

Wayne Brill

Autodesk Developer Network



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 3 of 7
stevor
in reply to: Anonymous

The 'command creation should still work, albeit the end directions must be entered.

This version seems to work, and in it the end directions are selected to go with the flow.

The commented out functions are at AusCadd.com, if using default values are of interest.


 (DEFUN C:desL ( /  npl pp ppp )  (redraw)
  (if (and ;(setq SP*p1  (get_p SP*p1 "  Start pt "))
           (setq SP*p1  (getpoint "  Start pt "))
           ;(setq SP*dp1 (get_prd SP*p1 SP*dp1 " Start Dir Pt "))
           (setq SP*dp1 (getpoint SP*p1
              " Start Dir Pt {towards next curve pt} "))
           (setq fp1 (polar SP*p1 (angle SP*p1 SP*dp1) 1e9))
       )
   (progn
     (grdraw SP*p1 fp1 5)   ; towards direction spline
     (setq pp SP*p1)
     (while (setq np (getpoint pp " Next "))
      (grdraw pp np 2) ; cord
      (grdraw pp (polar np (angle pp np) 1e8) 2) ; running tans
      (setq npl (cons np npl)  ppp pp  pp np) ; prevs
     )
     ;(setq SP*dp2 (get_prd pp SP*dp2 " End Dir Pt "))
     (grdraw pp  (polar ppp (angle ppp pp) 1e8)  5)
     (setq SP*dp2 (getpoint pp
         " End Dir Pt {away from last curve pt}"))
     ;
     (command "spline" SP*p1 )
     (foreach np (reverse npl) ; (gr_xdc np 1 1)
            (command np ) )
     (command  "" (polar SP*p1 (angle SP*dp1 SP*p1) 1e8)
                  SP*dp2 )  
     ;(redraw)
    ) ) (princ) )  ;  


S
Message 4 of 7
hmsilva
in reply to: Anonymous

Hi Thomas

 

using your method, so try

 

(defun c:test2 ()
  (setq pt (getpoint "\n define point:"))
  (setq ptlist nil)
  (while (not (equal pt nil))
    (setq ptlist (cons pt ptlist))
    (setq pt (getpoint "\n define point:"))
  )
  (command "_SPLINE")
  (mapcar 'command ptlist)
  (command "" "" "")
  (princ)
)

 

Cheers

Henrique

EESignature

Message 5 of 7
pbejse
in reply to: hmsilva

Similar

 

(defun c:test3  ( / pt pt2 ptlist)
(if (setq pt     (getpoint "\n define point:")
            ptlist (list pt))
    (progn
      (while (setq pt2 (getpoint pt "\n define point:"))
            (grdraw pt pt2 1 1)
            (setq ptlist (cons pt2 ptlist)
                  pt     pt2)
            )
      (command "spline")
      (foreach
             p  ptlist
            (command p))
      (command "" "" "")
      (redraw)
      )
    )
      )

 

Message 6 of 7
Anonymous
in reply to: pbejse

My apologies for waiting so long whit posting;

But i was still testing my one solution.

 

thank you all for the posts, this is what i finaly used:

 

 

(defun drawspl (ptlist)
  (setvar "osmode" 0)
  (command "spline")
  (foreach pt ptlist
    (command pt)
  )
  (command ""
	   ""
	   ""
  )
)

 

Message 7 of 7
pbejse
in reply to: Anonymous


@Anonymous wrote:

My apologies for waiting so long whit posting;

But i was still testing my one solution.

 

thank you all for the posts, this is what i finaly used: 


Godd for you,

 

Thats  what i did on my post too Thomas

 

Cheers

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost