I have a VBA script designed under V8i and which worked very well on this version.By wanting to reuse it under CONNECT I have an error that occurs at each execution on my DGN.
Rub-time error '-2147467259 (80004005)' Method 'CreatePropertyHandler' of object '_application' failed
An example of code reproducing the error
Dim oPH As PropertyHandler Dim sArray() As String 'Store all cells in array Set oScanCriteriaCell = New ElementScanCriteria oScanCriteriaCell.ExcludeAllTypes oScanCriteriaCell.IncludeType msdElementTypeCellHeader oScanCriteriaCell.IncludeType msdElementTypeSharedCell oScanCriteriaCell.ExcludeNonGraphical Set oCells = ActiveModelReference.Scan(oScanCriteriaCell) elArrayCell = oCells.BuildArrayFromContents 'Loop in cells to extract sub shape For i = LBound(elArrayCell) To UBound(elArrayCell) Set ee = elArrayCell(i).AsCellElement.GetSubElements elArraySubElement = ee.BuildArrayFromContents For j = LBound(elArraySubElement) To UBound(elArraySubElement) If elArraySubElement(j).IsShapeElement = True Then Set oPH = CreatePropertyHandler(elArraySubElement(j).AsShapeElement) oPH.SelectByAccessString "Count" nEles = oPH.GetValue ReDim sArray(0 To nEles - 1) As String End If Next Next
An example of the type of object on which this occurs
There have been breaking changes between V8i and CONNECT which could explain this problem? Or is it an internal bug?
Hi John,
John Doe said:There have been breaking changes between V8i and CONNECT which could explain this problem? Or is it an internal bug?
it can be both, API is different in some tiny aspects, and also bugs in VBA API are discussed from time to time.
But, at first, I'd like to clarify what the code is expected to do and when I understand it right (it finds shape and counts a number of vertices), why it is so overcomplicated?
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
What about this code, not based on PropertHandler (and not using memory inefficient array):
Public Sub GetShapesVerticesCount() Dim esc As New ElementScanCriteria esc.ExcludeAllTypes esc.IncludeType msdElementTypeCellHeader Dim ee As ElementEnumerator Set ee = ActiveModelReference.Scan(esc) Do While ee.MoveNext Dim cell As CellElement Set cell = ee.Current.AsCellElement Dim cellee As ElementEnumerator Set cellee = cell.GetSubElements Do While cellee.MoveNext If cellee.Current.Type = msdElementTypeShape Then Dim shp As ShapeElement Set shp = cellee.Current.AsShapeElement Dim vertices As Integer vertices = shp.VerticesCount MessageCenter.StatusMessage = "Element id: " & CStr(shp.ID.Low) & ", vertices=" & CStr(vertices) End If Loop Loop End Sub
BTW You search for both normal and shared cells, but the rest of the code works with normal cells only.
there is a known issue with method CreatePropertyHandler and subelements of cells. This issue is addressed as Bug # 777974 and will be fixed with the next CONNECT Update 17.
Best regards,
Artur
Artur Goldsweer said:This issue is addressed as Bug # 777974 and will be fixed with the next CONNECT Update 17.
Thanks for the information (Update 17 seems to be often mentioned in relation to fixed bugs ;-)
On the other hand, as I wrote above, I think PropertyHandler is not required in the discussed code.
Thanks for yours answers.
Artur Goldsweer said:there is a known issue with method CreatePropertyHandler and subelements of cells. This issue is addressed as Bug # 777974 and will be fixed with the next CONNECT Update 17.
So it's a problem related to the version of Microstation.
Jan Ĺ legr said:What about this code, not based on PropertHandler (and not using memory inefficient array):
Thanks for your proposition. The sample code is actually a small part from an old script. I'm not a VBA developer but from what i understand it is necessary to use PropertyHandler to access at SelectByAccessString("Segments[1].Start").
John Doe said:it is necessary to use PropertyHandler to access at SelectByAccessString("Segments[1].Start").
No, PropertyHandler is useless (and probably far slower) in this case, because all information about shape vertices are avaialble in LineElement class directly.
I agree with Jan, PropertyHandler is not required with this example, the MicroStation VBA object library has methods to directly retrieve the shape vertices.
A code snippet like this could be used to read the vertex coordinates:
Dim oShape As ShapeElement Dim pVert() As Point3d '... pVert = oShape.GetVertices For i = LBound(pVert) To UBound(pVert) Debug.Print pVert(i).x, pVert(i).y, pVert(i).z Next