revit二次开发里用LocationPoint和point移动

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using Autodesk.Revit.UI;using Autodesk.Revit.DB;using Autodesk.Revit.UI.Selection;using Autodesk.Revit.ApplicationServices;namespace 移动族到指定位置{ [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)] [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)] public class Class1 : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { Document revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档 Application revitApp = commandData.Application.Application; //取得应用程序 UIDocument uiDoc = commandData.Application.ActiveUIDocument; Selection sel = uiDoc.Selection; Reference ref1 = sel.PickObject(ObjectType.Element, "选择一个族实例"); Element elem = revitDoc.GetElement(ref1); FamilyInstance familyInstance = elem as FamilyInstance; using (Transaction transaction = new Transaction(revitDoc)) { transaction.Start("主题"); //在下面添加主要代码内容 //把选择的元素移到(0,0,0)点 XYZ newlocation = new XYZ(0, 0, 0); MoveToAnyPlace(familyInstance, newlocation); ElementTransformUtils.CopyElement(uiDoc.Document, uiDoc.Document.GetElement(ref1).Id, new XYZ(5000/304.8, 0, 0)); transaction.Commit(); } return Result.Succeeded; } //方法:移到任意位置,newLocation表示移到的目标位置 private void MoveToAnyPlace(FamilyInstance familyInstance, XYZ newlocation) { if (null!= familyInstance) { LocationPoint famliyInstancePoint = familyInstance.Location as LocationPoint; famliyInstancePoint.Point = newlocation; } } }}

你可能感兴趣的:(revit二次开发)