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.
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.
Solved by ctm_mka. Go to Solution.
Technically no, you do not need a separate list, you should be able to accomplish what you want within the foreach loop on line 33 of your sample.
Technically no, you do not need a separate list, you should be able to accomplish what you want within the foreach loop on line 33 of your sample.
hi, thank you for the answer, but I admit I don't know what to do with this one (this most certainly comes from my lack of skills in C#, I need to look very deeply into this point)
Sincerely
christian.stan
hi, thank you for the answer, but I admit I don't know what to do with this one (this most certainly comes from my lack of skills in C#, I need to look very deeply into this point)
Sincerely
christian.stan
You don't necessarily need to do anything. is anything not working? are you getting any errors? or just looking to be more efficient with your coding?
You don't necessarily need to do anything. is anything not working? are you getting any errors? or just looking to be more efficient with your coding?
Hi, indeed I'm looking to improve, but I don't want to waste your time, I have to work on C# (public private void everything still seems a little too nebulous to me)
I give you a solution
thank you for taking the time to answer me
sincerely
christian.stan
Hi, indeed I'm looking to improve, but I don't want to waste your time, I have to work on C# (public private void everything still seems a little too nebulous to me)
I give you a solution
thank you for taking the time to answer me
sincerely
christian.stan
Can't find what you're looking for? Ask the community or share your knowledge.