Thursday, March 15, 2012

Vasari SDK Sample 1 - DividedSurfacePanelNumbering

Sample #1 of the new Vasari SDK samples is DividedSurfacePanelNumbering. The SDK sample contains code in  both VB.NET and C#.

This is a short and sweet sample demonstrating how to read the column and row numbers for panels instantiated within a Divided Surface pattern. This sample needs to be run from within a family (rfa) file for an element who's face(s) have a Divided Surface and are populated with a panel based pattern family. A family file named "DividedSurfacePanelNumbering.rfa" has been provided with the SDK to use for this sample.

The first task at hand is to get the document object and attain the list of Divided Surface elements in the family. This is also a good place to initiate the required transaction.

            ' The Document
            Dim m_doc As Document = commandData.Application.ActiveUIDocument.Document

            ' Get the Divided Surfaces by Category
            Dim m_col As New FilteredElementCollector(m_doc)
            ' Transaction
            Dim m_t As New Transaction(m_doc, "Vasari SDK - Panel Numbering")

After we have the list of divided surface elements, we can iterate them and iterate through each of their U and V sets to get all the way down to the panel instance family. Once we have the family instance, we'll set the parameters to their grid values.
            ' Succesful Panel Renumbering Count
            Dim m_reportInt As Integer = 0


                ' Iterate the DS
                For Each x In m_col.ToElements

                    If TypeOf x Is DividedSurface Then

                        ' Cast to DS
                        Dim m_ds As DividedSurface = TryCast(x, DividedSurface)

                        ' Iterate Columns
                        For u = 1 To m_ds.NumberOfUGridlines - 1

                            ' GridNode Element
                            Dim m_gn As New GridNode

                            ' Set the U Grid
                            m_gn.UIndex = u

                            ' Iterate Rows
                            For v = 1 To m_ds.NumberOfVGridlines - 1

                                ' Set the V Grid
                                m_gn.VIndex = v

                                ' Get the Family Instance
                                Dim m_fi As FamilyInstance = m_ds.GetTileFamilyInstance(m_gn, 0)

                                If m_fi Is Nothing Then Continue For

                                ' Set the Panels's Row and Column Parameters Respectively
                                m_fi.Parameter("Panel Column").Set(u.ToString)
                                m_fi.Parameter("Panel Row").Set(v.ToString)

                                ' Step the Succes Counter
                                m_reportInt += 1



                    End If

                ' Commit the Transaction

                ' Inform the User
                Dim m_td As New TaskDialog("Panel Renumbering Stats")
                m_td.MainInstruction = m_reportInt.ToString & " Panels were succesfully renumbered!" & vbCr & "Check each panel's parameters 'Panel Column' and 'Panel Row'"
                m_td.MainContent = "These are shared parameters and can be scheduled from the 'Curtain Panel' category when loaded into a project."

            Catch uvnumbering As Exception

                ' Rollback the transaction

            End Try

            ' Success
            Return Result.Succeeded

The result will populate each panel instance within the Divided Surface pattern grid to their respective column and row values.

No comments:

Post a Comment