How to get Element at Point is Intersection

Hi

I have multi Structural Framing Elements, I select few elements
Then check Intersection of Elements (this is Start Point and End Point)
How to get pair: Point - Element

Example:
Select 2 element b and c then check element intersect → get: a,d and b,e
How to get Pair: Point -Element
p1-d
p2-a
p3-b
p4-e


Thank Advance!!!

I think this is what you’re looking for?

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
all_beam_curves = IN[0]
all_beam_elems = IN[1]
selected_beams = IN[2]

	
def BeamIntersecter(beam):
	# Get Start & End Point
	StrtEndPts = [beam.StartPoint,beam.EndPoint]
	intersections = []
	
	# For each point in selected curves start end
	for point in StrtEndPts:
		# for each curve in all the beams 
		for index, curve in enumerate(all_beam_curves):
			# If the start end point intersects the curve
			if Geometry.DoesIntersect(point, curve):
				# And if the start point of that curve is not in StrtEndPts
				if curve.StartPoint not in StrtEndPts:
					# Append the point and beam element
					intersections.append([point, curve])
					# UNFREEZE THE BELOW LINE IF YOU WANT TO RETURN THE BEAM ELEMENT RATHER THAN ITS LOCATION CURVE
					#intersections.append([point, all_beam_elems[index]])

	return intersections
	
OUT = [BeamIntersecter(curve) for curve in selected_beams]

You tagged this with Python so I went down that route and assumed you can edit it if you need to slightly change what is being output.

Hope it helps

3 Likes

Hello, you tried if it was possible via bimorph (see link) to see if the category is possible.

From your script after filtering only Points (List.RemoveIfNot) then getting index and GetitematIndex on list elements

Cordially
christian.stan

1 Like

Awesome!! Thank you<3

But I think need change to list if select 1 element

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

#create list
if isinstance(IN[0],list):
	all_beam_curves = IN[0]
else:
	all_beam_curves = [IN[0]]

if isinstance(IN[1],list):
	all_beam_elems = IN[1]
else:
	all_beam_elems = [IN[1]]

if isinstance(IN[2],list):
	selected_beams = IN[2]
else:
	selected_beams = [IN[2]]


def BeamIntersecter(beam):
	# Get Start & End Point
	StrtEndPts = [beam.StartPoint,beam.EndPoint]
	intersections = []
	
	# For each point in selected curves start end
	for point in StrtEndPts:
		# for each curve in all the beams 
		for index, curve in enumerate(all_beam_curves):
			# If the start end point intersects the curve
			if Geometry.DoesIntersect(point, curve):
				# And if the start point of that curve is not in StrtEndPts
				if curve.StartPoint not in StrtEndPts:
					# Append the point and beam element
					#intersections.append([point, curve])
					# UNFREEZE THE BELOW LINE IF YOU WANT TO RETURN THE BEAM ELEMENT RATHER THAN ITS LOCATION CURVE
					intersections.append([point, all_beam_elems[index]])

	return intersections

OUT = [BeamIntersecter(curve) for curve in selected_beams]

image

1 Like

Great, glad it worked.

Ah yes, I didn’t check it with 1 beam input.

Top tip though, instead of writing out your ‘ininstance’ check for each input, write another function and pass your inputs through it :slight_smile:, something like this:

def tolist(obj1):
	if hasattr(obj1, "__iter__"): return obj1
	else: return [obj1]

all_beam_curves = tolist(IN[0])
all_beam_elems = tolist(IN[1])
selected_beams = tolist(IN[2])

This uses a slightly different method for checking if the item is a list. Rather than checking if it is an instance, instead you are checking if the item has the attribute of being iterable ("__iter__").

The only reason I used this method over the isinstance one is because it’s the main method I use so I simply copied and pasted it haha.

Hope this helps,
Jake

1 Like

dynamo solution

1 Like