Wednesday, March 28, 2012

Vasari SDK Sample 8 - PlaceFamilesByXyzFromFile

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

This sample places a family instance at the location specified in an external file. The file is a tab delimited text file with containing a row for each family instance to be placed in the model. A chess board setup is the topic of this one.



Monday, March 26, 2012

Vasari SDK Sample 7 - ExportElementXYZtoTextFile

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

This is a simple sample that can export XYZ coordinates for a selected category. Another sweet feature within this sample is the ability to also filter by Design Option. Filtering by Design Option can be tricky of you've never had to do it before. This sample can be run on any ol file you want.

The codes used to filter b category and design option is quite simple. An option in the API exists for you to filter by ContainedInDesignOption as shown below in a short snippet.

        ' Filter by the Category Selected - by Category Name
        Dim m_col As New FilteredElementCollector(_doc)

        ' Get the selected item as an object
        Dim m_desOpt As clsDesignOption = Me.ComboBoxDesignOption.SelectedItem

        ' Do we have a Design Option Filter?
        If Not m_desOpt.DesignOption Is Nothing Then

            ' Apply the Option Set ID to the Filter

        End If

The element processing to get the element XYZ is fairly simple as well. This is a very basic implementation that doesn't take into account any corrections for offsets or hosting.

        ' Process the Elements
        For Each x As Element In m_col.ToElements


                ' Get the XYZ Location
                Dim m_location As Location = x.Location

                ' Continue if we have a location
                If Not m_location Is Nothing Then

                    ' Get the XYZ object
                    Dim m_xyz As XYZ = DirectCast(m_location, LocationPoint).Point

                    ' Design Option Data
                    Dim m_dopt As String = ""
                    Dim m_set As String = ""
                    If Not x.DesignOption Is Nothing Then
                        m_dopt = x.DesignOption.Name
                        ' Cast the Object to a Design Option Object
                        Dim mm_DesignOption = TryCast(x.DesignOption, DesignOption)
                        ' Get the Set Name
                        m_set = _doc.Element(New ElementId(mm_DesignOption.Parameter(BuiltInParameter.OPTION_SET_ID).AsElementId.IntegerValue)).Name
                    End If

                    ' Write out the Element Data
                    Dim m_line As New List(Of String)

                    With m_line
                    End With


                End If

            Catch ex As Exception

            End Try


Friday, March 23, 2012

Vasari SDK Sample 6 - ExtrudeRoomsToMass

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

This is a sample that demonstrates how to read the boundaries of a room element and extrude a form using these coordinates. Each room results in a new family creation that gets loaded into the model with a material generated for the department name. The material color is completely randomized.

A sample model containing a few room contained only by a series of room separation lines named "ExtrudeRoomsToMass.rvt" is provided along with the sample.

If you want to see the code samples for this one, you'll just have to get the Vasari SDK from
matt dot jezyk at autodesk dot com!

Wednesday, March 21, 2012

Vasari SDK Sample 5 - FormulaDrivenCurves

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

This might be my favorite sample out of the Vasari SDK. This sample needs to be run from inside a fresh conceptual mass family. It takes a while to run, but it basically reads through a set of formulas describing a somewhat complex shape and lofts a series of surfaces to generate what looks a lot like a piece of pasta!

The formula steps through a series of i (cnTi) and j (cnTj) ranges to generate the reference points that are then used to generate a series of curves. The curves then get lofted around the object. The equation is shown here.

                    ' Equation                     
                    m_x = 10 * ((0.7 + 0.2 * Math.Sin((21 * cnTj / 250) * Math.PI)) * Math.Cos((cnTi / 20) * Math.PI))
                    m_y = 10 * ((0.7 + 0.2 * Math.Sin((21 * cnTj / 250) * Math.PI)) * Math.Sin((-cnTi / 20) * Math.PI))
                    m_z = 10 * (39 * cnTi / 1000 + 1.5 * Math.Sin((cnTj / 50) * Math.PI))

The complete Vasari SDK can be shared from our buddy Matt dot Jezyk at Autodesk dot com

Tuesday, March 20, 2012

Vasari SDK Sample 4 - MassColorGrossFloorArea

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

