[Shocker CAD!]You can never modify a spline curve in an LSP script?[About Knots and Uniform!]

[Shocker CAD!]You can never modify a spline curve in an LSP script?[About Knots and Uniform!]

U-O-U
Contributor Contributor
1,195 Views
8 Replies
Message 1 of 9

[Shocker CAD!]You can never modify a spline curve in an LSP script?[About Knots and Uniform!]

U-O-U
Contributor
Contributor

I need to generate the required spline curve automatically with an LSP script: directly generated Fit-Uniform-Spline (not first generated and then set to "Fit-Uniform").
But I realized that I can't do it, it's a bit complicated, please hear me out ......

 

(setvar "SPLMETHOD" 0)
(setvar "SPLKNOTS" 2)
At first I used the method of changing system variables to try to solve the problem quickly.
Result: entmake and command can't inherit these two system variables, it's not that the change didn't work, but these two system variables are only valid for manual input, and with code you can only generate Fit-Chord-Spline.

 

'(72 . 2)
I didn't give in and tried to set it up directly with entmake.
Result: The CAD website doesn't have a detailed description of "SPLINE (DXF) Group code 72", and ChatGpt tells me that 2 stands for "Uniform", but no matter what I change it to, the resulting spline is always Fit-Chord-Spline. 

 

(initcommandversion 1)
(command "-SPLINE" "Method" "Fit" "Knots" "Uniform")
(initcommandversion 0)
Still haven't given up! This time I used command to set the parameters directly!
Result: no! It seems that since a long time ago CAD doesn't support calling "M" and "K" via command, and restoring the old version with initcommandversion didn't work, so I suspect that these functions have been completely removed.

 

(setq splineObj (vla-AddSpline modelSpace points_right_variant nil nil))
(vla-put-KnotParameterization splineObj acUniformKnotParameterization)
(vla-put-Method splineObj acFitMethod)
I'm not convinced! Tried to use the unfamiliar ActiveX, thinking that utilizing the API would surely work.
Result: I wrote half a day's worth of code and couldn't write a script that would generate a spline curve properly! ActiveX was too difficult and I didn't understand it at all!

 

My core need:
(1) The best result is to generate Fit-Uniform-Spline directly using entmake or command, either by inheriting system variables or by setting it directly with a command.
(2) Barely acceptable result is to generate Fit-Chord-Spline and then modify it to Fit-Uniform-Spline after generating Fit-Chord-Spline.
(3) If the esteemed big guys are willing, I'd also like to get an LSP script that generates Fit-Uniform-Spline via ActiveX API, mainly because I'm curious about how to implement it.

First time in the community, hopefully some of the big guys can help me out as a newbie who doesn't know anything.


As a final note, my CAD version is the mechanical version of the 2024, thanks!

0 Likes
1,196 Views
8 Replies
Replies (8)
Message 2 of 9

devitg
Advisor
Advisor

@U-O-U Please upload you sample.DWG , points as CSV  xx,yy , I will try to do by VLX. 

0 Likes
Message 3 of 9

U-O-U
Contributor
Contributor

 

