Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Remove loops from SketchFittedSpline

moritz.bischof1
Explorer

Remove loops from SketchFittedSpline

moritz.bischof1
Explorer
Explorer

moritzbischof1_1-1648074336228.png

 

A script im working on generates points and draws a SketchFittedSpline through them. In the image above, you can see a part of the SketchFittedSpline, and the blue area it encloses. However, there is also this loop (which i circled in green) which i would like to get rid of. 

 

I already tried a lot of approaches, like manually calculating intersections using the Bently-Ottmann algorithm, but that went nowhere.

 

I would highly appreciate some guidance where to start! I was hoping that some features of the API would make this somewhat easy so that I could avoid having to calculate everything manually.

0 Likes
Reply
Accepted solutions (1)
363 Views
2 Replies
Replies (2)

MichaelT_123
Advisor
Advisor

Hi Mr Moritz.Bischof1,

 

Consider the following:

  1. Identify a profile you want to 'preserve'
  2. Iterate through the spline's fit points.
  3. Check if a given fit point falls within profile or not (perhaps algorithm here does need the explanation)
  4. Dependent upon the objective include in the calculation profile's edge or implement some tolerances
  5. Mark the spline fittedPoints which fall outside the profile (or outside tolerance)
  6. Draw a new spline including all fit points from the previous one, but marked

Regards

MichaelT

MichaelT
1 Like

moritz.bischof1
Explorer
Explorer
Accepted solution

Hey Michael, 

thanks for the reply.

While you did not directly answer the question, you motivated me to dig a bit deeper in the API docs, and I found a solution which works. 

1. create a temporary sketch

2. create my shape in the temporary sketch using lines

3. get the profile from the temporary sketch im interested in:

 

 

 

biggest = None
for p in tmp_sketch.profiles:
    if biggest is None or p.areaProperties().area > biggest.areaProperties().area:
        biggest = p

 

 

 

4. copy all points from the profile

 

 

 

 # copy points from profile into new list
 resulting_profile_curves = biggest.profileLoops.item(0).profileCurves
 new_point_list = adsk.core.ObjectCollection.create()
 for curve in resulting_profile_curves:
     line: Line3D = curve.geometry
     new_point_list.add(line.endPoint.copy())

 

 

 

5. create the final SketchFittedSpline in the "original" sketch

6. delete temporary sketch

 

Definetely got more familiar with the API trying to figure this out ^^

1 Like