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?
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,
Ian Sage said: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
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
VBA's built-in file and folder functions are primitive. They derive from Microsoft's first attempts at providing a BASIC language.
Fortunately, we can do better! Windows Scripting Runtime is a Microsoft COM plug-in that make file & folder computations simple. It's almost certainly installed on your computer.
Regards, Jon Summers LA Solutions
Awesome. I look forward to trying this.