Results 1 to 3 of 3

Thread: [Revit 2013] Transaction error when editing families using API

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2012-04
    Posts
    1
    Login to Give a bone
    0

    Default [Revit 2013] Transaction error when editing families using API

    Hi,

    I am now testing a script to modify family instances using API, but transaction errors occur.
    Transaction was set to manual, and I think I set proper transaction start and commit.
    The code simply takes a family instances, create new type, and reload the instance.
    Could anyone please look at my code and give me some help?

    in advance, Thank for your help!

    Code:
    using System;using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Autodesk.Revit.DB;
    using Autodesk.Revit.DB.Architecture;
    using Autodesk.Revit.UI;
    using Autodesk.Revit.UI.Selection;
    using Autodesk.Revit.ApplicationServices;
    using Autodesk.Revit.Attributes;
    
    
    [TransactionAttribute(TransactionMode.Manual)]
    [RegenerationAttribute(RegenerationOption.Manual)]
    class familyExtract : IExternalCommand
    {
    
    
        public Result Execute(ExternalCommandData commandData, ref String massage, ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            Document doc = uiApp.ActiveUIDocument.Document;
    
    
            Selection sel = uiApp.ActiveUIDocument.Selection;
            Reference selected = null;
    
    
            FamSelectionFilter famFilter = new FamSelectionFilter();
            selected = sel.PickObject(ObjectType.Element, famFilter, "select family");
    
    
            Element elem = doc.GetElement(selected);
            FamilyInstance familyInstance = elem as FamilyInstance;
    
            Transaction trans = new Transaction(doc, "excomm");
            trans.Start();
            editFamilyProperties(doc, familyInstance);
            trans.Commit();
    
    
            return Result.Succeeded;
        }
    
    
        public void editFamilyProperties(Document document, FamilyInstance familyInstance)
        {
            if (null != familyInstance.Symbol)
            {
                Family family = familyInstance.Symbol.Family;
                Document familyDoc = document.EditFamily(family);
                if (null != familyDoc)
                {
                    FamilyManager familyManager = familyDoc.FamilyManager;
                    FamilyType newFamType = familyManager.NewType("Test");
    
    
                    FamilyParameter familyParam = familyManager.get_Parameter("width");
    
    
                    if (null != familyParam)
                    {
                        familyManager.Set(familyParam, 200);
                    }
                    family = familyDoc.LoadFamily(document);
    
    
                    FamilySymbolSetIterator symbolsItor = family.Symbols.ForwardIterator();
                    symbolsItor.Reset();
                    while (symbolsItor.MoveNext())
                    {
                        FamilySymbol familySymbol = symbolsItor.Current as FamilySymbol;
                        if (familySymbol.Name == "mass_Ctype")
                        {
                            familyInstance.Symbol = familySymbol;
                            break;
                        }
                    }
                    
                }
            }
    
    
        }
    
    
        public class FamSelectionFilter : ISelectionFilter
        {
            public bool AllowElement(Element element)
            {
                if (element is FamilyInstance)
                {
                    return true;
                }
                return false;
            }
    
    
            public bool AllowReference(Reference refer, XYZ point)
            {
                return false;
            }
        }
    
    
    }

  2. #2
    100 Club
    Join Date
    2004-09
    Posts
    104
    Login to Give a bone
    0

    Default Re: [Revit 2013] Transaction error when editing families using API

    You actually have two documents open, "doc" and "familyDoc." So far, you are not making changes to "doc" but you are attempting to make changes to "familyDoc."

    Therefore, you need to add a transaction in familyDoc, inside editFamilyProperties(), whenever you make a change to the family: add type, change width- not sure about mass_type.

  3. #3
    100 Club
    Join Date
    2004-02
    Location
    Brookline, MA
    Posts
    186
    Login to Give a bone
    0

    Default Re: [Revit 2013] Transaction error when editing families using API

    I agree with Peter that you need a transaction within FamilyDoc to make that change.

    But there's also a new wrinkle in 2013 that will make the code need to be even more complicated:

    I believe now, you cannot perform an "EditFamily" while you've got a transaction open on the project document - is that where it's failing now? on the EditFamily()?

    I'm honestly not sure how you'll need to structure your code for this, but focus on separating the two actions:
    EditFamily()
    The Family Transaction
    The Family Change
    Commit the Family Transaction
    Start a Project Transaction
    Do the Load Family
    Commit the Project Transaction

    (that's what seems like it would work).

    Good Luck,
    Matt

Similar Threads

  1. Families seem to be missing or not loading Revit 2013
    By bwilliams133 in forum Revit Architecture - General
    Replies: 5
    Last Post: 2014-02-12, 03:26 PM
  2. Replies: 0
    Last Post: 2012-04-25, 08:12 AM
  3. Transaction failure inside a transaction?
    By abe.buckingham in forum Revit - API
    Replies: 4
    Last Post: 2010-07-02, 10:09 AM
  4. general question about editing families and revit
    By ntnik in forum Revit Architecture - Families
    Replies: 7
    Last Post: 2007-08-27, 04:18 PM
  5. Replies: 0
    Last Post: 2006-10-12, 03:44 PM

Tags for this Thread

Posting Permissions

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