My goal is DGN to DWG conversion starting from an Excel workbook using VBA.
I have developed VBA macros to use AutoCAD from Excel and am venturing into VBA macros to use Microstation from Excel.
I have Microstation V8i on a Windows 10 computer. I hope to ask a minimum number of questions and then start seeing the light bulbs illuminate (We'll see how that goes).
Question #1
My first step when using AutoCAD from Excel involves the lines below to identify the application I wish to access.
Public Const AC_Ver As String = "AutoCAD.Application.23" 'AC 2019Public AcadApp As AcadApplication
What would be comparable code to use as a first step in using Microstation from Excel?
Which version of MicroStation are you using?
Is there a reason you want to perform these conversions yourself? MicroStation has a built-in highly customizable file format converter. All your conversion options can be set in an Excel file and used to bulk process the conversions.
If you are still wanting to go the VBA route I would highly recommend getting the "Learning MicroStation VBA" book. It was written for V8i but is still pretty relevant for VBA in CONNECT editions. https://www.amazon.com/Learning-MicroStation-VBA-Jerry-Winters/dp/0971414181
This book covers exactly what you are asking in Chapter 37.
James Milam said:My goal is DGN to DWG conversion
MicroStation can open and save native DGN files and DWG files.
What do you want to automate with VBA that MicroStation can't already do? Where does Excel come into your operations?
Regards, Jon Summers LA Solutions
I have a large number of files to convert and am seeking an efficient method of accomplishing this.
i.e. - I don't want to individually open & save this may files.
Oops!
this MANY files, not this MAY files
Thanks
Here's a link on how to use the batch conversion utility: (This shows using ProStructures but it is in the other DGN software also) https://communities.bentley.com/products/prostructures/w/structural_drafting_and_detailing__wiki/45173/how-to-convert-dgn-to-dwg-by-batch-converter
Where Excel enters the picture
For me, Excel works as a good tool for getting information to macros. It's common to have several directories of data or files I want to process in the same manner. Typically, I'll have a column of directory names, start the macro and it will sequentially process them all. If I need to do the same processing for other directories, Excel makes it easy to change the directories in the spreadsheet. Many applications are recurring. I can copy and paste directory names from a master spreadsheet to various macro spreadsheets to speed processing.
James Milam said:Excel works as a good tool for getting information to macros
Here's an article about using Excel VBA from MicroStation VBA.
You want to do things the other way around...
MicroStationDGN.Application
OpenDesignFile
OpenDesignFileForProgram
I'll check it out - Thanks!
James,
Without much direct knowledge into what you are trying to do, here is a bit of code I use to batch convert DGN files to DWG using VBA within MicroStation. In this example a small GUI is populated with a list of files that exist in the same directory as the file that is active in MicroStation. It then creates a subfolder if it does not exist and effectively does a Save As of each selected file into that new folder. It sounds like you may want to modify the incoming list to be a list in some other spreadsheet but the actions once the filepath/filename are established should be the same.
Dim val As String Dim cFullName As String Dim oFile As DesignFile Dim DGNPath As String Dim cListFile As Scripting.File Dim i As Long Dim cSelectFile As String Dim cSelectPath As String cSelectFile = ListFiles.Name cSelectPath = ActiveDesignFile.Path cFullName = cSelectPath & "\" & cSelectFile DGNPath = ActiveDesignFile.Path & "\DGN" If Dir(DGNPath, vbDirectory) = vbNullString Then MkDir ActiveDesignFile.Path & "\DGN" End If For i = 0 To ListFiles.ListCount - 1 If ListFiles.Selected(i) = True Then val = ListFiles.List(i) cFullName = cSelectPath & "\" & val Set oFile = OpenDesignFileForProgram(cFullName) 'Saves to whatever format is currently set in the Save As dialog options oFile.SaveAs cSelectPath & "\DGN\" & Left(val, Len(val) - 3) & "dgn", False, msdDesignFileFormatV8 End If Next i
Cheers,