Hi,
Im new to coding in Microstation, have a bit of VBA AutoCAD experience. Im trying to insert a cell into a DGN via VBA (have many todo).
I have attached a cell library via "AttachCellLibrary". When trying to set the active cell I get "Unknown error"
CadInputQueue.SendCommand "PLACE CELL ICON" 'insert active cell
This has been cobbled together from a recorded macro and a bit of playing around.
Sub AddRevBlock() Dim startPoint As Point3d Dim point As Point3d, point2 As Point3d Dim CellLib As String Dim DGNSize As String CadInputQueue.SendCommand "AS=1" 'set active scale to 1 CadInputQueue.SendCommand "AA=0" 'set active rotation to 0 DGNSize = GetTitleSize 'get dgn size
' Start a command CadInputQueue.SendCommand "DIALOG CELLMAINTENANCE TOGGLE" ' not sure what this is for, MS macro recording added it
'attach the standard cell lib CellLib = "D:\Microstation\RevBlock.CEL" AttachCellLibrary CellLib 'Call AttachedCellLib
ActiveSettings.CellName = "REV Block"
' Send a data point to the current command point.X = startPoint.X point.Y = startPoint.Y point.Z = startPoint.Z CadInputQueue.SendDataPoint point, 1
' Send a reset to the current command
CadInputQueue.SendReset CommandState.StartDefaultCommandEnd Sub
Hi John,
some comments and advises:
[<product> <version> <language>] Topic
[MStn CE U14.2] How to add cell to model?
John Burland said:have a bit of VBA AutoCAD experience
I do not have experience with AutoCAD VBA, but because some concepts are quite different in MicroStation and AutoCAD, VBA API is different also.
John Burland said:This has been cobbled together from a recorded macro and a bit of playing around.
Even when VBA macro recorder is helpful often, for programming it's not recommended tool. A problem is that the created code is not good VBA code, but in fact a script of user's action, transformed to code that can be used as VBA.
To simulate user's action is not a good way and should be used only when it's really necessary, because e.g. such functionality is missing in VBA API. But usually, to simulate users lead to worse and unstable code.
VBA API offers rich functionality that allows to access MicroStation functionality directly.
John Burland said:I have attached a cell library via "AttachCellLibrary".
In MicroStation it's not required to attach cell library before a cell is placed. It's recommended to use MS_CELLLIST variable instead of attaching a library.
But when you preferred to attach the library, use AttachCellLibrary method from VBA API.
John Burland said:Im trying to insert a cell into a DGN via VBA
It's not clear whether you want to place the cell dynamically (similarly to Place cell tool) or simply to place it at some coordinates without an interaction with user. Anyway, the core method here is CreateCellElement1 method.
John Burland said:Im new to coding in Microstation
I recommend to start with:
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Thanks Jan,
I will have a read of the linked documents and go from there. The code is working at the moment, to dynamically place a cell in multiple drawings at various set locations i.e. different for A2 and A3 drawings. Some drawings have been scaled, or not set at 0,0,0 (working with Client drawings of varying quality)
I now need to read the existing drawing border scale and insertion point, to adjust the cell insertion point and location based on the existing title block.
I will do a bit of reading, this should be relatively straight forward.