Mass Place New Family Instances Relative to other Instances

Mass Place New Family Instances Relative to other Instances

tom-bBSYBT
Contributor Contributor
1,058 Views
3 Replies
Message 1 of 4

Mass Place New Family Instances Relative to other Instances

tom-bBSYBT
Contributor
Contributor

Hi, I have the following workflow and not sure which overload is the best one for the below code:

1. The user should pick an instance from his local model which is already hosted on a face of a linked element.

2. The user should pick a linked element (could be any family wall, furniture, duct etc...)

3. The function should auto-insert the element (1) on all the faces of the same instance (2) at the same relative point.

 

For example: the user has a lamp placed on a desk at the far left corner, there are multiple instances of this desk in the view, I want the function to auto-insert the lamp on all the desks at the far left corner.

 

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
    var doc = commandData.Application.ActiveUIDocument.Document;
    
    var PromptPickObject = new PromptPickObject(doc);
    var localElement = PromptPickObject.GetLocalElement().Element;
    var linkedElement = PromptPickObject.GetLinkedElement().Element;

    var elFamInst = localElement as FamilyInstance;

    using (Transaction trans = new Transaction(doc, "Mass Place Instances"))
    {
        trans.Start();

        //doc.Create.NewFamilyInstance(???, ???? , ???);

        trans.Commit();
    }

    return Result.Succeeded;
}

 

Could you please help me by pointing me in the right direction, what is the best way in this case?

0 Likes
Accepted solutions (1)
1,059 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni

Cool project. The first thing to do is to break it up into separate pieces that have little or almost nothing to do with each other. How to identify those pieces is a bit of a question of personal taste, and art, and OOP practice, object-oriented programming. For instance, yu could start by implementing separate external command to:

  

  • Pick a family instance in a view, then retrieve and list all of the similar instances
  • Pick an existing inserted face-hosted instance, and then another point on a face to duplicate it to

  

Once you have a couple of pieces like that in place, putting them together will be a piece of cake.

  

Good luck and have fun.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 4

tom-bBSYBT
Contributor
Contributor

Hi @jeremy_tammik , I already have a handler to prompt the user to pick the objects, I abstracted it at the begging of the code I posted.

 

Now when I have these objects and their properties, I am asking which overload for the method:

doc.Create.NewFamilyInstance

 Is the most suitable in the case I described?

0 Likes
Message 4 of 4

jeremy_tammik
Alumni
Alumni
Accepted solution

Good for you. I'm not sure which overload is best. For a lamp on a desk, I assume that you need at least the symbol, the insertion point and the face input arguments. You may need to try out which overload works best for you. Here are some previous explorations of similar topics:

 

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes