« Open Revit OLE Storage | Main | TextNote Rotation »

June 15, 2010

Comments

Hi Jeremy,

I am trying to set viewsheet parameters from a text file, and have a mysterious exception upon commit. I have an error handler that does not capture an error, so am at a loss and have begun breaking things apart.

I read the values from a text file, so my outer loop is a streamreader.ReadLine() call

Then I loop through my viewSheets collector to find the right sheet. It strikes me that I may be better off using LINQ to find the particular sheet, but cannot find a suitable example. I am assuming that Revit won't allow a sheet to have a Sheet Number that is not unique (untested assumption for now).

So here is what I'm doing, but the compiler doesn't like it. Can you help?

string[] linearray;
ViewSheet vQuery;
FilteredElementCollector Sheets = new
FilteredElementCollector(doc).OfClass(typeof(ViewSheet));

var query = from element in Sheets
where
element.get_Parameter(KeyParameter.Text).AsString() == linearray[0]
select element; //linearray is a split (\t) on the ReadLine
if (query.Count.AsValue() > 0) //doesn't like this
vQuery = (ViewSheet) query.ElementAt(0); // I know this is wrong . . . how do I get the actual sheet?


Thanks for your help!

Dear Paul,

First you talk about an exception. That is a runtime error.

Then you say the compiler is complaining. That is a compile time error, and not an exception.

Anyway, I would suggest that you search for some examples of using the .NET generic templated collection extension method FirstOrDefault in conjunction with a FilteredElementCollector.

http://lmgtfy.com/?q=FirstOrDefault+FilteredElementCollector

I use that myself on a regular basis, and I think that does exactly what you need.

LINQ will not be any better than anything else.

The only thing that makes a difference performance-wise is whether you use the Revit filtered element collector functionality, which is very fast, or something based on .NET that post processes the results of the former. That is significantly slower.

Cheers, Jeremy.

Hi Jeremy,
I am looking to read xml data into a revit addin. Are there any Revit specific tutorials I could possibly read up on?

Cheers,
Frank

Dear Frank,

There are about umpteen zillion .NET XML libraries you can use, plus this functionality is provided by the standard .NET framework:

http://lmgtfy.com/?q=.NET+XML+library

Cheers, Jeremy.

thanx jeremy, thats C# power I love it

:-)

Hi Jeremy,
Why do we need to set the transaction property to read-only? How can I edit the family doc to acquire it's path then famdoc.close() it in readonly mode as this causes an exception.
cheers
fabs

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Your Information

(Name and email address are required. Email address will not be displayed with the comment.)

Jeremy Tammik

AboutTopicsIndexSource