学习4、Revit二次开发1:创建标高
1、我们从AutoCAD读取层高表标高至剪切板,标高从底到顶,用分号“;”分隔。用以下代码可以再从剪切板中读取,并在Revit中添加标高。
比如我粘贴到记事本中的数据
运行命令之后效果
Imports Autodesk.Revit.DB
Imports Autodesk.Revit.UI
Imports Autodesk.Revit.UI.Selection
Imports Autodesk.Revit.Attributes
Imports System.Windows.Forms
Imports Autodesk.Revit.ApplicationServices
Namespace MyFirstRevitDll5
<Transaction(TransactionMode.Manual)>
Public Class Class1
Implements IExternalCommand
Private Function Execute(ByVal commandData As ExternalCommandData,
ByRef message As String,
ByVal elements As ElementSet) _
As Result Implements IExternalCommand.Execute
Dim uidoc As UIDocument = commandData.Application.ActiveUIDocument
Dim doc As Document = uidoc.Document
Dim selection As Selection = uidoc.Selection
Using ts As New Transaction(doc)
ts.Start('创建标高')
Dim bgstr As String = Clipboard.GetText
Dim bgs() As String = bgstr.Split(';')
For Each bg As String In bgs
Level.Create(doc, UnitUtils.Convert(bg, DisplayUnitType.DUT_METERS, DisplayUnitType.DUT_DECIMAL_FEET))
Next
ts.Commit()
End Using
Return Result.Succeeded
End Function
End Class
End Namespace
2、Revit中使用Level.Create创建标高。
3、创建标高时候,需要单位转换。我们的标高时米(m)单位需要转换为Revit内部单位英寸。单位转换用UnitUtils。
单位转换举例:
Dim Dis As Double
'英尺到米
Dim d1 As Double = UnitUtils.Convert(Dis, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_METERS)
'英尺到毫米
Dim d2 As Double = UnitUtils.Convert(Dis, DisplayUnitType.DUT_DECIMAL_FEET, DisplayUnitType.DUT_MILLIMETERS)
'米到英寸
Dim d3 As Double = UnitUtils.Convert(Dis, DisplayUnitType.DUT_METERS, DisplayUnitType.DUT_DECIMAL_FEET)
'毫米到英寸
Dim d4 As Double = UnitUtils.Convert(Dis, DisplayUnitType.DUT_MILLIMETERS, DisplayUnitType.DUT_DECIMAL_FEET)
赞 (0)