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
Hi Juliusz,
Juliusz Szczeblewski said:However, on the others computers it works fine, an error is only on my computer.
What error is reported. To say "error" provides no valuable information. Is there any VBA error code reported? Or something else happens?
Juliusz Szczeblewski said:It looks like VBA can't see Texts in Microstation CE.
What does it mean? ... can't see? ... the classes are not available in VBA Editor?
Juliusz Szczeblewski said:What could be the reason?
At first you should test whether there is a problem with MicroStation CE + VBA installation, or in VBA macro or somewhere else.
Do other VBA macros (e.g. examples delivered with MicroStation installation) work fine?
Is correct library referenced to your VBA project?
With regards,
Jan
P.S. Please read and follow this forum best practices, especially what subject format is recommended to be used and what information should be always provided (e.g. exact product version, Windows version...).
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Jan Šlegr said:What error is reported. To say "error" provides no valuable information. Is there any VBA error code reported? Or something else happens?
That kind of errror in this place.
Jan Šlegr said:What does it mean? ... can't see? ... the classes are not available in VBA Editor?
As on the upper screenshot, FOUNDCELLNAMET is empty.
On the drawing in dgn I have Text and TextNode, for TextNode code is executing correctly, for Text that error occures.
Jan Šlegr said:At first you should test whether there is a problem with MicroStation CE + VBA installation, or in VBA macro or somewhere else.
I don't know where could be problem. I tried a lot of things and it doesn't work just in this moment. Also, my collegue has the same computer, configs and everything else and on his computer with the same files this code is executed corectly.
Jan Šlegr said:Do other VBA macros (e.g. examples delivered with MicroStation installation) work fine?
Yes, other macros work fine.
Jan Šlegr said:Is correct library referenced to your VBA project?
I think yes.
Juliusz Szczeblewski said:I want to extract elements...Dim myEleEnum As ElementEnumerator
Dim myEleEnum As ElementEnumerator
How do you get myEleEnum? Show us your code, please?
myEleEnum
Juliusz Szczeblewski said: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
Jon Summers said: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
Jon Summers said: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.
Juliusz Szczeblewski said: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.
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.).
Juliusz Szczeblewski said:Dim myUstation As MicroStationDGN.Application
Dim myUstation As MicroStationDGN.Application
Jan Šlegr said:Based on your code it seems it's not MicroStation VBA in a meaning "code running in MicroStation"!
Where is your VBA project created?
Jon Summers said:Where is your VBA project created?
In Excel.
I will try reinstall Micrtostation
Jan Šlegr said: but there is a problem with MicroStation installation
I will try reinstall Micrtostation.
Juliusz Szczeblewski said: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,