# Intersection

Hi Friends !

I´m trying to create a function that return Z when there are a intersection in my DGNApplication . . . How can I give Z code of my Element2? This is my code...

Thanks!

Private Sub ILocateCommandEvents_LocateFilter(ByVal Element As Element, point As Point3d, Accepted As Boolean)

Dim ScanEnumerator  As ElementEnumerator
Dim ScanCriteria    As New ElementScanCriteria
Dim Element2      As Element
Dim t               As Integer
Dim points()        As Point3d

Set ScanEnumerator = ActiveModelReference.Scan(ScanCriteria)
Do While ScanEnumerator.MoveNext

Set Element2 = ScanEnumerator.Current

If Element.IsIntersectableElement Then

points = Element.AsIntersectableElement.GetIntersectionPoints(Element2, Matrix3dIdentity)

End If

For t = 0 To UBound(points)

If (UBound(points) = 0) Then
Set oTextEle = CreateTextElement1(Nothing, points(t).Z, points(t), Matrix3dIdentity)
End If
Next
Loop

End Sub

• rodrigo.teodoro said:
points = Element.AsIntersectableElement.GetIntersectionPoints(Element2, Matrix3dIdentity)

It's a little confusing.  VBA help says: "For three dimensional elements, GetIntersectionPoints returns apparent intersections, ignoring differences along the Z-axis".  The Matrix3d argument specifies a rotation: "The coordinate system in which the apparent intersections are calculated".

You have an array of Point3d, which are 'apparent intersections' in 3D.  Try using Element.ProjectPointOnPerpendicular2  to find the real intersection for each point.

Regards, Jon Summers
LA Solutions

• Just a few small changes to your sub got it working:

1. Added a Dim statement for oTextEle
In the VBA Editor select Tools > Options and toggle on the setting for Require Variable Declaration. This will place on Option Explicit statement at the top of each new module and catch problems like this.

2. Moved the For t = 0 To UBound(points) loop inside the If Element.IsIntersectableElement block
The way the code was previously it was attempting to iterate through the points array of intersecting points even if there were no intersecting points found. This raised an error because the array was undefined.

The updated sub that worked for me is shown below.

`Private Sub ILocateCommandEvents_LocateFilter(ByVal Element As Element, point As Point3d, Accepted As Boolean)    Dim ScanEnumerator  As ElementEnumerator    Dim ScanCriteria    As New ElementScanCriteria    Dim Element2      As Element    Dim t               As Integer    Dim points()        As Point3d    Dim oTextEle As TextElement        Set ScanEnumerator = ActiveModelReference.Scan(ScanCriteria)        Do While ScanEnumerator.MoveNext        Set Element2 = ScanEnumerator.Current                If Element.IsIntersectableElement Then           points = Element.AsIntersectableElement.GetIntersectionPoints(Element2, Matrix3dIdentity)                       For t = 0 To UBound(points)                If (UBound(points) = 0) Then                    Set oTextEle = CreateTextElement1(Nothing, points(t).Z, points(t), Matrix3dIdentity)                    ActiveModelReference.AddElement oTextEle                End If            Next        End If    LoopEnd Sub`

Rod Wing
Senior Systems Analyst