Insert Family Instance

Insert Family Instance

Anonymous
Not applicable
2,186 Views
3 Replies
Message 1 of 4

Insert Family Instance

Anonymous
Not applicable

Hi All,

 

I know that this topic has been discussed before, but I still can't get what I want. I have a family which I get using:

 

FilteredElementCollector famColl
                            = new FilteredElementCollector(doc)
                            .OfClass(typeof(Family)); 
Family fam = null;

foreach (Element e in famColl)
{
if (e.Name == "FAMILY NAME")
{
fam = e as Family;
}
}

From this step, I just need to get the Family Symbol. I used this (got this from this forum), but with no success:

 

FamilySymbol famSym = null;

                        foreach (ElementId fsIds in fam.GetFamilySymbolIds())
                        {
                            ElementType elemType = doc.GetElement(fsIds) as ElementType;

                            if (elemType.Name == "NAME")
                            {
                                famSym = doc.GetElement(fsIds) as FamilySymbol;
                            }
                        }

Finally, I want to use the Create.NewFamilyInstance method as follows:

 

FamilyInstance famInst = null;
using (Transaction t = new Transaction(doc, "Insert Family Instance")) { t.Start(); famInst = doc.Create.NewFamilyInstance(posEtiqueta, famSym, view); t.Commit(); }

Any tip of advice will be well received!

 

Thanks in advance!

0 Likes
2,187 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Hi All,

 

I managed to create a procedure based on @jeremy_tammik's site: http://thebuildingcoder.typepad.com/blog/2015/02/sending-escape-to-terminate-a-family-instance-place...

 

The only thing I'm missing here is the capability to manipulate the family instance parameters after placing them in the view. I can't figure out how to access the just-created element.

 

Any tip of advice will be very appreciated.

 

Thanks in advance!

0 Likes
Message 3 of 4

JimJia
Alumni
Alumni

Dear Jorge Villarroel,

 

Can you clarify your question?  in your latest comment, you mean "...can't figure out how to access the just-created element... ",  do you think the GetAddedElementIds in OnDocumentChanged event can satisfy your requirement? 

 

 

Besides, can you provide a reproducible case for it?


In order to explore this matter further, we will need to provide a minimal reproducible case for the development team to analyse in depth.
In order to understand exactly what you mean and be able to research possible reasons for the discrepancy between the observed and expected behaviour, they require: 
· A short exact description of what you are trying to achieve.
· The behavior you observe versus what you expect, and why this is a problem.
· A complete yet minimal Revit sample model to run a test in.
· A complete yet minimal macro embedded in the sample model or Visual Studio solution with add-in manifest that can be compiled, loaded, run and debugged with a single click to analyse its behavior live in the sample model.
· Detailed step-by-step instructions for reproducing the issue, e.g. which element to pick, what command to launch etc.
· http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
0 Likes
Message 4 of 4

MarryTookMyCoffe
Collaborator
Collaborator

in this case you need use

  ICollection<ElementId> idsAdded
      = e.GetAddedElementIds();

from OnDocumentChanged event, than past this to Idle Event and change parameter in chosen symbol.
I'm not sure now but I thing OnDocumentChanged is only read event, that is why you have to pass it to Idle event.

 

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
0 Likes