public static void CreateFinFloor(this Room room) { BoundaryData BData = new BoundaryData(room); if (null != BData.Edges()) { CurveArray array = new CurveArray(); foreach (KeyValuePair <Line, XYZ> kvp in BData.Edges()) { Curve c = kvp.Key as Curve; array.Append(c); } Autodesk.Revit.Creation.Document doc = room.Document.Create; doc.NewFloor(array, false); } }
private void CreateWall() { RevitCreation.Application createApp = m_commandData.Application.Application.Create; RevitCreation.Document createDoc = m_commandData.Application.ActiveUIDocument.Document.Create; RevitDB.Line geometryLine = RevitDB.Line.CreateBound(m_startPoint, m_endPoint); if (null == geometryLine) { throw new Exception("Create the geometry line failed."); } RevitDB.Wall createdWall = RevitDB.Wall.Create(m_commandData.Application.ActiveUIDocument.Document, geometryLine, m_createType.Id, m_createlevel.Id, 15, m_startPoint.Z + m_createlevel.Elevation, true, true); if (null == createdWall) { throw new Exception("Create the wall failed."); } }
/// <summary> /// Create a wall with the collected data or the data read from journal /// </summary> private void CreateWall() { // Get the create classes. Creation.Application createApp = m_commandData.Application.Application.Create; Creation.Document createDoc = m_commandData.Application.ActiveUIDocument.Document.Create; // Create geometry line(curve) Line geometryLine = Line.CreateBound(m_startPoint, m_endPoint); if (null == geometryLine) // assert the creation is successful { throw new Exception("Create the geometry line failed."); } // Create the wall using the wall type, level and created geometry line Wall createdWall = Wall.Create(m_commandData.Application.ActiveUIDocument.Document, geometryLine, m_createType.Id, m_createlevel.Id, 15, m_startPoint.Z + m_createlevel.Elevation, true, true); if (null == createdWall) // assert the creation is successful { throw new Exception("Create the wall failed."); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; if (doc.IsFamilyDocument) { TaskDialog.Show("ОТМЕНЕНО", "Данная команда предназначена для запуска в документе проекта"); return(Result.Cancelled); } try { //Выбрать несколько файлов CSV с координатами Transform projectTransform = Utils.GetProjectCoordinatesTransform(doc); string[] filenames = null; WinForms.OpenFileDialog openFileDialog1 = new WinForms.OpenFileDialog(); string curDocPath = doc.PathName; if (!String.IsNullOrEmpty(curDocPath)) { openFileDialog1.InitialDirectory = Path.GetDirectoryName(curDocPath); } openFileDialog1.Filter = "csv files (*.csv)|*.csv"; openFileDialog1.FilterIndex = 1; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = true; openFileDialog1.Title = "Выберите таблицы CSV с координатами 3d-полилиний"; if (openFileDialog1.ShowDialog() == WinForms.DialogResult.OK) { filenames = openFileDialog1.FileNames; List <List <XYZ> > lines3d = new List <List <XYZ> >(); if (Utils.ReadCoordinatesFromCSV(filenames, projectTransform, lines3d)) { //Создать линии модели по координатам RCreation.Document crDoc = doc.Create; using (Transaction tr = new Transaction(doc)) { tr.Start("Draw 3D line"); foreach (List <XYZ> ptList in lines3d) { for (int i = 0; i < ptList.Count - 1; i++) { XYZ startPt = ptList[i]; XYZ endPt = ptList[i + 1]; if (!startPt.IsAlmostEqualTo(endPt)) { Line line = Line.CreateBound(startPt, endPt); XYZ lineVector = (endPt - startPt).Normalize(); XYZ horizontal = XYZ.BasisZ.CrossProduct(lineVector).Normalize(); XYZ norm = lineVector.CrossProduct(horizontal).Normalize(); Plane plane = Plane.CreateByNormalAndOrigin(norm, startPt); SketchPlane sketchPlane = SketchPlane.Create(doc, plane); crDoc.NewModelCurve(line, sketchPlane); } } } tr.Commit(); } } } } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { } catch (Exception ex) { CommonException(ex, "Ошибка при вычерчивании 3d линии в Revit"); } return(Result.Succeeded); }
private static void PlaceLevelBasedHosted(Autodesk.Revit.Creation.Document create, Element host, FamilySymbol familySymbol) { create.NewFamilyInstance(Arrangement.Current.Center, familySymbol, host, Loader.Level, StructuralType.NonStructural); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; if (doc.IsFamilyDocument) { TaskDialog.Show("ОТМЕНЕНО", "Данная команда предназначена для запуска в документе проекта"); return(Result.Cancelled); } try { Transform projectTransform = Utils.GetProjectCoordinatesTransform(doc); //выбрать несколько xml с расположением водосбросов string[] filenames = null; WinForms.OpenFileDialog openFileDialog1 = new WinForms.OpenFileDialog(); string curDocPath = doc.PathName; if (!String.IsNullOrEmpty(curDocPath)) { openFileDialog1.InitialDirectory = Path.GetDirectoryName(curDocPath); } openFileDialog1.Filter = "xml files (*.xml)|*.xml"; openFileDialog1.FilterIndex = 1; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = true; openFileDialog1.Title = "Выберите таблицы CSV с координатами 3d-полилиний"; if (openFileDialog1.ShowDialog() == WinForms.DialogResult.OK) { Creation.Document crDoc = doc.Create; filenames = openFileDialog1.FileNames; using (TransactionGroup trGr = new TransactionGroup(doc)) { trGr.Start("CreateSpillways"); foreach (string filename in filenames) { //распаристь xml PositionData positionData = null; using (StreamReader sr = new StreamReader(filename)) { string serializedData = sr.ReadToEnd(); var xmlSerializer = new XmlSerializer(typeof(PositionData)); var stringReader = new StringReader(serializedData); positionData = (PositionData)xmlSerializer.Deserialize(stringReader); } if (positionData != null) { foreach (SpillwayPosition sp in positionData.SpillwayPositions) { //Загрузка семейства водосброса если еще нет Family spillwayFamily = null; if (sp.Slopes.Count == 2) { spillwayFamily = Utils.GetFamily(doc, "Водосброс2Укл"); } else if (sp.Slopes.Count == 3) { spillwayFamily = Utils.GetFamily(doc, "Водосброс3Укл"); } if (spillwayFamily != null) { ElementId symId = spillwayFamily.GetFamilySymbolIds().First(); FamilySymbol familySymbol = (FamilySymbol)doc.GetElement(symId); using (Transaction tr = new Transaction(doc)) { tr.Start("CreateSpillway"); //активировать типоразмер if (!familySymbol.IsActive) { familySymbol.Activate(); doc.Regenerate(); } //Вставка водосбросов в заданные координаты //Поворот на заданный угол //Если водосброс направлен направо, то использовать отражение (с поворотом в противоположную сторону) XYZ location = projectTransform.OfPoint(Utils.PointByMeters(sp.X, sp.Y, sp.Z)); FamilyInstance fi = crDoc.NewFamilyInstance(location, familySymbol, StructuralType.NonStructural); Line rotationAxis = Line.CreateBound(location, location + XYZ.BasisZ); double rotationAngle = sp.Z_Rotation / (180 / Math.PI); if (sp.ToTheRight) { rotationAngle = rotationAngle + Math.PI; } fi.Location.Rotate(rotationAxis, rotationAngle); if (sp.ToTheRight) { XYZ spillwayDir = Transform.CreateRotation(XYZ.BasisZ, rotationAngle).OfVector(XYZ.BasisY); Plane mirrorPlane = Plane.CreateByNormalAndOrigin(spillwayDir, location); ElementTransformUtils.MirrorElements(doc, new List <ElementId>() { fi.Id }, mirrorPlane, false); //doc.Delete(fi.Id); } //Назначение параметров уклонов водосброса for (int i = 0; i < sp.Slopes.Count; i++) { string lengthParamName = "Длина" + (i + 1); string slopeParamName = "Уклон" + (i + 1); Parameter lengthParam = fi.LookupParameter(lengthParamName); Parameter slopeParam = fi.LookupParameter(slopeParamName); if (lengthParam != null && slopeParam != null) { Slope s = sp.Slopes[i]; lengthParam.Set(UnitUtils.Convert(s.Len, DisplayUnitType.DUT_METERS, DisplayUnitType.DUT_DECIMAL_FEET)); slopeParam.Set(s.S); } } tr.Commit(); } } } } } trGr.Assimilate(); } } } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Succeeded); } catch (Exception ex) { CommonException(ex, "Ошибка при расстановке водосбросов в Revit"); return(Result.Succeeded); } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; if (doc.IsFamilyDocument) { TaskDialog.Show("ОТМЕНЕНО", "Данная команда предназначена для запуска в документе проекта"); return(Result.Cancelled); } try { //Выбрать несколько файлов CSV с координатами Transform projectTransform = Utils.GetProjectCoordinatesTransform(doc); string[] filenames = null; WinForms.OpenFileDialog openFileDialog1 = new WinForms.OpenFileDialog(); string curDocPath = doc.PathName; if (!String.IsNullOrEmpty(curDocPath)) { openFileDialog1.InitialDirectory = Path.GetDirectoryName(curDocPath); } openFileDialog1.Filter = "csv files (*.csv)|*.csv"; openFileDialog1.FilterIndex = 1; openFileDialog1.RestoreDirectory = true; openFileDialog1.Multiselect = true; openFileDialog1.Title = "Выберите таблицы CSV с координатами 3d-полилиний"; if (openFileDialog1.ShowDialog() == WinForms.DialogResult.OK) { filenames = openFileDialog1.FileNames; List <List <XYZ> > lines3d = new List <List <XYZ> >(); if (Utils.ReadCoordinatesFromCSV(filenames, projectTransform, lines3d) && lines3d.Count > 0 && lines3d.First().Count > 0) { //Выбор семейства из числа загруженных семейств формы //Определить id категории Форма Categories categories = doc.Settings.Categories; ElementId IdForm = categories.get_Item(BuiltInCategory.OST_Mass).Id; SelectTypeWindow selectTypeWindow = new SelectTypeWindow(doc, IdForm); bool? result = selectTypeWindow.ShowDialog(); if (result != null && result.Value && selectTypeWindow.SelectedFamilySymbols.Count > 0) { FamilySymbol selectedSymbol = selectTypeWindow.SelectedFamilySymbols.First(); Document crossSectFamDoc = doc.EditFamily(selectedSymbol.Family); //Создать новое семейство формы string fileName = Path.Combine(Path.GetDirectoryName(App.AssemblyLocation), App.FamilyLibRelativePath + massTemplateName + ".rft"); Document massFamDoc = app.NewFamilyDocument(fileName); if (massFamDoc == null) { throw new Exception("Невозможно создать семейство формы"); } //Пересчет координат относительно координат первой точки List <List <XYZ> > lines3dInFam = new List <List <XYZ> >(); XYZ basePt = lines3d.First().First(); foreach (List <XYZ> ptList in lines3d) { List <XYZ> ptListInFam = new List <XYZ>(); lines3dInFam.Add(ptListInFam); foreach (XYZ pt in ptList) { XYZ convertedPt = pt - basePt; ptListInFam.Add(convertedPt); } } //Полный путь к сохраненному семейству string targetRfaFullPath = null; //Выбрать имя для семейства формы, так чтобы оно не пересекалось с уже загруженными семействами FilteredElementCollector a = new FilteredElementCollector(doc).OfClass(typeof(Family)); string famName = null; int n = 0; do { famName = "Massing" + n; n++; } while (a.Any(e => e.Name.Equals(famName))); { //Расставить формы по координатам внутри формы, считая за ноль первую точку первой линии //Вставить созданное семейство в проект //Загрузить семейство поперечного сечения Family family = crossSectFamDoc.LoadFamily(massFamDoc); using (Transaction tr = new Transaction(massFamDoc)) { RCreation.FamilyItemFactory crDoc = massFamDoc.FamilyCreate; tr.Start("Place cross sections"); //Найти выбранный типоразмер FamilySymbol familySymbol = null; foreach (ElementId id in family.GetFamilySymbolIds()) { FamilySymbol fs = (FamilySymbol)massFamDoc.GetElement(id); if (fs.Name.Equals(selectedSymbol.Name)) { familySymbol = fs; } } //активировать типоразмер Utils.ActivateFamSym(massFamDoc, familySymbol); //Вставить поперечник в каждую точку и повернуть по биссектриссе foreach (List <XYZ> ptList in lines3dInFam) { for (int i = 0; i < ptList.Count; i++) { XYZ pt = ptList[i]; FamilyInstance crossSection = crDoc.NewFamilyInstance(pt, familySymbol, StructuralType.NonStructural); XYZ prevVector = null; double prevHorAngle = 0; XYZ nextVector = null; double nextHorAngle = 0; if (i != 0) { XYZ prevPt = ptList[i - 1]; prevVector = pt - prevPt; prevHorAngle = XYZ.BasisY.AngleOnPlaneTo(prevVector, XYZ.BasisZ); } if (i != ptList.Count - 1) { XYZ nextPt = ptList[i + 1]; nextVector = nextPt - pt; nextHorAngle = XYZ.BasisY.AngleOnPlaneTo(nextVector, XYZ.BasisZ); } //Изначально поперечное сечение ориентировано по оси Y //Расчет угла поворота double horRotationAngle = 0; if (prevVector != null && nextVector != null) { horRotationAngle = (prevHorAngle + nextHorAngle) / 2; } else if (prevVector != null && nextVector == null) { horRotationAngle = prevHorAngle; } else if (prevVector == null && nextVector != null) { horRotationAngle = nextHorAngle; } Line vertAxis = Line.CreateBound(pt, pt + XYZ.BasisZ); ElementTransformUtils.RotateElement(massFamDoc, crossSection.Id, vertAxis, horRotationAngle); #region ЭЛЕМЕНТ НЕ МОЖЕТ БЫТЬ ПОВЕРНУТ В ЭТУ ПОЗИЦИЮ //? Определить угол поворота в плоскости, перпендикулярной сечению //XYZ normal = Transform.CreateRotation(XYZ.BasisZ, horRotationAngle).OfVector(XYZ.BasisX);//Нормаль плоскости //double vertRotationAngle = 0; //double prevVertAngle = 0; //double nextVertAngle = 0; //if (prevVector != null) //{ // prevVertAngle = XYZ.BasisY.AngleOnPlaneTo(prevVector, normal); //} //if (nextVector != null) //{ // nextVertAngle = XYZ.BasisY.AngleOnPlaneTo(nextVector, normal); //} //if (prevVector != null && nextVector != null) //{ // vertRotationAngle = (prevVertAngle + nextVertAngle) / 2; //} //else if (prevVector != null && nextVector == null) //{ // vertRotationAngle = prevVertAngle; //} //else if (prevVector == null && nextVector != null) //{ // vertRotationAngle = nextVertAngle; //} //Line horAxis = Line.CreateBound(pt, pt + normal); //ElementTransformUtils.RotateElement(massFamDoc, crossSection.Id, horAxis, vertRotationAngle); #endregion } } tr.Commit(); } string famSaveDir = doc.PathName; if (!String.IsNullOrEmpty(famSaveDir)) { famSaveDir = Path.GetDirectoryName(famSaveDir); } else { famSaveDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); } targetRfaFullPath = Common.Utils.GetNonExistentFileName(famSaveDir, famName, "rfa"); massFamDoc.SaveAs(targetRfaFullPath); } { //Загрузить семейство формы. Family family = massFamDoc.LoadFamily(doc); using (Transaction tr = new Transaction(doc)) { RCreation.Document crDoc = doc.Create; tr.Start("Place mass family"); FamilySymbol familySymbol = (FamilySymbol)doc.GetElement(family.GetFamilySymbolIds().First()); //активировать типоразмер Utils.ActivateFamSym(doc, familySymbol); //Вставить экземпляр семейства crDoc.NewFamilyInstance(basePt, familySymbol, StructuralType.NonStructural); tr.Commit(); } } //Удалить сохраненный файл семейства формы massFamDoc.Close(); if (!String.IsNullOrEmpty(targetRfaFullPath)) { File.Delete(targetRfaFullPath); } //TODO: Открыть загруженное в проект семейство. //Похоже можно открыть только сохраненное семейство по пути //uiapp.OpenAndActivateDocument() } } } } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { } catch (Exception ex) { CommonException(ex, "Ошибка при расстановке поперечных сечений в Revit"); } return(Result.Succeeded); }