Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GetOrderedParameters() and Parameter.AsValueString() - Object reference not set to an instance of an object

1 REPLY 1
SOLVED
Reply
Message 1 of 2
EATREVITPOOPCAD
183 Views, 1 Reply

GetOrderedParameters() and Parameter.AsValueString() - Object reference not set to an instance of an object

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")

 

The definition of insanity is doing the same thing over and over again and expecting different results
1 REPLY 1
Message 2 of 2

                        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....

The definition of insanity is doing the same thing over and over again and expecting different results

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community