public static void SetLocation(this Instance element, XYZ newOrigin, XYZ newBasisX, XYZ newBasisY) { element.GetLocation(out var origin, out var basisX, out var basisY); var basisZ = basisX.CrossProduct(basisY); var newBasisZ = newBasisX.CrossProduct(newBasisY); { if (!basisZ.IsParallelTo(newBasisZ)) { var axisDirection = basisZ.CrossProduct(newBasisZ); double angle = basisZ.AngleTo(newBasisZ); using (var axis = Line.CreateUnbound(origin, axisDirection)) ElementTransformUtils.RotateElement(element.Document, element.Id, axis, angle); element.GetLocation(out origin, out basisX, out basisY); basisZ = basisX.CrossProduct(basisY); } if (!basisX.IsAlmostEqualTo(newBasisX)) { double angle = basisX.AngleOnPlaneTo(newBasisX, newBasisZ); using (var axis = Line.CreateUnbound(origin, newBasisZ)) ElementTransformUtils.RotateElement(element.Document, element.Id, axis, angle); } { var trans = newOrigin - origin; if (!trans.IsZeroLength()) { ElementTransformUtils.MoveElement(element.Document, element.Id, trans); } } } }
public void ApplyChange() { if (this.NewLocationCurve != null) { var lc = this.Elem.Location as LocationCurve; lc.Curve = this.NewLocationCurve; } if (this.Translation != null) { ElementTransformUtils.MoveElement(this.Elem.Document, this.Elem.Id, this.Translation); } foreach (var pcm in this.ParametersToChange.Values) { pcm.ApplyChange(); } if (this.Elem is FamilyInstance) { var fi = this.Elem as FamilyInstance; if (fi.HandOrientation.IsAlmostEqualToByDifference(this.HandOrientation, 0.0001) == false) { fi.flipHand(); } if (fi.FacingOrientation.IsAlmostEqualToByDifference(this.FacingOrientation, 0.0001) == false) { fi.flipFacing(); } } if (this.ElemType != ElementId.InvalidElementId) { var typeP = this.Elem.get_Parameter(BuiltInParameter.ELEM_TYPE_PARAM); typeP.Set(this.ElemType); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Reference pickObj = uidoc.Selection.PickObject(ObjectType.Element); ElementId eleId = pickObj.ElementId; Element ele = doc.GetElement(eleId); using (Transaction trans = new Transaction(doc, "Edit Element")) { trans.Start(); //Move element XYZ moveVec = new XYZ(3, 3, 0); ElementTransformUtils.MoveElement(doc, eleId, moveVec); //Rotate element LocationPoint locp = ele.Location as LocationPoint; XYZ p1 = locp.Point; XYZ p2 = new XYZ(p1.X, p1.Y, p1.Z + 10); Line axis = Line.CreateBound(p1, p2); double angle = 30 * Math.PI / 180; ElementTransformUtils.RotateElement(doc, eleId, axis, angle); trans.Commit(); return(Result.Succeeded); } }
private void editByOffsetCurve() { var doc = this.Wall.Document; var locCurve = this.Wall.LocationCurve(); var pos = locCurve.GetEndPoint(0); var offsetPos = this.newOffsetLocCurve.GetEndPoint(0); var deltaZ = (offsetPos - pos).Z; var p = this.Wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET); this.paramValues[BuiltInParameter.WALL_BASE_OFFSET.GetId()] = new ParameterEditRecorder(p, deltaZ); XYZ tl = null; if (this.newOffsetLocCurve.Translational(locCurve, ref tl)) { tl = new XYZ(tl.X, tl.Y, 0.0); ElementTransformUtils.MoveElement(doc, this.Wall.Id, tl); } else { tl = new XYZ(0, 0, deltaZ * -1.0); var tf = Transform.CreateTranslation(tl); var newLocCurve = this.newOffsetLocCurve.CreateTransformed(tf); ((LocationCurve)this.Wall.Location).Curve = newLocCurve; } }
//LAB 12 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; Selection sel = uidoc.Selection; IList <Reference> refs = sel.PickObjects(ObjectType.Element, "Please select some elements"); if (!refs.Count().Equals(1)) { TaskDialog.Show("Error", "Please select only one element from the drawing"); } else { if (refs.Count.Equals(1)) { Element selectedElement = doc.GetElement(refs.First().ElementId); using (Transaction trans = new Transaction(doc, "Translate Element")) { trans.Start(); ElementTransformUtils.MoveElement(doc, selectedElement.Id, new XYZ(20, 0, 0)); trans.Commit(); } } else { return(Result.Failed); } } return(Result.Succeeded); }
public void Createline(Document doc, FamilyInstance familyInstance, XYZ point) { var dic = GetTypeFace(familyInstance); using (Transaction t = new Transaction(doc, "Create detail line")) { t.Start(); var list = dic.Keys.ToList(); foreach (var item in list) { foreach (var i in dic[item]) { EdgeArrayArray edgeArrayArray = i.EdgeLoops; foreach (EdgeArray j in edgeArrayArray) { foreach (Edge k in j) { try { Curve curve = k.AsCurve(); View view = doc.ActiveView; var detailCurve = doc.Create.NewDetailCurve(view, curve); ElementTransformUtils.MoveElement(doc, detailCurve.Id, point); } catch { } } } } } t.Commit(); } }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Expected results: The Analytical Node has been moved and the connection has been kept try { // Get the Document UIDocument activeDoc = commandData.Application.ActiveUIDocument; Autodesk.Revit.DB.Document document = activeDoc.Document; // Create Analytical Panel AnalyticalPanel analyticalPanel = CreateAnalyticalPanel.CreateAMPanel(document); // Create the connected Analytical Member AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document); // Select the node Reference eRef = activeDoc.Selection.PickObject(ObjectType.PointOnElement, "Select an Analytical Node"); // Move the Analytical Panel using ElementTransformUtils using (Transaction transaction = new Transaction(document, "Move panel with ElementTransformUtils")) { transaction.Start(); ElementTransformUtils.MoveElement(document, eRef.ElementId, new XYZ(-5, -5, 0)); transaction.Commit(); } return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
private void EditLocation(Element opening) { XYZ curentLocation = Common.GetFamilyInstanceOrigin(opening); XYZ tranformVector = _origin - curentLocation; ElementTransformUtils.MoveElement(_doc, opening.Id, tranformVector); }
/// <summary> /// Mutate the two end points of the ReferencePlane /// </summary> /// <param name="bubbleEnd"></param> /// <param name="freeEnd"></param> /// <returns>False if the operation failed</returns> private bool InternalSetEndpoints(XYZ bubbleEnd, XYZ freeEnd) { TransactionManager.Instance.EnsureInTransaction(Document); var refPlane = this.InternalReferencePlane; XYZ oldBubbleEnd = refPlane.BubbleEnd; XYZ oldFreeEnd = refPlane.FreeEnd; XYZ midPointOld = 0.5 * (oldBubbleEnd + oldFreeEnd); XYZ midPoint = 0.5 * (bubbleEnd + freeEnd); XYZ moveVec = XYZ.BasisZ.DotProduct(midPoint - midPointOld) * XYZ.BasisZ; // (sic) From Dynamo Legacy var success = true; try { ElementTransformUtils.MoveElement(Document, refPlane.Id, moveVec); refPlane.BubbleEnd = bubbleEnd; refPlane.FreeEnd = freeEnd; } catch { success = false; } TransactionManager.Instance.TransactionTaskDone(); return(success); }
private void EditVerticalLocation(Element opening) { XYZ curentLocation = Common.GetSharfOpenningOrigin(opening); XYZ tranformVector = _origin - curentLocation; ElementTransformUtils.MoveElement(_document, opening.Id, tranformVector); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var uiDoc = uiApp.ActiveUIDocument; var app = uiApp.Application; var doc = uiDoc.Document; try { // Sử dụng PickObject để chọn đối tượng trên giao diện Revit // các dòng sau hàm này sẽ chưa được thực thi cho đến khi người dùng chọn một đối tượng trên Revit var refObject = uiDoc.Selection.PickObject(ObjectType.Element); var element = doc.GetElement(refObject.ElementId); var elementId = element.Id; using (var transaction = new Transaction(doc, "Change Location")) { transaction.Start(); var vectorMove = new XYZ(10, 10, 0); ElementTransformUtils.MoveElement(doc, elementId, vectorMove); transaction.Commit(); } } catch (Exception e) { message = e.Message; return(Result.Failed); } return(Result.Succeeded); }
internal bool MovePointById(ElementId id, XYZ trans) { var pt = this.RevitElement.Document.GetElement(id) as ReferencePoint; ElementTransformUtils.MoveElement(this.RevitElement.Document, id, trans); return(pt.Location.Move(trans)); }
/// <summary> /// Move a wall, append a node to tree view /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void moveWallButton_Click(object sender, EventArgs e) { if (m_lastCreatedWall == null) { return; } // a sub-transaction is not necessary in this case // it is used for illustration purposes only using (SubTransaction subTransaction = new SubTransaction(m_document)) { // if not handled explicitly, the sub-transaction will be rolled back when leaving this block try { if (subTransaction.Start() == TransactionStatus.Started) { Autodesk.Revit.DB.XYZ translationVec = new Autodesk.Revit.DB.XYZ(10, 10, 0); ElementTransformUtils.MoveElement(m_document, m_lastCreatedWall.Id, translationVec); updateModel(true); // immediately update the view to see the changes if (subTransaction.Commit() == TransactionStatus.Committed) { AddNode(OperationType.ObjectModification, "Moved wall " + m_lastCreatedWall.Id.IntegerValue.ToString()); return; } } } catch (System.Exception ex) { TaskDialog.Show("Revit", "Exception when moving a wall: " + ex.Message); } } TaskDialog.Show("Revit", "Moving wall failed."); }
/// <summary> /// need open transaction. /// </summary> public static void CreateDirectShape(this Document _doc, IEnumerable <GeometryObject> _geometry, XYZ _translation) { DirectShape ds = DirectShape.CreateElement(_doc, new ElementId(BuiltInCategory.OST_GenericModel)); ds.SetShape(_geometry.ToList()); ElementTransformUtils.MoveElement(ds.Document, ds.Id, _translation); }
public static void SetTransform(this Instance element, XYZ newOrigin, XYZ newBasisX, XYZ newBasisY) { var current = element.GetTransform(); var BasisZ = newBasisX.CrossProduct(newBasisY); { if (!current.BasisZ.IsParallelTo(BasisZ)) { var axisDirection = current.BasisZ.CrossProduct(BasisZ); double angle = current.BasisZ.AngleTo(BasisZ); using (var axis = Line.CreateUnbound(current.Origin, axisDirection)) ElementTransformUtils.RotateElement(element.Document, element.Id, axis, angle); current = element.GetTransform(); } if (!current.BasisX.IsAlmostEqualTo(newBasisX)) { double angle = current.BasisX.AngleOnPlaneTo(newBasisX, BasisZ); using (var axis = Line.CreateUnbound(current.Origin, BasisZ)) ElementTransformUtils.RotateElement(element.Document, element.Id, axis, angle); } { var trans = newOrigin - current.Origin; if (!trans.IsZeroLength()) { ElementTransformUtils.MoveElement(element.Document, element.Id, trans); } } } }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Expected results: The Analytical Panel has been moved and the connection with the Analytical Member was kept try { // Get the Document Document document = commandData.Application.ActiveUIDocument.Document; // Create Analytical Panel AnalyticalPanel analyticalPanel = CreateAnalyticalPanel.CreateAMPanel(document); // Create an Analytical Member connected with the Analytical Panel above AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document); // Move the Analytical Panel using ElementTransformUtils using (Transaction transaction = new Transaction(document, "Move panel with ElementTransformUtils")) { transaction.Start(); ElementTransformUtils.MoveElement(document, analyticalPanel.Id, new XYZ(5, 5, 0)); transaction.Commit(); } return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
/// <summary> /// Move an element to the point. /// </summary> /// <param name="elem">The element to be moved.</param> /// <param name="targetPoint">The location element to be moved.</param> internal void MoveElement(Element elem, XYZ targetPoint) { XYZ vecToMove = targetPoint - m_elemPickedPoint; m_elemPickedPoint = targetPoint; ElementTransformUtils.MoveElement(m_document.Document, elem.Id, vecToMove); }
/// <summary> /// A sampler function that demonstrates how to modify an element /// transform utils methods. /// </summary> public void ModifyElementByTransformUtilsMethods(Element e) { string msg = "The element changed:\n\n"; // Try move double dt = Constant.MmToFeet(1000.0); // Hard cording for simplicity. XYZ v = new XYZ(dt, dt, 0.0); ElementTransformUtils.MoveElement(e.Document, e.Id, v); // 2012 msg += "move by (1000, 1000, 0)\r\n"; // Try rotate: 15 degree around z-axis. XYZ pt1 = XYZ.Zero; XYZ pt2 = XYZ.BasisZ; Line axis = Line.CreateBound(pt1, pt2); ElementTransformUtils.RotateElement(e.Document, e.Id, axis, Math.PI / 12.0); // 2012 msg += "rotate by 15 degree around Z-axis\r\n"; TaskDialog.Show("Modify element by utils methods", msg); }
private void SetViewForSheet(View view, ViewSheet sheet, int scale) { if (scale > 0) { try { view.Scale = scale; } catch (Exception ex) { } } try { if (Viewport.CanAddViewToSheet(view.Document, sheet.Id, view.Id)) { BoundingBoxUV sheetBox = sheet.Outline; XYZ sheetOrigin = sheet.Origin; Viewport viewport = Viewport.Create(view.Document, sheet.Id, view.Id, XYZ.Zero); BoundingBoxXYZ viewportBoundingBox = viewport.get_BoundingBox(sheet); XYZ viewportOrigin = viewportBoundingBox.Min; ElementTransformUtils.MoveElement(view.Document, viewport.Id, new XYZ(sheetOrigin.X - viewportOrigin.X, sheetOrigin.Y - viewportOrigin.Y, 0)); } else { } } catch (ArgumentException ex) { } }
private Curve moveModelLine(ExternalCommandData commandData) { Document revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档 Autodesk.Revit.ApplicationServices.Application revitApp = commandData.Application.Application; //取得应用程序 UIDocument uiDoc = commandData.Application.ActiveUIDocument; //取得当前活动文档 Curve curve; Selection sel = uiDoc.Selection; Reference ref1 = sel.PickObject(ObjectType.Element, "选择一条模型线作为平曲线/纵曲线"); Element elem = revitDoc.GetElement(ref1); ModelLine modelLine = elem as ModelLine; //做一个判断,判断其是否为ModelNurbSpline if (modelLine == null) { ModelNurbSpline modelNurbSpline = elem as ModelNurbSpline; curve = modelNurbSpline.GeometryCurve; } else { curve = modelLine.GeometryCurve; } //移动平曲线 XYZ moveVec = new XYZ(curve.Length, curve.Length, curve.Length); ElementTransformUtils.MoveElement(uiDoc.Document, elem.Id, moveVec); return(curve); }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // Expected results: the first Analytical Member has been moved and the connection with the second Analytical Member was kept try { // Get the document Document document = commandData.Application.ActiveUIDocument.Document; // Create the first Analytical Member AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document); // Create the second Analytical Member that is convergent with the first one AnalyticalMember convergentAnalyticalMember = CreateAnalyticalMember.CreateConvergentMember(document); // Move the first Analytical Member using ElementTransformUtils using (Transaction transaction = new Transaction(document, "Move member with ElementTransformUtils")) { transaction.Start(); ElementTransformUtils.MoveElement(document, analyticalMember.Id, new XYZ(15, 0, 0)); transaction.Commit(); } return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
public void ModifyElementByTransformUtilsMethods(Element elem) { // keep the message to the user. string msg = "The element changed: " + "\n\n"; // try move double dt = mmToFeet(1000.0); // hard cording for simplicity. XYZ v = new XYZ(dt, dt, 0.0); ElementTransformUtils.MoveElement(m_rvtDoc, elem.Id, v); msg = msg + "move by (1000, 1000, 0)" + "\n"; // try rotate: 15 degree around z-axis. XYZ pt1 = XYZ.Zero; XYZ pt2 = XYZ.BasisZ; Line axis = Line.CreateBound(pt1, pt2); ElementTransformUtils.RotateElement(m_rvtDoc, elem.Id, axis, Math.PI / 12.0); msg = msg + "rotate by 15 degree around Z-axis" + "\n"; // message to the user. TaskDialog.Show("Modify element by utils methods", msg); }
// 移動柱的Function private string moveColumn(Document doc, FamilyInstance column) { // 抓取柱的位置並記錄起始位置 LocationPoint columnLocation = column.Location as LocationPoint; XYZ oldPlace = columnLocation.Point; // 給予位移值 XYZ translationVector = new XYZ(10, 20, 30); // 此處雖然有給Z方向的移動量,但因為柱子底部必須與樓板做連接,因此柱子並不會做Z方向的移動 // 將Document(doc)內的column移動 ElementTransformUtils.MoveElement(doc, column.Id, translationVector); // 抓取柱的位置並記錄最後位置 columnLocation = column.Location as LocationPoint; XYZ newPlace = columnLocation.Point; // 回傳資訊 string info = "元件移動前的座標為:\n " + "(" + oldPlace.X + ", " + oldPlace.Y + ", " + oldPlace.Z + ")" + "\n元件移動後的座標為:\n" + "(" + newPlace.X + ", " + newPlace.Y + ", " + newPlace.Z + ")"; return(info); }
void ReconstructSketchPlaneByPlane ( Document doc, ref Autodesk.Revit.DB.Element element, Rhino.Geometry.Plane plane ) { if (!plane.IsValid) { ThrowArgumentException(nameof(plane), "Plane is not valid."); } var scaleFactor = 1.0 / Revit.ModelUnits; plane = plane.ChangeUnits(scaleFactor); if (element is SketchPlane sketchPlane) { bool pinned = element.Pinned; element.Pinned = false; var plane0 = sketchPlane.GetPlane(); using (var plane1 = plane.ToHost()) { if (!plane0.Normal.IsParallelTo(plane1.Normal)) { var axisDirection = plane0.Normal.CrossProduct(plane1.Normal); double angle = plane0.Normal.AngleTo(plane1.Normal); using (var axis = Line.CreateUnbound(plane0.Origin, axisDirection)) ElementTransformUtils.RotateElement(doc, element.Id, axis, angle); plane0 = sketchPlane.GetPlane(); } { double angle = plane0.XVec.AngleOnPlaneTo(plane1.XVec, plane1.Normal); if (angle != 0.0) { using (var axis = Line.CreateUnbound(plane0.Origin, plane1.Normal)) ElementTransformUtils.RotateElement(doc, element.Id, axis, angle); } } var trans = plane1.Origin - plane0.Origin; if (!trans.IsZeroLength()) { ElementTransformUtils.MoveElement(doc, element.Id, trans); } } element.Pinned = pinned; } else { ReplaceElement(ref element, SketchPlane.Create(doc, plane.ToHost())); } }
//directly moves an element around a sheet, DOES NOT MOVE IT BETWEEN SHEETS public void MoveElement(ElementId id, double x, double y) { using (Transaction t = new Transaction(doc)) { t.Start("Moving element with id: '" + id + "' - X: '" + x + "' Y: '" + y); ElementTransformUtils.MoveElement(doc, id, new XYZ(x, y, 0)); t.Commit(); } }
public override void Execute() { if (this.translation != null) { ElementTransformUtils.MoveElement(this.FI.Document, this.FI.Id, this.translation); } base.executeChange(); }
public XYZ GetReferenceDirection(Reference ref1, Document doc) // returns the direction perpendicular to reference // returns XYZ.Zero on error; { XYZ res = XYZ.Zero; XYZ workPlaneNormal = doc.ActiveView.SketchPlane.GetPlane().Normal; if (ref1.ElementId == ElementId.InvalidElementId) { return(res); } Element elem = doc.GetElement(ref1.ElementId); if (elem == null) { return(res); } if (ref1.ElementReferenceType == ElementReferenceType.REFERENCE_TYPE_SURFACE || ref1.ElementReferenceType == ElementReferenceType.REFERENCE_TYPE_LINEAR) { // make a dimension to a point for direction XYZ bEnd = new XYZ(10, 10, 10); ReferenceArray refArr = new ReferenceArray(); refArr.Append(ref1); Dimension dim = null; using (Transaction t = new Transaction(doc, "test")) { FailureHandlingOptions failureHandlingOptions = t.GetFailureHandlingOptions(); FailureHandler failureHandler = new FailureHandler(); failureHandlingOptions.SetFailuresPreprocessor(failureHandler); failureHandlingOptions.SetClearAfterRollback(true); t.SetFailureHandlingOptions(failureHandlingOptions); t.Start(); using (SubTransaction st = new SubTransaction(doc)) { st.Start(); ReferencePlane refPlane = doc.Create.NewReferencePlane(XYZ.Zero, bEnd, bEnd.CrossProduct(XYZ.BasisZ).Normalize(), doc.ActiveView); ModelCurve mc = doc.Create.NewModelCurve(Line.CreateBound(XYZ.Zero, new XYZ(10, 10, 10)), SketchPlane.Create(doc, refPlane.Id)); refArr.Append(mc.GeometryCurve.GetEndPointReference(0)); dim = doc.Create.NewDimension(doc.ActiveView, Line.CreateBound(XYZ.Zero, new XYZ(10, 0, 0)), refArr); ElementTransformUtils.MoveElement(doc, dim.Id, new XYZ(0, 0.1, 0)); st.Commit(); } if (dim != null) { Curve cv = dim.Curve; cv.MakeBound(0, 1); XYZ pt1 = cv.GetEndPoint(0); XYZ pt2 = cv.GetEndPoint(1); res = pt2.Subtract(pt1).Normalize(); } t.RollBack(); } } return(res); }
public void Generate(Document doc, CSAModel model, Element element, XYZ offset) { CompoundStructure compoundStructure = model.GetCompoundStructure(element);//获取文本载体 if (compoundStructure == null) { return; } var texts = model.FetchTextsFromCompoundStructure(doc, compoundStructure);//获取文本数据 if (texts.Count == 0) { return; } if (texts.Count == 1) { TaskDialog.Show("警告", "暂不支持单层的结构做法标注"); } else { model.TargetId = element.Id; //主体 var lineFamilySymbol = VLConstraintsForCSA.GetMultipleTagSymbol(doc); //获取线标注类型 bool isRegenerate = offset != null; FamilyInstance line; if (isRegenerate) { line = doc.GetElement(model.LineId) as FamilyInstance; model.CalculateLocations(element, line, offset); //计算内容定位 Clear(doc, model); line = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), lineFamilySymbol, doc.ActiveView); //生成 线 } else { line = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), lineFamilySymbol, doc.ActiveView); //生成 线 model.CalculateLocations(element, line, offset); //计算内容定位 } var lineLocation = model.LineLocation; var textLocations = model.TextLocations; ElementTransformUtils.MoveElement(doc, line.Id, lineLocation); //线定位 LocationPoint locationPoint = line.Location as LocationPoint; //线 旋转处理 locationPoint.RotateByXY(lineLocation, model.VerticalVector); model.LineId = line.Id; model.UpdateLineParameters(line, model.LineHeight, model.LineWidth, model.LineSpace, model.Texts.Count()); //线参数设置 List <TextNote> textNotes = new List <TextNote>(); foreach (var text in model.Texts) //生成 文本 { var textLocation = model.TextLocations[model.Texts.IndexOf(text)]; var textNote = TextNote.Create(doc, doc.ActiveView.Id, textLocation, text, model.TextNoteTypeElementId); textNotes.Add(textNote); textNote.Location.RotateByXY(textLocation, model.VerticalVector); } model.TextNoteIds = textNotes.Select(c => c.Id).ToList(); //测试用 //GraphicsDisplayerManager.Display(@"E:\WorkingSpace\Outputs\Images\1023结构做法标注.png", lines, Model.TextLocations); } }
private Extrusion CreateExtrusion(Document document, SketchPlane sketchPlane) { Extrusion rectExtrusion = null; // make sure we have a family document if (true == document.IsFamilyDocument) { // define the profile for the extrusion CurveArrArray curveArrArray = new CurveArrArray(); CurveArray curveArray1 = new CurveArray(); CurveArray curveArray2 = new CurveArray(); CurveArray curveArray3 = new CurveArray(); // create a rectangular profile XYZ p0 = XYZ.Zero; XYZ p1 = new XYZ(10 / 304.8, 0, 0); XYZ p2 = new XYZ(10 / 304.8, 10 / 304.8, 0); XYZ p3 = new XYZ(0, 10 / 304.8, 0); Line line1 = Line.CreateBound(p0, p1); Line line2 = Line.CreateBound(p1, p2); Line line3 = Line.CreateBound(p2, p3); Line line4 = Line.CreateBound(p3, p0); curveArray1.Append(line1); curveArray1.Append(line2); curveArray1.Append(line3); curveArray1.Append(line4); curveArrArray.Append(curveArray1); using (Transaction ts = new Transaction(document)) { ts.Start("Create"); // create solid rectangular extrusion rectExtrusion = document.FamilyCreate.NewExtrusion(true, curveArrArray, sketchPlane, 1000 / 304.8); if (null != rectExtrusion) { // move extrusion to proper place XYZ transPoint1 = new XYZ(2000 / 304.8, 0, 0); ElementTransformUtils.MoveElement(document, rectExtrusion.Id, transPoint1); } else { throw new Exception("Create new Extrusion failed."); } ts.Commit(); } } else { throw new Exception("Please open a Family document."); } return(rectExtrusion); }
private static Element createNextElement(Document doc, Element prevElem, string elemFamType, string sizeParName, double sizeInMm, bool rotateOnSingleConDirection = false) { Cons prevElemCons = mp.GetConnectors(prevElem); FamilySymbol familySymbol = fi.GetElements <FamilySymbol, BuiltInParameter> (doc, BuiltInParameter.SYMBOL_FAMILY_AND_TYPE_NAMES_PARAM, elemFamType).FirstOrDefault(); if (familySymbol == null) { throw new Exception(elemFamType + " not found!"); } //The strange symbol activation thingie... //See: http://thebuildingcoder.typepad.com/blog/2014/08/activate-your-family-symbol-before-using-it.html if (!familySymbol.IsActive) { familySymbol.Activate(); doc.Regenerate(); } //Create family instance Element elem = doc.Create.NewFamilyInstance(prevElemCons.Secondary.Origin, familySymbol, StructuralType.NonStructural); doc.Regenerate(); //Set size Parameter sizeParameter = elem.LookupParameter(sizeParName); sizeParameter.Set(sizeInMm.MmToFt()); doc.Regenerate(); //Rotate the element Cons elemCons = mp.GetConnectors(elem); if (rotateOnSingleConDirection) { RotateElementInPosition(prevElemCons.Secondary.Origin, elemCons.Primary, prevElemCons.Secondary, elem); } else { RotateElementInPosition(prevElemCons.Secondary.Origin, elemCons.Primary, prevElemCons.Secondary, prevElemCons.Primary, elem); } //Move in position ElementTransformUtils.MoveElement(doc, elem.Id, prevElemCons.Secondary.Origin - elemCons.Primary.Origin); return(elem); }