Message 1 of 21
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm trying to create a new plug-in on Revit 2016/2017 with the API. The idea is to copy a set of element from small revit file to a central one to compile them.
Here is the code I'm using :
UIDocument mainUiDoc;
Document mainDoc;
string mainPath;
UIDocument secUiDoc;
Document secDoc;
try
{
mainUiDoc = app.ActiveUIDocument;
mainDoc = mainUiDoc.Document;
ViewPlan mainView = (ViewPlan)mainDoc.ActiveView;
mainPath = mainDoc.PathName;
XYZ extremitePoint;
Selection sel = mainUiDoc.Selection;
extremitePoint = sel.PickPoint("Selectionner le coin sup. gauche de la feuille");
secUiDoc = app.OpenAndActivateDocument(((RevitFile)Main._roomData["revit"]).Path);
secDoc = secUiDoc.Document;
FilteredElementCollector collector = new FilteredElementCollector(secDoc);
ViewPlan secView = collector.OfClass(typeof(ViewPlan)).Cast<ViewPlan>().First(
x => x.ViewType == ViewType.FloorPlan &&
x.IsTemplate == false &&
x.Name.Contains(((RevitFile)Main._roomData["revit"]).Typology, StringComparison.OrdinalIgnoreCase));
secUiDoc.ActiveView = secView;
FilterableValueProvider provider = new ParameterValueProvider(new ElementId(BuiltInParameter.ALL_MODEL_TYPE_NAME));
FilterRule rule = new FilterStringRule(provider, new FilterStringContains(), "BY_GO", false);
ElementParameterFilter epf = new ElementParameterFilter(rule, true);
ICollection<ElementId> npText = new FilteredElementCollector(secDoc, secView.Id).WherePasses(epf).ToElementIds();
using (TransactionGroup tx = new TransactionGroup(mainDoc, "Insert"))
{
ICollection<ElementId> pastedElements;
tx.Start();
using (Transaction tr = new Transaction(mainDoc, "Copy elements"))
{
tr.Start();
FailureHandlingOptions failOpt = tr.GetFailureHandlingOptions();
failOpt.SetFailuresPreprocessor(new WarningSwallower());
tr.SetFailureHandlingOptions(failOpt);
pastedElements = ElementTransformUtils.CopyElements(secView, npText, mainView,null, new CopyPasteOptions());
mainDoc.Regenerate();
tr.Commit();
}
using (Transaction tr = new Transaction(mainDoc, "translate elements"))
{
tr.Start();
pastedElements = new FilteredElementCollector(mainDoc, pastedElements).WherePasses(epf).ToElementIds();
BoundingBoxXYZ floor = new FilteredElementCollector(mainDoc, pastedElements).OfClass(typeof(Floor)).First().get_BoundingBox(null);
XYZ originePoint = floor.Min;
XYZ translation = extremitePoint - originePoint;
translation = new XYZ(translation.X, translation.Y, 0);
ElementTransformUtils.MoveElements(mainDoc, pastedElements, translation);
tr.Commit();
}
using (Transaction tr = new Transaction(mainDoc, "rotate elements"))
{
tr.Start();
BoundingBoxXYZ floor = new FilteredElementCollector(mainDoc, pastedElements).OfClass(typeof(Floor)).First().get_BoundingBox(null);
XYZ originePoint = floor.Min;
Line rotation = Line.CreateBound(extremitePoint, new XYZ(extremitePoint.X, extremitePoint.Y, extremitePoint.Z+10));
ElementTransformUtils.RotateElements(mainDoc, pastedElements, rotation, - (double)Main._roomData["rotation"] * Math.PI / 180);
tr.Commit();
}
using (Transaction tr = new Transaction(mainDoc, "miror elements"))
{
tr.Start();
pastedElements = new FilteredElementCollector(mainDoc, pastedElements).WherePasses(epf).ToElementIds();
BoundingBoxXYZ floor = new FilteredElementCollector(mainDoc, pastedElements).OfClass(typeof(Floor)).First().get_BoundingBox(null);
Plane mirror = null;
switch ((string)Main._roomData["Symétries"])
{
case "nulle":
break;
case "horizontale":
mirror = new Plane(new XYZ(1, 0, 0), new XYZ((floor.Max.X + floor.Min.X) / 2, (floor.Max.Y + floor.Min.Y) / 2, 0));
ElementTransformUtils.MirrorElements(mainDoc, pastedElements, mirror, false);
break;
case "verticale":
mirror = new Plane(new XYZ(0, 1, 0), new XYZ((floor.Max.X + floor.Min.X) / 2, (floor.Max.Y + floor.Min.Y) / 2, 0));
ElementTransformUtils.MirrorElements(mainDoc, pastedElements, mirror, false);
break;
default:
break;
}
tr.Commit();
}
tx.Assimilate();
}When I use it, everything is good except the dimensions. They are inside the new document (I can get them with there id and RevitLookup) but they are hidden. If I select on of them and add a witness line the dimension is now visible again. I tried to close and reopen Revit and place the vien on a sheet bt nothing.
Any idea ?
Thank you !
Solved! Go to Solution.