[CE 10.0 VBA] Extracting informations about elements from Microstation CE VBA

Hi,

I want to extract elements informations (text, id, origin) located in Microstation CE and list them in Excel. Following code doesn't work just with TypeText, with TypeTextNode and TypeCell everything is fine. However, on the others computers it works fine, an error is only on my computer. I have the same configs in Microstation CE and VBA as on working computer. It looks like VBA can't see Texts in Microstation CE. Earlier I worked with PowerRailTrack V8i and everything worked, an error occurred after change to Microstation CE. What could be the reason?

Dim myEleEnum As ElementEnumerator
Dim FOUNDCELLNAME As String
Dim FOUNDCELLID As DLong
Dim FOUNDTAGOX As String
Dim FOUNDTAGOY As String
Dim FOUNDTAGOZ As String
Dim otext As TextElement

If myEleEnum.Current.Type = msdElementTypeText Then
    Set otext = myEleEnum.Current
     
    FOUNDCELLNAMET = otext.Text
    FOUNDCELLID = otext.id
    FOUNDCELLOX = otext.Origin.X
    FOUNDCELLOY = otext.Origin.Y
    FOUNDCELLOZ = otext.Origin.Z
    
End If

Parents
  • I want to extract elements...
    Dim myEleEnum As ElementEnumerator

    How do you get myEleEnum?  Show us your code, please?

    I want to extract elements informations (text, id, origin) located in Microstation CE and list them in Excel

    While I'm sure that you enjoy writing VBA, you can achieve your goal using MicroStation Reports.  No programming required!  You can export a Report to Excel.

    Here's an example Text Report.

     
    Regards, Jon Summers
    LA Solutions

  • How do you get myEleEnum?  Show us your code, please?

    Sure, here you go.

    Sub listowanie_new()
    
    Dim askUser As Integer
    
    Dim myDGN As DesignFile
    'Dim myTagSet As TagSet
    Dim myTag As TagElement
    Dim myCell As Element
    Dim myEleEnum As ElementEnumerator
    Dim myEleFilter As New ElementScanCriteria
    Dim myString As String
    Dim myStringCell As String
    
    
    Dim id As DLong
    Dim s As String
    Dim oTarget As Element
    Dim PUNKT As Point3d
    Dim PUNKT2 As Point3d
    Dim PUNKT3 As Point3d
    Dim PUNKT4 As Point3d
    
     PUNKT.X = 0
     PUNKT.Y = 0
     PUNKT.Z = 0
     
     PUNKT2.X = 20
     PUNKT2.Y = 20
     PUNKT2.Z = 0
    
    
    Dim oScanCriteria As New ElementScanCriteria
    Dim oEnumerator As ElementEnumerator
    Dim oelement As Element
    Dim ocell As CellElement
    Dim otext As TextElement
    Dim otextNo As TextNodeElement
    Dim oline As LineElement
    Dim olinestring As LineElement
    Dim oellipse As EllipseElement
    Dim oshape As ShapeElement
    
    Dim FOUNDTAGNAME As String
    Dim FOUNDTAGID As DLong
    Dim FOUNDTAGVERTEX As String
    Dim FOUNDTAG1 As String
    Dim FOUNDTAG2 As String
    Dim FOUNDTAG3 As String
    Dim FOUNDTAGOX As String
    Dim FOUNDTAGOY As String
    Dim FOUNDTAGOZ As String
    
    Dim FOUNDCELLNAME As String
    Dim FOUNDCELLNAMET As String
    Dim FOUNDCELLNAME1 As String
    
    Dim FOUNDCELLID As DLong
    Dim FOUNDCELLVERTEX As String
    Dim FOUNDCELL1 As String
    Dim FOUNDCELL2 As String
    Dim FOUNDCELL3 As String
    Dim FOUNDCELLOX As String
    Dim FOUNDCELLOY As String
    Dim FOUNDCELLOZ As String
    Dim FOUNDCELLDES As String
    
    Dim EScanCriteria As New ElementScanCriteria
    Dim EEnumerator As ElementEnumerator
    Dim Eelement As Element
    
    Dim ee As ElementEnumerator
    Dim es As New ElementScanCriteria
    Dim elArray() As Element
    Dim i As Long
    Dim iStart As Long
    Dim iEnd As Long
    Dim p As Integer
    Dim t As Integer
    
    p = 2
    
    Dim ogranicz As Long
    'ogranicz = 250
    
    Dim SCIEZKA As String
    
    
    Dim Einput As String
    Einput = "lista"
    
    Dim Winput As String
    Winput = "lista_work"
    
    
    'AKTYWUJ LORKSHITA
    Worksheets(Winput).Activate
    
    
    Range("A2:L2000").Select
    Selection.ClearContents
    Range("A2").Select
    
    
    'AKTYWUJ LORKSHITA
    Worksheets(Einput).Activate
    
    
    Range("A2:L2000").Select
    Selection.ClearContents
    Range("A2").Select
    Range("k2").Select
    
    
    
    'PRZYPISZ SCIEZKE PLIKU DO ZMIENNEJ SCIEZKA
    'SCIEZKA = FileNM
    SCIEZKA = "C:\JZSI\TCtest\kabel_test\3740-031_001.dgn"
    
    
    Dim myUstation As MicroStationDGN.Application
    Set myUstation = New MicroStationDGN.Application
    
    'OTWORZ PLIK PO  ZMIENNEJ SCIEZKA
    Set dFile = myUstation.OpenDesignFile(SCIEZKA, False)
    
    
    myEleFilter.ExcludeAllTypes
    myEleFilter.IncludeType msdElementTypeText
    myEleFilter.IncludeType msdElementTypeTextNode
    
    Set myEleEnum = dFile.Models(1).Scan(myEleFilter)
    
    Dim textNodeI As Integer
    
    While myEleEnum.MoveNext
    
    If myEleEnum.Current.Type = msdElementTypeText Then
        Set otext = myEleEnum.Current
        
        FOUNDCELLNAMET = otext.Text
        FOUNDCELLID = otext.id
        FOUNDCELLOX = otext.Origin.X
        FOUNDCELLOY = otext.Origin.Y
        FOUNDCELLOZ = otext.Origin.Z
    
    End If
    
    Wend
    
    End Sub
    

    While I'm sure that you enjoy writing VBA, you can achieve your goal using MicroStation Reports.  No programming required!  You can export a Report to Excel.

    Thank you for this advice, but it is a case where I have to do it by macro for more automatization.

  • Hi Juliusz,

    Sure, here you go.

    Based on your code it seems it's not MicroStation VBA in a meaning "code running in MicroStation"!

    It's crucial to provide all details, especial when it's so critical fact that changes complete context.

    When writing code accessing MicroStation from outside, did you study MicroStation VBA for specifics when this approach is used? The most of VBA code can be the same, but some parts (e.g. ScanCriteria) have to be modified.

    Search for topics like CreateObjectInMicroStation method, Connecting to MicroStation from a Separate Process and similar.

    What could be the reason?

    Based on new information I can imagine that the problem is caused by code itself (not adapted to external process access properly) or the code works fine, but there is a problem with MicroStation installation, because this situation is more sensitive everything is configured properly (registration of correct VBA with MicroStation etc.).

    With regards,

      Jan

  • Dim myUstation As MicroStationDGN.Application
    Based on your code it seems it's not MicroStation VBA in a meaning "code running in MicroStation"!

    Where is your VBA project created?

    • In MicroStation
    • In Excel
    • In another app

     
    Regards, Jon Summers
    LA Solutions

  • Where is your VBA project created?

    In Excel.

    I will try reinstall Micrtostation

    but there is a problem with MicroStation installation

    I will try reinstall Micrtostation.

  • In Excel.

    If you start the code from Excel (why such crucial information has not been shared from very first post?), the first step has to be to adapt MicroStation VBA code accordingly to requirements described in chapters I mentioned earlier.

    To reinstall MicroStation and to hope potential bugs in the code itself will be solved does not make any sense.

    Regards,

      Jan

Reply Children
No Data