I am trying to find all sheet's parameters that have a string value of 'X' and store their names and values (In this case always 'X')
These sheet parameters have varying names per project, such as "50% CD Set" or "Owner Progress Set" and will have a value 'X' or be empty. Our office standards don't have any other parameters with a value 'X' so this isn't an issue.
The problem I have is I am getting an exception on some parameters .AsValueString() that I haven't been able to skip using try{}catch{}
Any ideas on which parameter could be doing this and how to skip them?
Here is the exception:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Autodesk.Revit.DB.Parameter.AsValueString(...) returned null.
int issuePackageParamName = 0;
int issuePackageParamValue = 1;
Dictionary<string, string[,]> exSheetsIssuePackages = new Dictionary<string, string[,]>();
foreach (ViewSheet v in exCivilSheets)
{
exCivilSheetsIDs.Add(v.Id);
// GET ISSUE PACKAGES
IList<Parameter> ps = v.GetOrderedParameters();
string[,] issuePackages = new string[2, 6];
int packageIndex = 0;
foreach (Parameter p in ps)
{
try
{
if (p.AsValueString().ToLower() == "x")
{
issuePackages[issuePackageParamName, packageIndex] = p.Definition.Name;
issuePackages[issuePackageParamValue, packageIndex] = p.AsValueString();
}
}
catch { }
++packageIndex;
}
exSheetsIssuePackages.Add(v.Name,issuePackages);
}
And this is the problematic line of code
if (p.AsValueString().ToLower() == "x")
Solved! Go to Solution.
Solved by EATREVITPOOPCAD. Go to Solution.
if(p.HasValue)
if (p.AsValueString().ToLower() == "x")
A strange phenomenon happens sometimes after I give up and post here, a light bulb goes off....
Can't find what you're looking for? Ask the community or share your knowledge.