Inserting family

Inserting family

MCalza
Contributor Contributor
1,429 Views
4 Replies
Message 1 of 5

Inserting family

MCalza
Contributor
Contributor

with PromptForFamilyInstancePlacement does not show us component placement options. The code we are using is the following:

 

public Element FindElementByName(Document doc, Type targetType,string targetName)
{
FilteredElementCollector filtro = new FilteredElementCollector(doc);
FilteredElementCollector aux = filtro.OfClass(targetType);
return aux.FirstOrDefault<Element>(e => e.Name.Equals(targetName));
}

public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
ref string message,
ElementSet elements)
{
UIApplication app = revit.Application;
Document doc = app.ActiveUIDocument.Document;
UIDocument uidoc = app.ActiveUIDocument;

Family familia = FindElementByName(doc, typeof(Family), nombreFamilia.Replace(".rfa","")) as Family;

FamilySymbol symbol = null;
if (null == familia)
{
Transaction trans = new Transaction(revit.Application.ActiveUIDocument.Document, "Cargar familia");
trans.Start();
doc.LoadFamily(Path.Combine(ButtonIconsFolder, nombreFamilia), out familia);
trans.Commit();
}


foreach (ElementId id in familia.GetFamilySymbolIds())
{
symbol = familia.Document.GetElement(id) as FamilySymbol;
break;
}

uidoc.PromptForFamilyInstancePlacement(symbol);

return Autodesk.Revit.UI.Result.Succeeded;
}

 

 

We have also tried to do it with the CM command using the following function:

 

RevitCommandId idplace = RevitCommandId.LookupPostableCommandId(PostableCommand.PlaceAComponent);
if (idplace != null) { app.PostCommand(idplace); }

 

 

This function does show us the component placement options, but it does not allow us to indicate the family to load, so by default it always uses the last one loaded.

We are looking for an intermediate solution, something that allows us to indicate the family to load and also shows us the component placement options.

 

 

 

0 Likes
Accepted solutions (1)
1,430 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

You have three options:

 

  • PromptForFamilyInstancePlacement, as you have tested
  • PostCommand to launch the built-in Revit command, as you have tested
  • The NewFamilyInstance method with its numerous overloads

 

I would assume that 95% (or 99%?) of all add-in operations use the latter.

 

It gives you some the control you require. 

 

However, note that you have to program all the steps yourself.

 

 

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

MCalza
Contributor
Contributor

Thanks for the help. We are going to use this function: 

 

Public method NewFamilyInstance(Face, Line, FamilySymbol)

 

(familySymbol) its ok, but (Face) and (Line) they can be anyone. How do I pass these parameters?

 

How can I see an example?

 

Thanks.

0 Likes
Message 4 of 5

MCalza
Contributor
Contributor
Thanks for the help. We are going to use this function:



Public method NewFamilyInstance(Face, Line, FamilySymbol)
(familySymbol) its ok, but (Face) and (Line) they can be anyone. How do I pass these parameters?
How can I see an example?
Thanks.
0 Likes
Message 5 of 5

franciscopossetto
Advocate
Advocate
Accepted solution

Hey, 

 

You can find samples in the Revit SDK. It contains a lot of Revit API samples.

 

Also, you can see RevitAPIDocs, this is the method you are using. At the bottom of the page, you will find an example.
https://www.revitapidocs.com/2016/993bb1aa-d039-d50b-7485-5f404add7cfa.htm

 

About how to pass Face and Line parameters? I am not sure if I understood your question correctly, but if you are asking how to get them, it depends on the workflow you have planned for your tools. You could select them from the UI or extract them from elements.

 

If you only want to pick a point in the space to insert the family I would recommend you use this alternative:

https://www.revitapidocs.com/2016/7499013d-e0d1-df16-92d0-ceefe7cf5c2a.htm

Github:
https://github.com/franpossetto