Results 1 to 5 of 5

Thread: Get a family in the drawing

  1. #1
    Member
    Join Date
    2014-01
    Posts
    8
    Login to Give a bone
    0

    Default Get a family in the drawing

    Hi -

    Using code, I'm trying to determine if a family with a particular name is in the Revit file, and if so, define a family variable for that family (ex. "Dim m_f as Family = ..." in Visual Basic).

    Any ideas?

    Thank you!
    Last edited by Dr. Emergence; 2014-02-27 at 08:27 PM.

  2. #2
    Member
    Join Date
    2013-09
    Location
    Boston
    Posts
    9
    Login to Give a bone
    0

    Default Re: Get a family in the drawing

    Here's a macro that looks for a family named "Single-Flush" of the Doors category

    public void getFamily()
    {
    Document doc = this.ActiveUIDocument.Document;
    string familyName = "Single-Flush";
    Family f = new FilteredElementCollector(doc)
    .OfClass(typeof(Family))
    .Cast<Family>()
    .FirstOrDefault(q => q.FamilyCategory.Name == "Doors" && q.Name == familyName);

    if (f == null)
    TaskDialog.Show("info", familyName + " does not exist");
    else
    TaskDialog.Show("info", familyName + " found");
    }

    Hope this helps
    Regards
    Harry
    http://boostyourbim.wordpress.com/

  3. #3
    Member
    Join Date
    2014-01
    Posts
    8
    Login to Give a bone
    0

    Default Re: Get a family in the drawing

    Thanks!! You wouldn't know how to translate the following to VB.net would you? I've tried but can't seem to get it to work:

    .OfClass(typeof(Family))
    .Cast<Family>()
    .FirstOrDefault(q => q.FamilyCategory.Name == "Doors" && q.Name == familyName);

  4. #4
    Member
    Join Date
    2013-09
    Location
    Boston
    Posts
    9
    Login to Give a bone
    0

    Default Re: Get a family in the drawing

    I don't. There are a bunch of free online c# to vb converters you can try.

  5. #5
    I could stop if I wanted to
    Join Date
    2007-07
    Location
    London, UK
    Posts
    361
    Login to Give a bone
    0

    Default Re: Get a family in the drawing

    Quote Originally Posted by Dr. Emergence View Post
    Thanks!! You wouldn't know how to translate the following to VB.net would you? I've tried but can't seem to get it to work:

    .OfClass(typeof(Family))
    .Cast<Family>()

    .FirstOrDefault(q => q.FamilyCategory.Name == "Doors" && q.Name == familyName);
    That is kind of a duplicate.
    Both methods can be replaced by a single OfType<TResult>() method, also with deferred execution.
    Although not risky in this case, Cast can come with a Invalid Cast exception that never happens with the OfType Linq extension.

Similar Threads

  1. Replies: 0
    Last Post: 2012-07-04, 08:07 PM
  2. Bind all Xrefs in a drawing, and perform the task on numerous drawing files
    By JeffThomasIII in forum AutoCAD Customization
    Replies: 3
    Last Post: 2007-06-19, 03:34 PM
  3. Replies: 2
    Last Post: 2007-05-17, 10:50 PM
  4. Replies: 2
    Last Post: 2006-05-10, 06:38 PM
  5. Replies: 2
    Last Post: 2006-05-02, 04:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •