Search code examples
excelvb.netrevit-apirevit

Create Revit Sheets from Excel with multiple project parameters


Hi I have a macro that creates multiple sheets and has Name, Number, Sheet Category. The last being my own project parameter.

I can successfully create the sheets with name and number but I am having difficulty adding the value from CSV file to the project parameter "SD_Sheet Category". Below are some code grabs to help explain.

Public Module mSheetCreator
Public Structure structSheet
    Public sheetNum As String
    Public sheetName As String
    Public sortCategory As String
End Structure

Then I have a function that reads the CSV file and does the following:

            Try
                currentRow = MyReader.ReadFields()

                'create temp sheet
                Dim curSheet As New structSheet
                curSheet.sheetNum = currentRow(0)
                cursheet.sheetName = currentRow(1)
                curSheet.sortCategory = currentRow(4)

                'add sheet to list
                sheetList.Add(curSheet)

Then I have a transaction that does the following:

For Each curSheet As structSheet In sheetList
        Try
        If sheetType = "Placeholder Sheet" Then
m_vs = ViewSheet.CreatePlaceholder(curDoc)
        Else 
m_vs = ViewSheet.Create(curDoc, tblock.Id)
m_vs.Parameter("SD_Sheet Category").Set(CStr(curSheet.sortCategory))
        End If
m_vs.Name = curSheet.sheetName
m_vs.SheetNumber = curSheet.sheetNum

The problem is this code:

m_vs.Parameter("SD_Sheet Category").Set(CStr(curSheet.sortCategory))

I am getting a warning that says it's an "implicit conversion from 'String' to 'Autodesk.Revit.DB.BuiltInParameter'" once I build solution

When I run the code in Revit it produces an error saying

"Conversion from string 'SD_Sheet Category" to type 'Integer' is not valid"

It creates the sheets but disregards all the info in the CSV file. I know the rest of the code works as I have removed this particular line of code so I know it isn't the problem

Any suggestions??


Solution

  • I believe that as of a particular version of Revit API you cannot use .Parameter(“name”)

    Because there might be two parameters with the same name.

    So you need to do something more like

    Dim cat as Parameter
    

    Cat = m_vs.GetParameters(“sd_sheet category”).First() Cat.Set(CSTR(cursht.sortCategory))

    Good luck!