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)
            ActiveModelReference.AddElement oTextEle
    End If
        Next
    Loop

End Sub

Parents
  • 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
    Loop
    End Sub

    Rod Wing
    Senior Systems Analyst

  • My dear,

    I get to give point Z from ElementEnumerator. Now I have to put the same rotation os my ElementEnumerator in my text. How can I do it?

    This is my code! Thanks!

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

        Dim counter As Integer

       Dim t As Integer

       Dim oEnumerator As ElementEnumerator

       Dim oScanCriteria As New ElementScanCriteria

       Dim myElement As Element

       Dim points() As Point3d

       Dim pointElemento() As Point3d

       Dim oTextEle As TextElement

       Dim coordZFormatada As String

       Dim oMatrix As Matrix3d

       Set elementoSelecionado = Element

       oScanCriteria.ExcludeAllTypes

       oScanCriteria.IncludeColor (175)

       oScanCriteria.IncludeType msdElementTypeBsplineCurve

       Set oEnumerator = ActiveModelReference.Scan(oScanCriteria)

       Do While oEnumerator.MoveNext

           counter = counter + 1

           Set myElement = oEnumerator.Current

           If myElement.IsIntersectableElement Then

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

           End If

           For t = 0 To UBound(points)

               coordZFormatada = Replace(Format(CDbl(points(t).Z), "#,##"), "-", "")

               Point.X = points(t).X

               Point.Y = points(t).Y

               Point.Z = points(t).Z

               Set oTextEle = CreateTextElement1(Nothing, coordZFormatada, Point, oMatrix)

               ActiveModelReference.AddElement oTextEle

           Next

       Loop

    End Sub

  • Unknown said:

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

        Dim counter As Integer

       Dim t As Integer

       Dim oEnumerator As ElementEnumerator

       Dim oScanCriteria As New ElementScanCriteria

    I'm not sure what you are trying to do here, but ILocateCommandEvents_LocateFilter is — or should be — a simple Subroutine that tests oElement . If the element passes your filter, then set accepted to True.  For example, if you are looking for TextElements, then this subroutine would look like this …

    Private Sub ILocateCommandEvents_LocateFilter( _
          ByVal oElement As Element, _
          point As Point3d, _
          accepted As Boolean)
       If msdElementTypeTex = oElement.Type Then
         accepted = True
       Else
         accepted = False
       EndIf
    End Sub

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

Reply
  • Unknown said:

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

        Dim counter As Integer

       Dim t As Integer

       Dim oEnumerator As ElementEnumerator

       Dim oScanCriteria As New ElementScanCriteria

    I'm not sure what you are trying to do here, but ILocateCommandEvents_LocateFilter is — or should be — a simple Subroutine that tests oElement . If the element passes your filter, then set accepted to True.  For example, if you are looking for TextElements, then this subroutine would look like this …

    Private Sub ILocateCommandEvents_LocateFilter( _
          ByVal oElement As Element, _
          point As Point3d, _
          accepted As Boolean)
       If msdElementTypeTex = oElement.Type Then
         accepted = True
       Else
         accepted = False
       EndIf
    End Sub

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

Children
No Data