You are currently reviewing an older revision of this page.
In the previous part, we read the endpoints of all lines of a drawing model and exported it to a text file. The text file, however, is rather confusing and difficult to interpret. We can fix this issue by summarizing each set of data about a line to a line of text in the file seperated with a semicolon (;).We can also create a .csv file to open directly in Excel.In order to identify the data that is in the beginning of the file, a header must be added so that each column can be identified. One possible approach might look like the following:
Sub elementinfo () Dim ele As Line Element Dim Ee As ElementEnumerator Dim startpoint, endpoint As Point3D Dim Sc As New ElementScanCriteria Dim header line As String Sc.ExcludeAllTypes Sc.IncludeType msdElementTypeLine Dim file As String file = ActiveDesignFile.FullName + "- Daten.csv" Open file For Output As #1 Header = "early X; Y early; early Z; Ibid X, Y End; End Z" Print # 1, header Set Ee = ActiveModelReference.GraphicalElementCache.Scan(Sc) Do While Ee.MoveNext Set ele = Ee.Current.AsLineElement startpoint = ele.startPoint Endpoint = ele.EndPoint Line = startpoint.X & ";" & startpoint.Y & ";" & startpoint.Z & ";" Line = Line & endppoint.X & ";" & endpoint.Y & ";" & endpoint.Z Print # 1, Line Loop Close #1 End Sub
The previous issues each take place in a seperate text or CSV file when using such programs that have several drawings collected in a file. There are different ways to achieve this, but we will use environment variables in the file name stored including the path.The beginning of the configuration variable is retrieved and will be used as the output file. If this variable is not set, the routine will fail with an appropriate error message.The configuration variable can be defined in Microstation as a user variable. One way to get there is to use the "Configuration" option under the "Workspace" dropdown menu. Hitting "New" will open the following menu, where the variable can be set.
In the configuration variables, we can access the Active Workspace object. It provides several methods, which might look something like this:
If ActiveWorkspace.IsConfigurationVariableDefined("MyOutputFile") Then file = ActiveWorkspace.ConfigurationVariableValue("MyOutputFile") Else MsgBox "The Variable My output file is undefined, processing canceled" , vbCritical Exit Sub End If
In the header, I will add a column that retrieves the complete drawing name with a path and ultimately retrieves the data to be added to the .csv file. We will "append" the open file instead of
"output". Overall this leads to the following routine:
Sub elementinfo () Dim ele As Line Element Dim Ee As ElementEnumerator Dim startpoint, endpoint As Point3D Dim Sc As New ElementScanCriteria Dim header line As String Sc.ExcludeAllTypes Sc.IncludeType msdElementTypeLine Dim file As String If ActiveWorkspace.IsConfigurationVariableDefined("MyOutputFile") Then file = ActiveWorkspace.ConfigurationVariableValue("MyOutputFile") Else MsgBox "The Variable My output file is undefined, processing canceled" , vbCritical Exit Sub End If 'File = ActiveDesignFile.FullName + "- Daten.csv" Open datei For Append As #1 Header = "early X; Y early; early Z; Ibid X, Y End; End Z;" & ActiveDesignFile.FullName Print # 1, header Set Ee = ActiveModelReference.GraphicalElementCache.Scan(Sc) Do While Ee.MoveNext Set ele = Ee.Current.AsLineElement startpoint = ele.startPoint Endpoint = ele.EndPoint Line = startpoint.X & ";" & startpoint.Y & ";" & startpoint.Z & ";" Line = Line & endpoint.X & ";" & endpoint.Y & ";" & endpoint.Z Print # 1, Line Loop Close #1 End Sub
To apply this routine in batch mode, we only need the Keyin to start the routine. In MicroStation Batch Process a text file is required where the commands would be listed to be executed. In our
case, we will use Keyin to call the VBA routine.
One should take the .MVBA project files in one of the VBA directories that are listed in the configuration variables MS_VBASEARCHDIRECTORIES. By default, they are located in \WorkSpace\System\VBA. If you store your files there, you can use it simultaneously with the following Keyin to load and run:
vba run [default]module1.elementinfo
If the subroutine named element info is clear, you can use this shorthand instead of the module name (the square brackets should remain): VBA Run [default] Element info This command line is derived from this generic Keyin: VBA run [projectname] modulename.subroutine
So far, we know how to read element information and output it to a file.
<< RETURN TO PART 3 << >> CONTINUE TO PART 5 >>