Hello, as you can see from my way of writing code, I'm really not very good in C#
Do I have to create a List<Face> to retrieve the FaceArray
public void placerUneBanche()
{
Document doc=this.Document;
UIDocument uidoc=Application.ActiveUIDocument;
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector = collector.OfClass(typeof(FamilySymbol));
// Get Element Id for family symbol which will be used to find family instances
var query = from e in collector where e.Name == "Pn 240 x 280" select e;
List<Element> famSyms = query.ToList<Element>();
ElementId symbolId = famSyms[0].Id;
FamilySymbol fs=doc.GetElement(symbolId) as FamilySymbol;
Reference choixselection = uidoc.Selection.PickObject(ObjectType.Element);
Element el=doc.GetElement(choixselection);
Wall wal=el as Wall;
Options options=new Options();
options.ComputeReferences = true;
GeometryElement geoelt=wal.get_Geometry(options);
//Creating an array of faces
FaceArray face;
//Creating a list to retrieve faces from an array
List<Face> lf= new List<Face>();
//Get the geometry of the element
foreach (GeometryObject gobj in geoelt)
{
Solid sol= gobj as Solid;
if (sol!=null)
{
face=sol.Faces;
foreach (Face f in face)
{
lf.Add(f);
}
}
}
//Creation of a query to filter by component of the normal vector
var query2= from f in lf where f.ComputeNormal(UV.Zero).Normalize().Z==-1 select f;
List<Face> lff = query2.ToList<Face>();
//Sort the list by point Z
lff = lff.OrderBy(f => f.Evaluate(UV.Zero).Z).ToList();
//Found the face
Face facesupport=lff[0];
//Found point on middle of the wall
Element elmur=doc.GetElement(choixselection);
LocationCurve lcurve=elmur.Location as LocationCurve;
XYZ ptsupport=lcurve.Curve.Evaluate(0.5,true);
//Found the normal of the wall direction
Transform t=lcurve.Curve.ComputeDerivatives(0.5,true);
XYZ vecn=t.BasisX.Normalize();
//Create a Transaction for the new object
Transaction trans = new Transaction(doc, "placez une Instance");
// Start the transaction
trans.Start();
FamilyInstance nvfam=doc.Create.NewFamilyInstance(facesupport,ptsupport,vecn,fs);
trans.Commit();
}
Do you have book references to progress in C# (preferably in French)
I thank you in advance.
Sincerely
christian.stan
Solved! Go to Solution.
Link copied