admin管理员组

文章数量:815284

microstation 批量插入单元和文字

这里写自定义目录标题

  • Microstation利用VBA批量插入单元和文字
    • 需要的工具

Microstation利用VBA批量插入单元和文字

在油田总图绘制过程中,总是要批量插入井、间、站。我习惯的做法是,点状要素在一个图层,要素的注记在另一个图层,利用vba工具实现批量插入

需要的工具

详细工具如下:

  1. Microsoft Excel
  2. MICROSTATION VBA
  3. cel文件
    真实代码如下

Sub aa()
Dim levelname As String '定义一个字符串对象
levelname = “油井03” '字符串赋值
Dim easementlevel As Level '定义一个层对象
Set eastmentlevel = ActiveDesignFile.AddNewLevel(levelname) '设置当前层
eastmentlevel.IsActive = 1

Dim ExcelApp As New Excel.Application '定义一个应用对象
ExcelApp.Workbooks.Open “e:\cadtools\dgn.xlsx”, , ReadOnly 'excel对象地址
Dim startPoint As Point3d
Dim i As Integer
i = 2
Do
Select Case ExcelApp.ActiveWorkbook.Worksheets(“sheet1”).Range(“b” & i)
Case “圆”:
’ 坐标以主单位计
startPoint.X = ExcelApp.ActiveWorkbook.Worksheets(“sheet1”).Range(“d” & i)
startPoint.Y = ExcelApp.ActiveWorkbook.Worksheets(“sheet1”).Range(“e” & i)
startPoint.Z = 0#

Dim ease As CellElement
Set ease = CreateCellElement2(“188310”, startPoint, Point3dFromXY(1, 1), True, Matrix3dIdentity()) '传入单元名,原点名,放大比例,真实比例,和三维
ease.Level = ActiveDesignFile.Levels(levelname) '设置插入的图层
ease.Color = 3 '设置插入时的颜色
ActiveModelReference.AddElement ease '将单元放置在model上

Case Else:
Exit Do
End Select
i = i + 1
Loop '循环

levelname = levelname & “注记” '字符串重新赋值

Set eastmentlevel = ActiveDesignFile.AddNewLevel(levelname)
eastmentlevel.IsActive = 1

Dim aa As Double
Dim bb As Double
Dim cc As String

i = 2
Do
Select Case ExcelApp.ActiveWorkbook.Worksheets(“sheet1”).Range(“b” & i)
Case “圆”:
aa = ExcelApp.ActiveWorkbook.Worksheets(“sheet1”).Range(“d” & i) + 30
bb = ExcelApp.ActiveWorkbook.Worksheets(“sheet1”).Range(“e” & i) + 30
cc = ExcelApp.ActiveWorkbook.Worksheets(“sheet1”).Range(“c” & i)

Dim oNewElement As Element
Set oNewElement = CreateTextElement1(Nothing, cc, Point3dFromXY(aa, bb), Matrix3dIdentity)
oNewElement.Color = 6
ActiveModelReference.AddElement oNewElement
oNewElement.Rewrite
oNewElement.Redraw
Case Else:
Exit Do
End Select
i = i + 1
Loop
ExcelApp.Workbooks.Close

End Sub

本文标签: microstation 批量插入单元和文字