Hi,
I trying to create column at gird interection, expection show"There are identical instances in the same place. This will result in double counting in schedules." please check attachments below. whats wrong with my code? any helps will be apprecitated.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using System.Runtime.InteropServices.WindowsRuntime;
namespace point
{
[Transaction(TransactionMode.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Document doc = uidoc.Document;
var gridlist = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Grids).OfClass(typeof(Grid)).ToList();
List<Curve> curelist = new List<Curve>();
List<XYZ> inpoint = new List<XYZ>();
foreach (Grid grid in gridlist)
{
curelist.Add(grid.Curve as Curve);
}
for (int i = 0; i < curelist.Count; i++)
{
IntersectionResultArray arrresult = null;
SetComparisonResult setresult = curelist[0].Intersect(curelist[1], out arrresult);
if (setresult != SetComparisonResult.Overlap)
{
throw new InvalidOperationException("no intersect");
}
if (arrresult == null || arrresult.Size != 1)
{
throw new InvalidOperationException("no intersect or more than one ");
}
if (setresult==SetComparisonResult.Overlap&&arrresult.Size==1)
{
XYZ point = arrresult.get_Item(0).XYZPoint;
if (inpoint.Where(x=>x.IsAlmostEqualTo(point)).Count()==0)
{
inpoint.Add(point);
}
}
var column = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Columns).Where(x => x.Name == "457 x 475mm");
Element ele = column.FirstOrDefault();
FamilySymbol fs = ele as FamilySymbol;
Level lv = doc.GetElement(new ElementId(13071)) as Level;
Transaction tx = new Transaction(doc, "create column");
tx.Start();
if (!fs.IsActive)
{
fs.Activate();
}
foreach (XYZ p in inpoint)
{
doc.Create.NewFamilyInstance(p, fs, lv, Autodesk.Revit.DB.Structure.StructuralType.Column);
}
tx.Commit();
}
return Result.Succeeded;
}
}
}