This is a rather interesting sample that implements IUpdater. This sample requires no command execution to update the materialism on a set of masses based on their relative closeness to a target Gross Floor Area (GFA). As the mass dimensions or applied mass floors are adjusting resulting in an updated GFA, the colors aromatically adjust to yellow if their GFA is under the allowable value for "Max Underage Gross Floor Area", red if over the "Max Overage Gross Floor Area", and green if within the allowable tolerance of the "Target Gross Floor Area" parameter. each of these parameters are type parameters within the mass family.

Here is a snapshot of the masses before they have been adjusted to be all within the GFA target.

Here is the masses all green after their dimensions have been adjusted to target their "Target Gross Floor Area" values.

Monday, March 19, 2012

Vasari SDK Sample 3 - Incrementer

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

Have you ever checked out some of the awesome "incremental" formula based families that Zach Kron has built and blogged about on

This sample helps construct a series of copied families all while incrementally filling in a numerical value within a specified integer parameter in the family. So basically you can take a series of families with formulas using this incremental value from this:

To this:

Friday, March 16, 2012

Vasari SDK Sample 2 - DividedSurfacePanelRandomizer

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

This is another short and sweet sample demonstrating how to randomize 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 "DividedSurfacePanelRandomizer.rfa" has been provided with the SDK to use for this sample.

This sample is provided with a modeless user form that prompts you to select a panel element from within a Divided Surface. Once you've selected a panel, the form loads all pattern families within the family that are of the same form pattern shape. These types are what will be randomized across the Divided Surface.

The code that handles the randomization is fairly straightforward. The .NET class "Random" used to generate a random number between 1 and the total qualifying panel families based on your original selection and uses that integer to identify the corresponding panel family symbol to apply in that instance.

        ' New Transaction
        Dim m_t As New Transaction(_doc, "Vasari SDK - Panel Randomization")


            ' Get all Panels of Matching Type
            Dim m_filter As New FilteredElementCollector(_doc)
            Dim m_panels As New List(Of Element)
            m_panels = m_filter.ToElements

            ' Random Object
            Dim m_r As New Random

            ' Prime Progressbar
            With Me.ProgressBar1
                .Minimum = 0
                .Maximum = m_panels.Count
                .Value = 0
            End With

            ' Randomize their types
            For Each x As Element In m_panels

                ' Step the progressbar

                ' Ignore non Panel Elements
                If Not TypeOf x Is Panel Then Continue For


                    ' Only Work with Panes of Qualifying Type
                    If _Panels.ContainsValue(x.GetTypeId) Then

                        ' Randomize Instance

                            ' Random Number between 1 and Quantity of Qualifying Panel Types
                            Dim m_i As Integer = m_r.Next(1, _Panels.Count)

                            ' Change the Type to the Matching Dictionary Entry for the Random Number Key
                            Dim m_eid As ElementId = Nothing
                            _Panels.TryGetValue(m_i, m_eid)

                            ' Was the Type Value Found?
                            If Not m_eid Is Nothing Then

                                ' Change the Type ID

                            End If

                        Catch ex2 As Exception

                        End Try

                    End If

                Catch ex1 As Exception

                End Try


            ' Finalize the Transaction

        Catch ex As Exception

            ' Rollback on failure

        End Try

You can click randomize as many times as you want until you get the desired randomization.

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.

Vasari 2.5 SDK

Some people don't know this, but Vasari 2.5 (just released today) has an SDK and it was put together by your friends at Case. The SDK has not been posted for download just yet, but Matt Jezyk said it was OK to have you guys contact him directly if you want to get an early copy of it.

Matt can be reached at: matt dot jezyk at autodesk dot com

Once you've managed to get a copy of the SDK and look inside, you may notice a lot of similarities between this Vasari SDK and the one that ships with Revit. The main difference between the Revit SDK and this new Vasari SDK is the 8 new Vasari oriented samples found in the "Vasari (NEW)" folder.

All 8 of the new Vasari samples are available in both VB.NET and C# for your programming pleasures.
  • DividedSurfacePanelNumbering
  • DividedSurfacePanelRandomizer
  • ExportElementXYZtoTextFile
  • ExtrudeRoomsToMass
  • FormulaDrivenCurves
  • Incrementer
  • MassColorGrossFloorArea
  • PlaceFamilesByXyzFromFile
Stay tuned for a daily post outlining each one of these samples and how to use them!