Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

How to build bezier path from points produced with python

Still a little green? Ask your beginner's questions here

How to build bezier path from points produced with python

Postby gor » Sat Jul 06, 2019 3:58 pm

I have a python script in a text DAT which outputs a bezier path. I am able to select all the points of the bezier path (on-curve, off-curve) which outputs something like shown below.

What is the most efficient way to visualise the points and bezier path in TD?
Is there an operator that I can pass all this information into that can reconstruct the bezier path?
Do the points have to be organised into a table?

Thanks in advance for any help:)


Code: Select all
[(38.427734375, -1.806640625), (28.401642578125, -1.806640625), (20.336944580078125, 1.6682595214843752), (14.2333984375, 8.6181640625), (8.129852294921875, 15.568068603515625), (5.078125, 24.75580224609375), (5.078125, 36.181640625), (5.078125, 47.67258349609375), (8.146128173828124, 56.860317138671874), (14.2822265625, 63.7451171875), (20.418324951171876, 70.62991723632813), (28.613229980468752, 74.072265625), (38.8671875, 74.072265625), (49.0885927734375, 74.072265625), (57.27535986328125, 70.63805517578125), (63.427734375, 63.76953125), (69.58010888671875, 56.90100732421875), (72.65625, 47.73768750000001), (72.65625, 36.279296875), (72.65625, 24.593040527343753), (69.58010888671875, 15.323927490234375), (63.427734375, 8.4716796875), (57.27535986328125, 1.6194318847656253), (48.942109863281246, -1.806640625), (38.427734375, -1.806640625), (38.57421875, 5.859375), (45.96357861328124, 5.859375), (51.67641210937499, 8.520481201171876), (55.712890625, 13.8427734375), (59.74936914062501, 19.165065673828124), (61.767578125, 26.6763837890625), (61.767578125, 36.376953125), (61.767578125, 45.78455224609375), (59.74123120117188, 53.141249511718755), (55.6884765625, 58.447265625), (51.63572192382812, 63.753281738281245), (46.028681640624995, 66.40625), (38.8671875, 66.40625), (31.673141113281254, 66.40625), (26.057962890625, 63.745143798828124), (22.021484375, 58.4228515625), (17.985005859375, 53.100559326171876), (15.966796875, 45.70317236328125), (15.966796875, 36.23046875), (15.966796875, 26.7903173828125), (17.96872998046875, 19.3685166015625), (21.97265625, 13.96484375), (25.97658251953125, 8.561170898437501), (31.51038134765625, 5.859375), (38.57421875, 5.859375), (38.57421875, 5.859375)]
gor
 
Posts: 4
Joined: Thu Jun 20, 2019 6:06 am

Re: How to build bezier path from points produced with pytho

Postby rob » Tue Jul 16, 2019 11:17 am

Hi Gor.

Try using a Script SOP.

(I've cut out the array contents for brevity).
Not sure this is closing the curve as you expect, so you may have to play around.

Some useful links:

https://docs.derivative.ca/Bezier_Class
https://docs.derivative.ca/ScriptSOP_Class

You'll also want to open the Display Options dialog from the viewer to turn on points and hulls:

https://docs.derivative.ca/Display_Options



Code: Select all
def onCook(scriptOp):
   scriptOp.clear()

   a = [(38.427734375....
   bez = scriptOp.appendBezier(len(a), closed=True)

   for vertex,coord in zip(bez,a):
      vertex.point.x = coord[0]
      vertex.point.y = coord[1]
   
   return
User avatar
rob
Staff
 
Posts: 1671
Joined: Tue Nov 13, 2007 1:14 am


Return to Beginners

Who is online

Users browsing this forum: barakooda, Bing [Bot] and 10 guests