If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: shared parameters

Public Sub GetSheetParams()
Dim doc As Document = Command.RevitStartInfo.RevitDoc
Dim sheetInfo As String = ""
For Each e As Element In New FilteredElementCollector(doc).OfClass(GetType(ViewSheet))
' get the parameter
Dim parameter As Parameter = e.Parameter("myProjectNo")
' get the string value of the parameter
Dim cadFileData = parameter.AsString
sheetInfo += cadFileData + vbLf
Next
TaskDialog.Show("myProjectNo", sheetInfo)
End Sub
End Class

but now get error : Object Reference not set to an instance of an object on line -

Code:

Dim cadFileData = parameter.AsString

Any help is much appreciated.

The parameter variable is null, meaning that the parameter was not found on that element. I see that the parameter name in the shared parameter file you posted is actually "ProjectNo" and not "myProjectNo". Make sure you've spelled the parameter name correctly - the name is also case sensitive so keep that in mind as well.

If you want to explore an element's parameters, you should use RevitLookup which is part of the SDK. I don't think it comes pre-built so you'll need to compile it in Visual Studio and add the add-in to Revit yourself. It comes with instructions on how to do this.

Re: shared parameters

Originally Posted by cshha

The parameter variable is null, meaning that the parameter was not found on that element. I see that the parameter name in the shared parameter file you posted is actually "ProjectNo" and not "myProjectNo". Make sure you've spelled the parameter name correctly - the name is also case sensitive so keep that in mind as well.

If you want to explore an element's parameters, you should use RevitLookup which is part of the SDK. I don't think it comes pre-built so you'll need to compile it in Visual Studio and add the add-in to Revit yourself. It comes with instructions on how to do this.

Re: shared parameters

The parameter probably hasn't been added to the element yet then. When dealing with shared parameters, the parameter needs to be bound to the element before it can be set.

Check out this post from Jeremy Tammik's blog. There's a link near the bottom to download a set of helper functions to deal with shared parameters. The function you'll be interested in is GetOrCreateElemSharedParam