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.StartDynamicsEnd SubPrivate 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 IfEnd Sub' -------------------------------------------------------Private Sub IPrimitiveCommandEvents_Keyin(ByVal Keyin As String)End SubPrivate 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 MeEnd SubPrivate Sub IPrimitiveCommandEvents_Start() ShowCommand "VBA Place Shape Example" ShowPrompt "Place first point for shape" Erase m_arrayPoints m_nPoints = 0End 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.featureoFeature.Name = <feature name> 'e.g. oFeature.Name = "PowerLine"oFeature.InitializeProperties "placing"oFeature.Geometry = oShape' You can also modify default values of the featureoFeature.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:
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hello, Jan
Thanks a lot!! Your help is great!!!!
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)
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.
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)