/// <summary> /// This node will place the given view on the given sheet, if possible. For floor plan views: They cannot be on any other sheets. Now supports schedules! /// </summary> /// <param name="sheet">The sheet to place views on.</param> /// <param name="view">The view to place.</param> /// <param name="location">The location of the view.</param> /// <returns name="Result">The result</returns> /// <search> /// viewport, addview,rhythm /// </search> public static global::Revit.Elements.Element Create(global::Revit.Elements.Views.Sheet sheet, global::Revit.Elements.Element view, Autodesk.DesignScript.Geometry.Point location) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; //obtain the element id from the sheet ElementId sheetId = new ElementId(sheet.Id); global::Revit.Elements.Element result = null; if (view.InternalElement.ToString() == "Autodesk.Revit.DB.ViewSchedule") { //obtain the element id from the view ElementId viewId = new ElementId(view.Id); //chane the dynamo point to a revit point var revitPoint = location.ToRevitType(true); //start the transaction to place views TransactionManager.Instance.EnsureInTransaction(doc); result = Autodesk.Revit.DB.ScheduleSheetInstance.Create(doc, sheetId, viewId, revitPoint).ToDSType(true); TransactionManager.Instance.TransactionTaskDone(); } else { //obtain the element id from the view ElementId viewId = new ElementId(view.Id); //chane the dynamo point to a revit point var revitPoint = location.ToRevitType(true); //start the transaction to place views TransactionManager.Instance.EnsureInTransaction(doc); result = Autodesk.Revit.DB.Viewport.Create(doc, sheetId, viewId, revitPoint).ToDSType(true); TransactionManager.Instance.TransactionTaskDone(); } return(result); }
//族实例化,创建族并对其进行旋转 private FamilyInstance CreateFamlyInstance(DG.Point DGpoint, DG.Curve curve, FamilySymbol FamilySymbol, ExternalCommandData commandData) { UIDocument uiDoc = commandData.Application.ActiveUIDocument; //取得当前活动文档 XYZ point = DGpoint.ToRevitType(false); //dynamo转Revit FamilyInstance familyInstance = uiDoc.Document.Create.NewFamilyInstance(point, FamilySymbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); LocationPoint locationPoint = familyInstance.Location as LocationPoint;//自适应族基点 XYZ axisP = new XYZ(point.X, point.Y, point.Z + 100); Autodesk.Revit.DB.Line axis = Autodesk.Revit.DB.Line.CreateBound(point, axisP);//旋转轴 //计算旋转角度 double ratio = curve.ParameterAtPoint(DGpoint); DG.Vector vector = curve.TangentAtParameter(ratio); MessageBox.Show(vector.ToString()); DG.Vector vector1 = DG.Vector.ByCoordinates(vector.X, vector.Y, 0);//三维切向量的平面向量 DG.Vector vectorY = DG.Vector.ByCoordinates(0, 1, 0); double angle = vector1.AngleWithVector(vectorY) / 180 * Math.PI; MessageBox.Show(angle.ToString()); //locationPoint.Rotate(axis, angle);//旋转横梁 ElementTransformUtils.RotateElement(uiDoc.Document, familyInstance.Id, axis, -angle); return(familyInstance); }
/// <summary> /// Set the Location on the sheet where the ScheduleInstance is placed (in sheet coordinates). /// </summary> /// <param name="point"></param> /// <returns></returns> public ScheduleOnSheet SetLocation(Autodesk.DesignScript.Geometry.Point point) { TransactionManager.Instance.EnsureInTransaction(Application.Document.Current.InternalDocument); this.InternalScheduleOnSheet.Point = point.ToRevitType(); TransactionManager.Instance.TransactionTaskDone(); return(this); }
/// <summary> /// This node will set the viewport's box center given the point. /// </summary> /// <param name="viewport">The viewport to set.</param> /// <param name="point">The point to use.</param> /// <search> /// viewport /// </search> public static void SetBoxCenter(global::Revit.Elements.Element viewport, Point point) { Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument; Autodesk.Revit.DB.Viewport internalViewport = (Autodesk.Revit.DB.Viewport)viewport.InternalElement; TransactionManager.Instance.EnsureInTransaction(doc); internalViewport.SetBoxCenter(point.ToRevitType()); TransactionManager.Instance.TransactionTaskDone(); }
/// <summary> /// Place an instance of a Model Group into the Autodesk Revit document, using a location and a group type. /// </summary> /// <param name="location">The point to place the group.</param> /// <param name="groupType">The type of group to place.</param> /// <returns>The new group instance.</returns> public static Group PlaceInstance(Autodesk.DesignScript.Geometry.Point location, Element groupType) { var internalType = groupType.InternalElement as Autodesk.Revit.DB.GroupType; if (internalType == null) { throw new InvalidOperationException(String.Format(Properties.Resources.InvalidGroupType, nameof(groupType))); } XYZ newLocation = location.ToRevitType(true); TransactionManager.Instance.EnsureInTransaction(Document); Group newGroup = Document.Create.PlaceGroup(newLocation, internalType).ToDSType(true) as Group; TransactionManager.Instance.TransactionTaskDone(); return(newGroup); }
/// <summary> /// Update an existing element's location /// </summary> /// <param name="geometry">New Location Point or Curve</param> public void SetLocation(Geometry geometry) { TransactionManager.Instance.EnsureInTransaction(Application.Document.Current.InternalDocument); if (this.InternalElement.Location is Autodesk.Revit.DB.LocationPoint) { if (geometry is Autodesk.DesignScript.Geometry.Point) { Autodesk.DesignScript.Geometry.Point point = geometry as Autodesk.DesignScript.Geometry.Point; Autodesk.Revit.DB.LocationPoint pt = this.InternalElement.Location as Autodesk.Revit.DB.LocationPoint; pt.Point = point.ToRevitType(true); } else { throw new Exception(Properties.Resources.PointRequired); } } else if (this.InternalElement.Location is Autodesk.Revit.DB.LocationCurve && geometry is Curve) { if (geometry is Curve) { Curve dynamoCurve = geometry as Curve; Autodesk.Revit.DB.LocationCurve curve = this.InternalElement.Location as Autodesk.Revit.DB.LocationCurve; curve.Curve = dynamoCurve.ToRevitType(true); } else { throw new Exception(Properties.Resources.CurveRequired); } } else { throw new Exception(Properties.Resources.InvalidElementLocation); } TransactionManager.Instance.TransactionTaskDone(); }