Getting error while creating a door in Level 2

Getting error while creating a door in Level 2

abdul.rafee
Contributor Contributor
1,403 Views
25 Replies
Message 1 of 26

Getting error while creating a door in Level 2

abdul.rafee
Contributor
Contributor

Hi,

 

I am trying to place a door on Level 2 but failed to say that cannot cut the instance of the door out of the wall.

below screenshot for you better understand 

 

abdulrafee_0-1680066016812.png

below my code

 

abdulrafee_1-1680066072263.png

 

0 Likes
1,404 Views
25 Replies
Replies (25)
Message 21 of 26

sayu94
Enthusiast
Enthusiast
i don't know, what are you doing. Please give me your code
0 Likes
Message 22 of 26

mhannonQ65N2
Collaborator
Collaborator

Try placing a door in that wall manually and use RevitLookup to look at its Location property.

 

Another thing you could do for testing is to change the top and bottom extents of the wall on level two so that it goes down to level one and perhaps up to level four. Then, try running your code and see if it places the door somewhere on the wall.

 

Also, I've used an overload of NewFamilyInstance that takes a level but not a host. With that method, the z coordinate was the offset from the level, not the total z coordinate. It's possible that the overload you're using works the same. Perhaps you could try @sayu94's suggestion of projecting your point onto the wall's LocationLine then setting its z coordinate to 0 (or the wall's offset from level 2, if it is not zero).

0 Likes
Message 23 of 26

abdul.rafee
Contributor
Contributor
sorry for the late reply I was busy with other work

below the code

public FamilyInstance CreateNewDoor(Document doc, "M_Single-Flush", "Custom Door Type - 2 M", "Level 2", XYZ xyz, Wall wwall, Application app)
{
// LINQ to find the window's FamilySymbol by its type name.
FamilySymbol familySymbol = (from fs in new FilteredElementCollector(doc).
OfClass(typeof(FamilySymbol)).
Cast<FamilySymbol>()
where (fs.Family.Name == fsFamilyName && fs.Name == fsName)
select fs).First();

// LINQ to find the level by its name.
Level level = (from lvl in new FilteredElementCollector(doc).
OfClass(typeof(Level)).
Cast<Level>()
where (lvl.Name == levelName)
select lvl).First();

#region Find the hosting Wall (nearst wall to the insertion point)

#endregion
//Wall wall = null;
//double proximity = (wwall.Location as LocationCurve).Curve.Distance(xyz);
//double distance = double.MaxValue;
//if (proximity < distance)
//{
// distance = proximity;
// wall = wwall;
//}



FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(Wall));

List<Wall> walls = collector.Cast<Wall>().Where(wl => wl.LevelId == level.Id).ToList();

Wall wall = null;

double distance = double.MaxValue;

foreach (Wall w in walls)
{
double proximity = (w.Location as LocationCurve).Curve.Distance(xyz);

if (proximity < distance)
{
distance = proximity;
wall = w;
}
}



// Create door.
using (Transaction t = new Transaction(doc, "Create Door"))
{
t.Start();

if (!familySymbol.IsActive)
{
// Ensure the family symbol is activated.
familySymbol.Activate();
doc.Regenerate();
}

ViewPlan viewPlan = doc.ActiveView as ViewPlan;
Level nlevel = viewPlan.GenLevel;
XYZ levelPoint = new XYZ(xyz.X, xyz.Y, nlevel.Elevation);

//XYZ nxyz = new XYZ(xyz.X, xyz.Y, level.Elevation);
FamilyInstance door = doc.Create.NewFamilyInstance(levelPoint, familySymbol, wall, StructuralType.NonStructural);

doc.Regenerate();
// Category doorCategory = Category.GetCategory(doc, BuiltInCategory.OST_Doors);
//CreateProjectParameterFromSharedparameterAndAddValue(doc, app, "UnitName", door, "201", doorCategory);
t.Commit();
return door;
}
//string prompt = "The element was created!";
//TaskDialog.Show("Revit", prompt);
}
0 Likes
Message 24 of 26

abdul.rafee
Contributor
Contributor
Thanks, brother for your reply, if you have any code for your suggestion I will try.
0 Likes
Message 25 of 26

abdul.rafee
Contributor
Contributor

 

I got the solution

// adding this code will place the door any level

LocationCurve locationCurve = (LocationCurve)wall.Location;
XYZ center = locationCurve.Curve.Evaluate(0.5, true);

 

abdulrafee_0-1680154501011.png

 

 


Many thanks for support.

0 Likes
Message 26 of 26

abdul.rafee
Contributor
Contributor
Thanks, brother for your support.
0 Likes