XTAtool: Xuất bảng thống kê sang Excel trong Revit2014

Addin hỗ trợ xuất bảng thống kê trong Revit 2014 sang Excel
Linhk dowload addin: http://upfile.vn/5sga
Video hướng dẫn sử dụng:


Mã nguồn chương trình bằng vb.net:
'------------------------------------------------------------------------------
Imports Autodesk.Revit.ApplicationServices
Imports Autodesk.Revit.Attributes
Imports Autodesk.Revit.DB
Imports Autodesk.Revit.UI
Imports Autodesk.Revit.UI.Selection
Imports mExcel = Microsoft.Office.Interop.Excel
'------------------------Hàm lấy kích thước của bảng thống kê ----------------------------
Public Function KichthuocBTK(ByVal view As ViewSchedule, ByVal sectype As SectionType, cot As Boolean) As Integer
        Dim i As Integer = 1
        While True
            Try
                If cot Then
                    view.GetCellText(sectype, i, 1)
                Else
                    view.GetCellText(sectype, 1, i)
                End If
                i = i + 1
            Catch ex As Autodesk.Revit.Exceptions.ArgumentException
                Return i
            End Try
        End While
        Return i
    End Function
'------------------------Thủ tục xuất bảng thống kê sang excel ----------------------------<Transaction(TransactionMode.Automatic)> _
Public Class XuatBangTK
    Implements IExternalCommand
    Public Function Execute(ByVal commandData As ExternalCommandData, _
                            ByRef message As String, _
                            ByVal elements As ElementSet) As Result Implements IExternalCommand.Execute
        Try
            If Nothing Is commandData Then
                Throw New ArgumentNullException("commandData")
            End If
            Dim uiApp As UIApplication = commandData.Application
            Dim uiDoc As UIDocument = uiApp.ActiveUIDocument
            Dim app As Autodesk.Revit.ApplicationServices.Application = uiApp.Application
            Dim doc As Document = uiDoc.Document
            Dim view As View = doc.ActiveView
            If view.ViewType <> ViewType.Schedule Then
                message += "Chỉ xuất được bảng thống kê trong view Schedule!"
                Return Result.Failed
            End If
            Dim vSchedule As ViewSchedule = TryCast(view, ViewSchedule)
            Dim excel As mExcel.Application = New mExcel.Application
            Dim books As mExcel.Workbook = excel.Workbooks.Add
            Dim sheet As mExcel.Worksheet = books.ActiveSheet
            excel.Visible = False
            sheet.Cells(1, 1) = vSchedule.Name
            Dim cel As mExcel.Range = sheet.Range(sheet.Cells(1, 1), sheet.Cells(1, KichthuocBTK(vSchedule, SectionType.Body, False)))
            cel.Merge()
            cel.VerticalAlignment = 3
            cel.HorizontalAlignment = 3
            cel.Font.Bold = True          
            For i As Integer = 0 To KichthuocBTK(vSchedule, SectionType.Body, True) - 1
                For j As Integer = 0 To KichthuocBTK(vSchedule, SectionType.Body, False) - 1
                    sheet.Cells(i + 2, j + 1) = vSchedule.GetCellText(SectionType.Body, i, j)
                Next
            Next
            cel = sheet.Range(sheet.Cells(2, 1), sheet.Cells(2, KichthuocBTK(vSchedule, SectionType.Body, False)))
            cel.Font.Bold = True
            cel.VerticalAlignment = 3
            cel.HorizontalAlignment = 3
            cel = sheet.Range(sheet.Cells(1, 1), sheet.Cells(KichthuocBTK(vSchedule, SectionType.Body, True) + 1, KichthuocBTK(vSchedule, SectionType.Body, False)))
            cel.Borders.LineStyle = 1
            cel.EntireColumn.AutoFit()
            excel.Visible = True
            cel = Nothing
            sheet = Nothing
            books = Nothing
            excel = Nothing
            Return Result.Succeeded
        Catch ex As Exception
           Return Result.Failed
        End Try
    End Function
End Class

4 nhận xét:

chiuxahoi nói...

Xuất dữ liệu trên Robot có tương tự không anh ? Em thấy trên Robot nó cho mình những bảng riêng rẽ . Mong anh giải đáp ạ

Unknown nói...

Mình chưa tìm hiểu về Robot nên mình cũng không rõ lắm. Mình biết Robot cũng cho phép người dùng tạo các addin giống như bên Revit. Vì vậy việc xuất dữ liệu như trên là hoàn toàn tương tự. Bạn chỉ cần nắm được các thuộc tính và truy cập được vào các giá trị của đối tượng bảng thống kê là giải quyết được. Việc link và xuất các giá trị vào đối tượng Excel là hoàn toàn giống như trên!

chiuxahoi nói...

Như trong clip này em thấy khi code người ra lấy 2 file RevitAPI và RevitAPIUI, với Robot thì mình lấy file nào ạ. e tìm trong robot có mỗi một file rcuapi.dll nhưng em viết tương tự thì không được. Mong anh giúp đỡ ạ
https://www.youtube.com/watch?v=PqgyeQDzGak

Unknown nói...

Dạ anh có thể cho em xin lại link file dc ko ạ?
Link trên die rồi ạ, ko load dc anh ơi!

Đăng nhận xét

 
Powered by by: Blogger