[V8i VBA] is possible set feature to created shape element?

Hello,

It's again question about creating own form instead build-in to place a polygon with feature.

I create a shape using Bentley example for VBA:

Private Sub IPrimitiveCommandEvents_DataPoint(point As Point3d, _
    ByVal View As View)
    m_nPoints = m_nPoints + 1
    CommandState.AccuDrawHints.SetOrigin point
    ReDim Preserve m_arrayPoints(0 To m_nPoints - 1)   
    m_arrayPoints(m_nPoints - 1) = point
    If (2 < m_nPoints) Then
        ShowPrompt "Place next point, reset to close the shape"
    Else
        ShowPrompt "Place next point"
    End If   
    CommandState.StartDynamics

End Sub

Private Sub IPrimitiveCommandEvents_Dynamics(point As Point3d, _
    ByVal oView As View, ByVal drawMode As MsdDrawingMode)

    If (1 = m_nPoints) Then
        '   Draw line from first point to current cursor location
        Dim oLine             As LineElement
        Set oLine = CreateLineElement2(Nothing, m_arrayPoints(0), point)
        oLine.Redraw drawMode
    Else
        Dim i           As Integer
        Dim points()    As Point3d
        ReDim points(m_nPoints)
        For i = 0 To m_nPoints - 1
            points(i) = m_arrayPoints(i)
        Next i
        points(m_nPoints) = point ' current cursor location
        Dim oShape As ShapeElement
        Set oShape = CreateShapeElement1(Nothing, points, msdFillModeUseActive)
        oShape.Redraw drawMode
    End If
End Sub
' -------------------------------------------------------
Private Sub IPrimitiveCommandEvents_Keyin(ByVal Keyin As String)
End Sub

Private Sub IPrimitiveCommandEvents_Reset()
    Dim nPoints     As Integer
    If (2 < m_nPoints) Then
       '' Dim oShapes As ShapeElement
        Set oShapes = CreateShapeElement1(Nothing, m_arrayPoints(), msdFillModeUseActive)
        ActiveModelReference.AddElement oShapes
        oShapes.Redraw
        ''oShapes.IsHighlighted = True
    End If   
    CommandState.StartPrimitive Me
End Sub

Private Sub IPrimitiveCommandEvents_Start()
    ShowCommand "VBA Place Shape Example"
    ShowPrompt "Place first point for shape"
    Erase m_arrayPoints
    m_nPoints = 0
End Sub

How  I could add feature information to my created shape?

Sincerely Yours,

Julia

  • Hi Julia,

    in VBA, the code can look like this:

    ' Create a shape here
    ' Set oShape = CreateShapeElement1(Nothing, vertices, msdFillModeUseActive)
    ' It's what you have already.

    Dim oFeature As New xft.feature
    oFeature.Name = <feature name> 'e.g. oFeature.Name = "PowerLine"
    oFeature.InitializeProperties "placing"
    oFeature.Geometry = oShape
    ' You can also modify default values of the feature
    oFeature.SetProperty <propety name>, <value> 'e.g. oFeature.SetProperty "Voltage", "12kV"
    oFeature.Write False

    I suppose you will be able to transform it to C# code easily. Openly, I don't know if it's the best and/or recommended way, but it works fine so far for me ;-)

    In general, what you have to do to create a feature in own way:

    • Create MicroStation element, which will be the feature geometry, but don't add it to an active model.
    • Create feature.
    • Set the element as the feature geometry.
    • (optionally) Initialize properties, "placing" key is often good choice, because it will initialize feature properties the same way as it will be done if you use GUI.
    • Modify property values if required and apply changes.
    • Write the feature to the design file.

    With regards,

      Jan

  • Hello, Jan

    Thanks a lot!! Your help is great!!!!

    Sincerely Yours,

    Julia

  • Can I hope You helping me one more time?

    I found such problem: some features can place without problem, but other placed without level information(it's show as shape with black line), but when open it for editing shows right feature information. And when it's placing information about feature also is correct. I didn't find any  dependence why one shape with feature information is placed correct, but other - not (when I'm placing this "bad" feature with build-in form it placed and shows correct)

    Desktop.rar
  • Hi Julia,

    try to use feature.ApplyAttributeChanges method just before writing the feature to a design file. In parallel it would be good to check how features are defined and how they differ.

    With regards,

     Jan

  • Hello, Jan

    I use  feature.ApplyAttributeChanges in code:

       Dim oFeature As New xft.feature

       Dim nPoints     As Integer

       If (2 < m_nPoints) Then

           Dim oShapes As ShapeElement

           Set oShapes = CreateShapeElement1(Nothing, m_arrayPoints(), msdFillModeUseActive)

           Set oShapes.Level = ActiveDesignFile.Levels.Find(frmComboPlace.txtNewPType.Value)

           ''ActiveModelReference.AddElement oShapes

          '' oShapes.Redraw

           oFeature.Name = "Aizsargjoslas"

           oFeature.InitializeProperties "placing"

           oFeature.Geometry = oShapes

           oFeature.SetProperty "Piezimes", frmComboPlace.txtPNote.Value

           oFeature.SetProperty "Veids", frmComboPlace.txtNewPType.Value

           oFeature.ApplyAttributeChanges

           oFeature.Display msdDrawingModeNormal

           oFeature.Write (False)

       End If

    After adding line  Set oShapes.Level = ActiveDesignFile.Levels.Find(frmComboPlace.txtNewPType.Value) now level is when creating, but still shapes shows as default.

    compare 2 features (which shows correct and incorrect I coulnd't find any differ)