Python – Comparing each item in array into another ( Dynamo )

问题内容:

I’m new to programming and only started writing my first lines of code last week.

I’m writing a script in a program called dynamo, this is to be used in my project. After some research, it appears like I need to use python.

What I need to script to do is look at a bunch of lines ( In a program called Revit), pick up the geometry of this line and then detect if any other line has a start point or end point that is in contact with that geometry. I then want to Split that line at that point, this can be done byCurve.SplitByPoints but I need some kind of way to compare ALL lines to ALL start/end points then the output be in a way that the output can be used to split the curve by the point. I can have the line and the point in which to cut in.

I tried to explain that the best I could…

code :

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

dataEnteringNode = IN
Line = IN[0]                    #Line
LPS = IN[1]                     # Line Point Start
LPE = IN[2]                     # Line Point End
LPC = IN[3]                     # Line Point Combined // Maybe not needed
T = 100                         # Tolerance of Intersection
INT1 = []                       # Blank Variable for First Loop Results
INT2 = []                       # Blank Variable for First Loop Results
result1 = []                    # Blank Variable for Second Loop Results
result2 =[]                     # Blank Variable for Second Loop Results

for i in range (0,len(LPS)):
distance = Curve.DistanceTo(LPS[i],Line[i])
INT1.append(distance)

for i in range (0,len(LPE)):
distance = Curve.DistanceTo(LPE[i],Line[i])
INT2.append(distance)

for i in range (0,len(INT1)):
if INT1 > T:
    result1.append('T1')
else:
    result1.append('F1')

for i in range (0,len(INT2)):
if INT2 > T:
    result2.append('T2')
else:
    result2.append('F2')

    Assign your output to the OUT variable.
    OUT = result1, result2

EDIT:

Sorry, I knew explaining this would be tricky for me.

I’ll attempt to simplify it.

I want something like:

if curve intersect with StartPoint or EndPoint
     Curve.split points(Curve,Intersecting_Point)

So im hoping something similar will have it so, when a start or end point intersects a curve, the curve will be split into 2 curves at that point.

So I want to above for to work on a range of lines. I drew a diagram and attempted to upload, but for some reason, it now says I need 10 rep to post an image. meaning I cant upload a new diagram and had to remove the ones I had in?

Thanks for the help! I’m sorry for my explaination skills

问题评论:

1  
Sorry but both what you’re trying to do and what problem(s) you get are quite unclear. Please simplify your code to a MCVE ( stackoverflow.com/help/mcve) and post example inputs and expected outputs.
    
And really, takes a bit time to learn Python – at least the basics like how to iterate over a list 😉
    
What exactly is your question? Does your script fail or provide incorrect results? If you are looking for a general algorithm, try to write a minimum working example without the Revit code, if your problem is not with Revit itself.

原文地址:

https://stackoverflow.com/questions/47754122/python-comparing-each-item-in-array-into-another-dynamo

添加评论

友情链接:蝴蝶教程