Fence Get Contents Elements

Hi Group,

Please have look my code,i have problem with fence Getcontents.Please correct me if i am wrong.


Sub Fence()

Dim Elm As Element
Dim pElm As Element
Dim FElm As Element
Dim point As Point3d
Dim Oview As view
Dim slby As ElementScanCriteria
Set slby = New ElementScanCriteria
Dim ofen As Fence
Dim EnumFen As ElementEnumerator
slby.ExcludeAllLevels
slby.IncludeLevel ActiveModelReference.Levels("island")


Dim PEnum As ElementEnumerator
Set PEnum = ActiveModelReference.Scan(slby)

Do While PEnum.MoveNext
    Set pElm = PEnum.Current
    point.X = pElm.AsLineElement.startPoint.X + 1
    point.Y = pElm.AsLineElement.startPoint.Y + 1
    point.Z = pElm.AsLineElement.startPoint.Z
    CadInputQueue.SendCommand "PLACE FENCE ICON "
    CadInputQueue.SendCommand "choose element"
    CadInputQueue.SendCommand "xy=0,0"
    CadInputQueue.SendCommand "PLACE FENCE ICON "
    CadInputQueue.SendCommand "LOCK FENCE OVERLAP "
    SetCExpressionValue "tcb->msToolSettings.fence.placeMode", 7, ""
    CadInputQueue.SendCommand "PLACE FENCE ICON "
    CadInputQueue.SendDataPoint point, 1
    Set ofen = ActiveDesignFile.Fence
        If ofen.IsDefined Then                            ===============>here its showing fence false
        Set EnumFen = ofen.GetContents
        EnumFen.Reset
        Do While EnumFen.MoveNext
        Set FElm = EnumFen.Current
        FElm.Color = 2
        FElm.Rewrite
        Loop

        Else


        End If

Loop

End Sub

Regards,

Venugopal

  • Simplify your code!

    Write one procedure that creates a fence.  Write a second procedure that enumerates a fence contents.

    Then you can test your fence enumerator independently of the code that creates a fence.

    It's not clear what you intend your code to do.  You scan a model for any element on a specified level.  Then, you make an assumption that the current element is a LineElement and extract data from it.

     
    Regards, Jon Summers
    LA Solutions

  • Hi,

       I am using Microstation V8 2004. My intention is ,I have a point in one level, from that point I need to select the boundary lines.

    Regards

    Venugopal

  • Unknown said:
    I have a point in one level

    Is that point a zero-length line?  Alternatives are a cell or text element.  Add an element type filter to your ScanCriteria to be sure that you find only the right types of element.

    oCriteria.ExcludeAllTypes

    oCriteria.IncludeType msdTypeLine

    Unknown said:
    From that point I need to select the boundary lines

    What do you mean by 'boundary lines'?

     
    Regards, Jon Summers
    LA Solutions

  • Hi,

       yes that is Zero length line.Boundary lines means surrounded by the Zero Length line boundary.

    Please refer my Screen Jpg.

    Regards

    Venugopal

  • Good illustration!

    Boundary Polygons

    You're attempting to recreate the functionality provided by Geographic Information System (GIS) products such as MicroStation GeoGraphics (Bentley Map in V8i).

    You may find VBA's mdlPolygon_pointInsideXY function useful.

    Assuming that the boundary lines are on a named layer, you can construct a set of polygons (MicroStation shape or complex shape elements). Then you can test your point against each polygon to find which boundary contains it.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

  • So, following up with what Jon has said so far, it appears that the issue with your original code may be that the element being used to set your fence initially cannot be 'interpreted' as a line element (since it just grabs the first element the scan, and could be anything), and therefore this code:

    point.X = pElm.AsLineElement.startPoint.X + 1
    point.Y = pElm.AsLineElement.startPoint.Y + 1
    point.Z = pElm.AsLineElement.startPoint.Z

    is not setting the point like you think it is in order to set the fence.

    If you take Jon's advice of filtering your scan for the right type of element, I think you will be able to be confident that the fence is getting set.

  • Thanks jon, Jhartog.Let me try and then i will come to you

    Regards

    Venu