1. 程式人生 > >revit二次開發裡用LocationPoint和point移動

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; } } }}