LoopWhile or Python about [PolyCurve.ByJoinedCurves]

Hello,
You know, [PolyCurve.ByJoinedCurves] node,
Whether or not this node is executed is determined depending on the input tolerance.

I am trying to program a python node to create a minimum tolerance value that will ensure that this node does not return a null value.
But I’m python beginner.
I’m studying to understand the principles, but it’s difficult to me. :sob:
Could you please give me a help? Python or LoopWhile node both is okay.
Thanks!


@Lynn_Kim ,

i am not sure for what the python script is good for… :confused:

KR

Andreas

1 Like

I think you’re overthinking this. This is based on your acceptable tolerance. It’s not really an issue of finding a “minimum” allowable value. If you want the curves to always join then use an incredibly large number. Obviously the smaller the tolerance the more “accurate” the joined polycurve will be, but if you don’t want it to fail then the you don’t care about how accurate it is.

1 Like

Might hop on this tonight as I see value in a PolyCurve.ByMinimalToleranceJoin node… can you provide a dataset?

1 Like

If you can get your curves in lists of segments this should exhaust tolerances until one works:

# Boilerplate text
import clr

clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import PolyCurve

# Define list/unwrap list functions
def tolist(input):
    result = input if isinstance(input, list) else [input]
    return result

# Do some action in a Transaction
lineLists  = tolist(IN[0])
tolerances = tolist(IN[1])

# List for polycurves
polyCurvesOut = []

# For each line list
for lineList in lineLists:
	# We assume no result to begin with
	pc = None
	# Try each tolerance until one works
	for t in tolerances:
		# Try to get a polycurve
		try:
			pc = PolyCurve.ByJoinedCurves(lineList,t,False,0)
			if pc:
				break
		except:
			pass
	# Append the polycurve
	polyCurvesOut.append(pc)

# Preparing output to Dynamo
OUT = polyCurvesOut

6 Likes

Thanks for the replies all. @GavinCrump @jacob.small @Draxl_Andreas @Nick_Boyts

I think I should explain in more detail what I want to achieve.

This is the length of the input curves. It has a very deep relationship with the value entered as a tolerance.

Curves with a length smaller than the entered tolerance value are deleted and a polycurve is created.
If you don’t enter anything, the join is performed without any curves being deleted because no curves are smaller than the default value of 0.001.
The same thing happens if you enter 0.1.
However, if you enter 1, there is one curve with a length less than 1, so that curve is deleted and joined.
Then, if you enter 1.3, two curves will be deleted,
Entering 1.6 will delete 4 curves.

You can see that only curves with a length smaller than the entered tolerance value are deleted, creating a polycurve with the original curve transformed.

However, the first issue is that I do not want to change this curve in the study I am working on.


To create a slightly non-stick curve, I deleted three short curves from the original curve using the script in the pink box.


Ignore the surface boundary curves in the original sat file.
Let’s assume that the current curve information is the original curve and run the polycurve node again.


With the default tolerance of 0.001, no polycurve is created and a null value is returned.

Now, what value should I enter as the tolerance input value?


It’s too inefficient to put all the numbers in one by one.

From above texts, it seems like it just needs to be a little smaller than the shortest value among the curves’ lengths.


Right! But…


A value smaller than the minimum value of the curve length was entered as the tolerance, but the resulting curve was reduced by one.
A value that is close to or smaller than the minimum length is correct, but depending on the value, it may create an undesirably closed curve and deform the curve.

[Polycurve.ByJoinedCurves] nodes are often used in my process of extracting edges on a curved multi-surface, offsetting, filleting, and project curves on the surface. However, due to this joinTolerance input problem, curve deformation or null value return makes the script doesn’t run smoothly. So I wanted to create a function that could automatically find the optimal tolerance input value.

I have attached related files :slight_smile:
Thanks!
why tolerance values are important.dyn (47.5 KB)
polycurveTest.sat (135.9 KB)

1 Like

Thank you so much @GavinCrump for your help!

But, I don’t know why my result is null :sob:

I attached related files to my added reply post.

It generally means it didn’t manage to generate a valid polycurve from the input curves. You might need to promote each of your nurbs curves into a list I think, or potentially break them down into segments that can come together to form a polycurve.

Without your actual curves I can’t test with your context.

1 Like

I applied it to straight curves on a very simple plane. Still, I got a null value.

I am attaching my sample file for other test.

Thanks @GavinCrump

Polycurve join_ test.dyn (96.8 KB)

Hi @Lynn_Kim,
This works


or you can update python code

1 Like

I appreciate your simple and perfect script. @GavinCrump
This is exactly the solution I wanted. :smiley:

As You said and @Drbohlav showed, I added text about the list level and it works very well.
or Using a node that promotes curve lists before your python script, It also run well. :slight_smile:

This!

or this!

Yay!! I am free from polycurve tolerances! :grin:

4 Likes