Create new family from existing

Create new family from existing

Anonymous
Not applicable
8,610 Views
8 Replies
Message 1 of 9

Create new family from existing

Anonymous
Not applicable

Hello. I want to implement such feature:

 

  1. User places some component family instance on the drawing
  2. Then user selects it.
  3. Program should extract the family object of the selected instance
  4. Program should create the copy of the extracted family, modify some parameter of the family (create new family on the base of existing), and place instance of newly created family on the drawing

I do not know how to create in-memory clone of the source family object and save it in current project (or separate .rfa file). How can I implement this?

8,611 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

Use the Duplicate method.

 

Discussed in 2008:

 

http://thebuildingcoder.typepad.com/blog/2008/11/creating-a-new-family-symbol.html

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 9

Anonymous
Not applicable

Hello, Jeremy. I am your fan). I think, that using Duplicate method will not solve my problem. I do not need to create new symbol. I want to create new family, based on source family. For example

 

 

    [Transaction(TransactionMode.Manual)]
    class CmdCreateFamily : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;
            Document doc = uidoc.Document;

            Family sourceFamily = null;

            using (var trans = new Transaction(doc))
            {
                trans.Start("Select family");

                // Prompt user to select some family instance. SelectSingleElementOfType is my own method.
                var sourceFamilyInstance = uidoc.SelectSingleElementOfType<FamilyInstance>("Select FamilyInstance");
                
                // Get Family object from family instance
                sourceFamily = sourceFamilyInstance?.Symbol.Family;

                if (sourceFamily == null)
                    return Result.Failed;

                /*
                 * here I need to call something like:
                 * 
                 * var destFamily = sourceFamily.Clone();
                 * destFamily.Name = destFamily.Name + " dest";
                 * destFamily.SomeParam = "New value";
                 * destFamily.SaveToCurrentDrawing()
                 */

                trans.Commit();
            }

            return Result.Succeeded;
        }
    }
Message 4 of 9

jeremytammik
Autodesk
Autodesk

Wow, cool, thank you for that.

 

In that case you can use the EditFamily method to obtain the family definition document from the project in which an instance has been placed.

 

On the family document object, you can call SaveAs.



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 9

Anonymous
Not applicable

And if I do not want to save new rfa file? If I want to do all this stuff in memory?

0 Likes
Message 6 of 9

jeremytammik
Autodesk
Autodesk

Go ahead and try it out.



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 7 of 9

Anonymous
Not applicable

I am trying to do this for two days. And I do not know, how to implement this, that is why I am asking for help. As far as I understand:

 

  1. When I call var familyDoc = doc.EditFamily(sourceFamily), Revit creates an independent copy of family for editing. But family document is the same as source family document
  2. If I modify something in edited document, independent copy of the family is modified, and modfications are saved in family document.
  3. And I do not understand, how can I load modified family in project as new family, without calling SaveAs on family doc (without creating new family doc on disk.

In general new in-memory family doc could be created, as you shown here . But I do not see the way to create new family document based on another family document.

 

The only solution I see, is to create new family document , and paste there all family symbols from source family, using Duplicate() method. And then modify copied family and load updated family in the project from new in-memory doc. But new family document could be created only using some family template. And again, I do not know, how to choose correct family template for new family doc, that corresponds to the family template of the source family. 

0 Likes
Message 8 of 9

jeremytammik
Autodesk
Autodesk

To modify the duplicate family without affecting the existing one, it needs to have a new, different name.

 

The family name seems to be inextricably linked with the RFA filename.

 

Therefore, I suggest you use SaveAs to a file, rename the file to the new different name, a reload that.

 

That should work right there.

 

I cannot suggest any other approach off-hand.

 

I hope this helps.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 9

Anonymous
Not applicable

Thank you. Calling SaveAs works , of course. And I will try to find out another solution

0 Likes