(defun c:NNN ()
  ; Fit and Uniform
  (setvar "SPLMETHOD" 0) 
  (setvar "SPLKNOTS" 2) 

  (setq n 180)
  (setq points_right '())
  (setq points_left '())
  
  ; Count-Right-Point
  (setq m 0)
  (while (<= m 90)
    (setq theta_prime (- (* m (/ 180.0 n)) 45))
    (setq r_prime (/ (+ theta_prime 45) (/ 180.0 n)))
    (setq x (* r_prime (cos (degrees-to-radians theta_prime))))
    (setq y (* r_prime (sin (degrees-to-radians theta_prime))))
    (setq points_right (append points_right (list (list x y 0))))
    (setq m (1+ m))
  )
  
  ; Count-Left-Point
  (setq m 0)
  (while (<= m 90)
    (setq theta_double_prime (+ (* m (/ 180.0 n)) 45))
    (setq r_double_prime (/ (- theta_double_prime 45) (/ 180.0 n)))
    (setq x (* r_double_prime (cos (degrees-to-radians theta_double_prime))))
    (setq y (* r_double_prime (sin (degrees-to-radians theta_double_prime))))
    (setq points_left (append points_left (list (list x y 0))))
    (setq m (1+ m))
  )
  
  ; Draw-Right-Spline
  (command "_SPLINE")
  (foreach pt points_right
    (command pt)
  )
  (command "") 
  (command "")
  (command "")
  
  ; Draw-Left-Spline
  (command "_SPLINE")
  (foreach pt points_left
    (command pt)
  )
  (command "")
  (command "")
  (command "")

  ; Circular
  (command "CIRCLE" '(0 0 0) "90")
)
  
(princ "\n 'NNN' ")
(princ)

(c:NNN)
(princ)

 

 

Hi, Good friend!
Since my code is complex, I simplified it to this sample.
I hope you can modify it to be able to generate Fit-Uniform-Spline directly.
If this is really not possible, I hope I can generate it first as a normal spline curve and then change it to Fit-Uniform-Spline.
Really thanks a lot you!
Thanks!

0 Likes
Message 4 of 9

leeminardi
Mentor
Mentor

You are correct in that it appears there is no direct way via VLISP to create a spline with a knot parametrization set to Uniform.  Very frustrating.  As you know, it's easy to do interactively via the spline command or by manually changing the knot parametrization parameter to Uniform after spline creation in the Properties dialog box.  Note that when the spline command is given, knot parametrization is automatcally changed to Chord no matter what has been set with with the system variable SPLKNOTS.

 

If you really need to create the uniform spline directly you could consider wrtiting code to detemine the location of the CVs for a given set of Fit Points.  The math is not for the light of heart and I'm not sure I get all of it!

Here's the equation (from "The NURBS Book" by Lee Piegl and Wayne Tiller)

leeminardi_0-1724722051900.png

N(i,p) is the basis function for the B-spline.  Of course this requires solving the linear et of simultaneous equations.

 

Why do you need a Uniform fit?  Can the differences in the spline your prgram will create of a consistent general shape?  If so, perhaps you could determine the appropriate placement of CVs from a pattern tha emerges when looking at a set of curves you need. 

You might also consider getting the shape you need by modifying kno weigh values as required when needing to crete an exact arc with a NURBS spline.

 

It would help to know more about your application.  It looks like you are trying to create a cycloid.

lee.minardi
0 Likes
Message 5 of 9

U-O-U
Contributor
Contributor
Thank you very much for your reply, I've been working on more complex code lately so I didn't get back to you in time, sorry!
The method you gave is too difficult, I don't need to modify the spline curve a lot, I'll opt for manual modification for now until the official CAD fix.
Thanks again!
0 Likes
Message 6 of 9

hak_vz
Advisor
Advisor

@U-O-UCurrently have no time to jump into solving your request, but you may look how this post about Catmull-Rom spline. just as an idea. You can con convert resulting lwpolyline to spline for even better smoothness.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 7 of 9

U-O-U
Contributor
Contributor

Update!
I have been told by some powerful people that if you use command to generate Spline, then by prefixing each piece of code that generates Spline with (initcommandversion 2) you are able to force the latest version to be used, inherit the system variables, and fulfill the requirements.
But after my attempts to generate Splines with command, there are tons of intractable problems that I can hardly express in a few words, I can only say that I refuse to use command to generate Splines.
Apart from command, all I can think of is entmake and vla-object, but neither of them can be affected by initcommandversion, so it still doesn't solve the problem.
That's probably it.

0 Likes
Message 8 of 9

leeminardi
Mentor
Mentor

I didn't have any luck either.  I tried the following which still did not creat a Unifrom parameterization spline.  Perhaps a VLISP Guru can jump in here.

(defun c:test (/) 
  (setq ptList (list '(1 1 0) '(4 2 0) '(10 0 0) '(8 4 0) '(3 3)))
  (setvar "SPLKNOTS" 2) 
  (command "_spline")
  (setvar "SPLKNOTS" 2) 
  (while (= (getvar "cmdactive") 1)
    (repeat (setq x (length ptList))
      ( initcommandversion 2)(setvar "SPLKNOTS" 2) 
       (command  (nth (setq x (- x 1)) ptList))
    )					
    (command "")			
  )
  (princ)
)

l

 

lee.minardi
0 Likes
Message 9 of 9

U-O-U
Contributor
Contributor
BREAKING NEWS! Good news!
A powerful man named “Nigma” has given the right answer!
In the case of creating a Spline using activeX, just add two lines of code at the end to fulfill the requirement.
The sample code is as follows:

 

(setq splineObj (vla-addSpline modelSpace points start end))


  (vla-put-splinemethod splineObj 0)
  (vla-put-KnotParameterization splineObj 2)

 

Thank you very much “Nigma” and thank you for your interest!
Thank you very much!

 
0 Likes