public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var app = commandData.Application.Application; var uiDoc = commandData.Application.ActiveUIDocument; var doc = commandData.Application.ActiveUIDocument.Document; var view = doc.ActiveView; VLTransactionHelper.DelegateTransaction(doc, "扩展存储", () => { //ExtensibleStorageHelperV1.Test(doc); return(true); }); VLTransactionHelper.DelegateTransaction(doc, "文件存储", () => { return(true); }); VLTransactionHelper.DelegateTransaction(doc, "日志系统", () => { return(true); }); return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var app = commandData.Application.Application; var uiDoc = commandData.Application.ActiveUIDocument; var doc = commandData.Application.ActiveUIDocument.Document; var view = doc.ActiveView; var storageEntity = new TestStorageEntity(); var d1 = ExtensibleStorageHelperV2.GetData(doc, storageEntity, storageEntity.FieldStr); VLTransactionHelper.DelegateTransaction(doc, "扩展存储", () => { ExtensibleStorageHelperV2.SetData(doc, storageEntity, storageEntity.FieldStr, "666"); var element = doc.Delete(new ElementId(197387)); return(true); }); var d2 = ExtensibleStorageHelperV2.GetData(doc, storageEntity, storageEntity.FieldStr); VLTransactionHelper.DelegateTransaction(doc, "扩展存储", () => { ExtensibleStorageHelperV2.SetData(doc, storageEntity, storageEntity.FieldStr, "777"); return(true); }); var d3 = ExtensibleStorageHelperV2.GetData(doc, storageEntity, storageEntity.FieldStr); return(Result.Succeeded); }
/// <summary> /// 加载族文件 /// </summary> public bool LoadFamilySymbols(Document doc, bool needTransaction) { if (needTransaction) { if (!VLTransactionHelper.DelegateTransaction(doc, "多管标注生成", () => { SingleTagSymbol = LoadFamilySymbol(doc, @"E:\WorkingSpace\Tasks\0609管道标注\管道尺寸标记.rfa", "管道尺寸标记", "管道尺寸标记", BuiltInCategory.OST_PipeTags); MultipleTagSymbol = LoadFamilySymbol(doc, @"E:\WorkingSpace\Tasks\0609管道标注\多管直径标注.rfa", "多管直径标注", "引线标注_文字在右端", BuiltInCategory.OST_DetailComponents); return(true); })) { return(false); } } else { SingleTagSymbol = LoadFamilySymbol(doc, @"E:\WorkingSpace\Tasks\0609管道标注\管道尺寸标记.rfa", "管道尺寸标记", "管道尺寸标记", BuiltInCategory.OST_PipeTags); MultipleTagSymbol = LoadFamilySymbol(doc, @"E:\WorkingSpace\Tasks\0609管道标注\多管直径标注.rfa", "多管直径标注", "引线标注_文字在右端", BuiltInCategory.OST_DetailComponents); } var familyDoc = doc.EditFamily(SingleTagSymbol.Family); var textElement = new FilteredElementCollector(familyDoc).OfClass(typeof(TextElement)).First(c => c.Name == "2.5") as TextElement; var textSizeStr = textElement.Symbol.get_Parameter(BuiltInParameter.TEXT_SIZE).AsValueString(); TextSize = double.Parse(textSizeStr.Substring(0, textSizeStr.IndexOf(" mm"))); WidthScale = double.Parse(textElement.Symbol.get_Parameter(BuiltInParameter.TEXT_WIDTH_SCALE).AsValueString()); return(true); }
private bool GetFamilySymbolInfo(ElementId targetId) { FamilySymbol annotationFamily = null; if (!VLTransactionHelper.DelegateTransaction(Document, "GetFamilySymbolInfo", (Func <bool>)(() => { annotationFamily = Model.GetAnnotationFamily(Document); return(annotationFamily != null); }))) { return(false); } //准备族内参数 if (!PBPAContext.FontManagement.IsCurrentFontSettled) { var familyDoc = Document.EditFamily(annotationFamily.Family); var textElement = new FilteredElementCollector(familyDoc).OfClass(typeof(TextElement)).First(c => c.Name == "3mm") as TextElement; var textElementType = textElement.Symbol as TextElementType; #if Revit2016 PBPAContext.FontManagement.SetCurrentFont(textElementType, 1, 1.2); #elif Revit2017 PBPAContext.FontManagement.SetCurrentFont(textElementType, 1, 1.55); #else PBPAContext.FontManagement.SetCurrentFont(textElementType, 1, 1.6); #endif } return(true); }
public override void Execute() { var viewType = (AnalysisViewType)Enum.Parse(typeof(AnalysisViewType), ViewType.ToString()); switch (viewType) { case AnalysisViewType.Idle: View = new AnalysisWindow(this); View.ShowDialog(); break; case AnalysisViewType.Close: View.Close(); break; case AnalysisViewType.DisplayGeometry: View.Close(); if (!VLHookHelper.DelegateKeyBoardHook(() => { Model.TargetId = UIDocument.Selection.PickObject(ObjectType.Element, "请选择对象").ElementId; })) { Model.TargetId = null; ViewType = (int)AnalysisViewType.Idle; } if (VLTransactionHelper.DelegateTransaction(Document, "DisplayGeometry", () => { if (Model.TargetId == null) { return(false); } if (string.IsNullOrEmpty(RootPath)) { MessageHelper.TaskDialogShow("根路径不能为空"); return(false); } Model.Document = Document; Model.RootPath = RootPath; Model.DisplayName = ViewType.ToString(); Model.DisplayGeometry(); AnalysisContext.SaveCollection(Document); return(true); })) { ViewType = (int)AnalysisViewType.DisplayGeometry; } else { ViewType = (int)AnalysisViewType.Idle; } Execute(); break; default: throw new NotImplementedException("功能未实现"); } }
public AnalysisViewModel(UIApplication app) : base(app) { VLTransactionHelper.DelegateTransaction(Document, "AnalysisContext", (() => { Model = AnalysisContext.GetCollection(Document); return(true); })); View = new AnalysisWindow(this); ////用以打开时更新页面 //AnnotationType = AnalysisAnnotationType.SPL; //LocationType = AnalysisLocationType.Center; }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var app = commandData.Application.Application; var uiDoc = commandData.Application.ActiveUIDocument; var doc = commandData.Application.ActiveUIDocument.Document; List <ElementId> elementIds = new List <ElementId>(); VLHookHelper.DelegateMouseHook(() => { elementIds = uiDoc.Selection.PickObjects(ObjectType.Element, new VLClassesFilter(false, typeof(Pipe), typeof(Duct), typeof(CableTray), typeof(Conduit) ), "选择要添加的构件").Select(c => c.ElementId).ToList(); }); if (elementIds == null || elementIds.Count() < 2) { return(Result.Failed); } var selectedElements = elementIds.Select(c => doc.GetElement(c)).ToList(); AvoidElementManager manager = new AvoidElementManager(uiApp); manager.AddElements(selectedElements); VLTransactionHelper.DelegateTransaction(doc, "调研_单点避让", () => { manager.CheckConflict(); manager.AutoAvoid(doc); return(true); }); VLTransactionHelper.DelegateTransaction(doc, "调研_单点避让", () => { var result = string.Join(",", manager.ConnectionNodes.Select(c => c.MEPCurve1.Id + "->" + c.MEPCurve2.Id)); var service = new MEPCurveConnectControlService(uiApp); foreach (var ConnectionNode in manager.ConnectionNodes) { try { service.NewTwoFitting(ConnectionNode.MEPCurve1, ConnectionNode.MEPCurve2, null); doc.Regenerate(); } catch (System.Exception ex) { VLLogHelper.Error(string.Format("Node1:{0},Node2:{1},Error:{2}", ConnectionNode.MEPCurve1.Id, ConnectionNode.MEPCurve2.Id, ex.Message)); var error = ex.ToString(); } } return(true); }); return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var app = commandData.Application.Application; var uiDoc = commandData.Application.ActiveUIDocument; var doc = commandData.Application.ActiveUIDocument.Document; var view = doc.ActiveView; if (view.ViewType != ViewType.FloorPlan && view.ViewType != ViewType.Elevation) { PmSoft.Common.Controls.PMMessageBox.Show("需选择二维视图或者图纸"); return(Result.Cancelled); } //TODO0817 增加功能面板启动时获取字体高度 VLTransactionHelper.DelegateTransaction(doc, "获取字体高度", () => { PAContext.LoadFamilySymbols(doc); return(true); }); PAContext.LoadTextHeight(doc); PipeAnnotationForm form = new PipeAnnotationForm(new PipeAnnotationCmd(uiApp)); System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.Retry; while ((result = form.ShowDialog()) == System.Windows.Forms.DialogResult.Retry) { switch (form.ActionType) { case ActionType.SelectSinglePipe: var selectedId = uiDoc.Selection.PickObject(ObjectType.Element, new PipeFramingFilter()).ElementId; form.SelectedElementIds.Clear(); form.SelectedElementIds.Add(selectedId); form.FinishSelection(); break; case ActionType.SelectMultiplePipe: var selectedIds = uiDoc.Selection.PickObjects(ObjectType.Element, new PipeFramingFilter()).Select(c => c.ElementId); form.SelectedElementIds.Clear(); form.SelectedElementIds.AddRange(selectedIds); form.FinishSelection(); break; default: break; } } return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var app = commandData.Application.Application; var uiDoc = commandData.Application.ActiveUIDocument; var doc = commandData.Application.ActiveUIDocument.Document; var view = doc.ActiveView; var storageEntity = new TestStorageEntity(); //var s = "S1"; ////事务1+事务2 是整体回退还是回退事务2? ////回退是事务型回退,事务2被回退了 Data=S1 //TransactionHelper.DelegateTransaction(doc, "扩展存储", () => //{ // var d1 = ExtensibleStorageHelperV2.GetData(doc, storageEntity, storageEntity.FieldStr); // ExtensibleStorageHelperV2.SetData(doc, storageEntity, storageEntity.FieldStr, s); // return true; //}); VLTransactionHelper.DelegateTransaction(doc, "扩展存储", () => { //var d2 = ExtensibleStorageHelperV2.GetData(doc, storageEntity, storageEntity.FieldStr); //var d2 = ExtensibleStorageHelperV2.GetData(doc, storageEntity, storageEntity.FieldNames2, storageEntity.FieldStr); ExtensibleStorageHelperV2.SetData(doc, storageEntity, storageEntity.FieldStr, "123"); ////s += "S2"; ////ExtensibleStorageHelperV2.SetData(doc, storageEntity, storageEntity.FieldStr, s); //var schema = ExtensibleStorageHelperV2.GetSchema(storageEntity.SchemaId, storageEntity.SchemaName, storageEntity.FieldNames2); //var storage = ExtensibleStorageHelperV2.GetOrCreateStorage(doc, storageEntity.StorageName); //Entity entity; //if (storage == null) //{ // storage = ExtensibleStorageHelperV2.CreateStorage(doc, storageEntity.StorageName); // entity = new Entity(schema); // entity.Set<string>(schema.GetField(storageEntity.FieldStr), ""); // storage.SetEntity(entity); //} //entity = storage.GetEntity(schema); //if (entity.IsValid()) //{ // var data = entity.Get<string>(schema.GetField(storageEntity.FieldStr)); //} return(true); }); var d3 = ExtensibleStorageHelperV2.GetData(doc, storageEntity, storageEntity.FieldStr); return(Result.Succeeded); }
public bool Prepare() { if (!VLTransactionHelper.DelegateTransaction(Document, "PBPAViewModel", (Func <bool>)(() => { //添加共享参数 var parameterHelper = new MyRevit.Utilities.ShareParameter(VLSharedParameterHelper.GetShareFilePath()); parameterHelper.AddShadeParameter(Document, PBPAContext.SharedParameterGroupName, PBPAContext.SharedParameterPL, Document.Settings.Categories.get_Item(BuiltInCategory.OST_PipeAccessory), true, BuiltInParameterGroup.PG_TEXT); return(true); }))) { ShowMessage("加载功能所需的共享参数失败"); return(false); } return(true); }
private void SaveSetting() { VLTransactionHelper.DelegateTransaction(Document, "Close", (Func <bool>)(() => { Setting.TargetType_BranchPipe = TargetType_BranchPipe; Setting.TargetType_Punch = TargetType_Punch; Setting.AnnotationType = AnnotationType; Setting.LocationType = LocationType; Setting.BottomPrefix = BottomPrefix; Setting.CenterPrefix = CenterPrefix; Setting.TopPrefix = TopPrefix; PBPAContext.SaveSetting(Document); return(true); })); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var app = commandData.Application.Application; var uiDoc = commandData.Application.ActiveUIDocument; var doc = commandData.Application.ActiveUIDocument.Document; var view = doc.ActiveView; VLTransactionHelper.DelegateTransaction(doc, "扩展存储", () => { var storageEntity = new TestStorageEntity(); var data = ExtensibleStorageHelperV2.GetData(doc, storageEntity, storageEntity.FieldStr); TaskDialogShow(data); return(true); }); return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { #region Recorder验证 ////Recorder验证 发现使用了doc的全文件路径则功能失效 //var recorder = new FaceRecorderForRevit( "Xia", ApplicationPath.GetCurrentPath(doc)); //var value = recorder.GetValue("Xia1", "", 10); //recorder.WriteValue("Xia1","111"); #endregion var uiApp = commandData.Application; var app = commandData.Application.Application; var uiDoc = commandData.Application.ActiveUIDocument; var doc = commandData.Application.ActiveUIDocument.Document; var view = doc.ActiveView; if (view.ViewType != ViewType.FloorPlan && view.ViewType != ViewType.Elevation && view.ViewType != ViewType.DrawingSheet && view.ViewType != ViewType.CeilingPlan && view.ViewType != ViewType.Section && view.ViewType != ViewType.Detail && view.ViewType != ViewType.DraftingView && view.ViewType != ViewType.EngineeringPlan) { PmSoft.Common.Controls.PMMessageBox.Show("需选择二维视图或者图纸"); return(Result.Cancelled); } if (false) { var selectedId = uiDoc.Selection.PickObject(ObjectType.Element, new PipeFilter()).ElementId; FamilySymbol tagSymbol = null; VLTransactionHelper.DelegateTransaction(doc, "加载族", () => { //查找族类型 string tagName = "管道尺寸标记"; var symbols = new FilteredElementCollector(doc) .WherePasses(new ElementCategoryFilter(BuiltInCategory.OST_PipeTags)) .WherePasses(new ElementClassFilter(typeof(FamilySymbol))); var targetSymbol = symbols.FirstOrDefault(c => (c as FamilySymbol).FamilyName == tagName); if (targetSymbol != null) { tagSymbol = targetSymbol as FamilySymbol; } //空时加载族类型 if (tagSymbol == null) { var symbolFile = @"E:\WorkingSpace\Tasks\0609管道标注\管道尺寸标记.rfa"; Family family; if (doc.LoadFamily(symbolFile, out family)) { //获取族类型集合Id var familySymbolIds = family.GetFamilySymbolIds(); foreach (var familySymbolId in familySymbolIds) { var element = doc.GetElement(familySymbolId) as FamilySymbol; if (element != null && element.FamilyName == tagName) { tagSymbol = element; break; } } } else { TaskDialogShow("加载族文件失败"); } } return(true); }); if (tagSymbol == null) { return(Result.Failed); } VLTransactionHelper.DelegateTransaction(doc, "选择使用的标注", () => { //TODO return(true); }); VLTransactionHelper.DelegateTransaction(doc, "文字位于管道", () => { var pipe = doc.GetElement(selectedId); var locationCurve = (pipe.Location as LocationCurve).Curve; var midPoint = (locationCurve.GetEndPoint(0) + locationCurve.GetEndPoint(1)) / 2; var tag = doc.Create.NewTag(view, pipe, false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, midPoint); return(true); }); VLTransactionHelper.DelegateTransaction(doc, "文字位于管道上方", () => { double length = 8; var pipe = doc.GetElement(selectedId); var locationCurve = (pipe.Location as LocationCurve).Curve; var midPoint = (locationCurve.GetEndPoint(0) + locationCurve.GetEndPoint(1)) / 2; var parallelVector = (locationCurve as Line).Direction; var verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0); if (verticalVector.Y < 0 || (verticalVector.Y == 0 && verticalVector.X == -1))//控制到一二象限 { verticalVector = new XYZ(-verticalVector.X, -verticalVector.Y, verticalVector.Z); } var tag = doc.Create.NewTag(view, pipe, false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, midPoint + length * verticalVector); return(true); }); VLTransactionHelper.DelegateTransaction(doc, "引线", () => { double length = 5; bool needLeader = true; var pipe = doc.GetElement(selectedId); var locationCurve = (pipe.Location as LocationCurve).Curve; var midPoint = (locationCurve.GetEndPoint(0) + locationCurve.GetEndPoint(1)) / 2; var parallelVector = (locationCurve as Line).Direction; var verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0); if (verticalVector.Y < 0 || (verticalVector.Y == 0 && verticalVector.X == -1)) { verticalVector = new XYZ(-verticalVector.X, -verticalVector.Y, verticalVector.Z); } var tag = doc.Create.NewTag(view, pipe, needLeader, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, midPoint + length * verticalVector); return(true); }); VLTransactionHelper.DelegateTransaction(doc, "标记距离管道边缘5mm", () => { double length = 5; bool needLeader = false; var pipe = doc.GetElement(selectedId); var locationCurve = (pipe.Location as LocationCurve).Curve; var midPoint = (locationCurve.GetEndPoint(0) + locationCurve.GetEndPoint(1)) / 2; var parallelVector = (locationCurve as Line).Direction; var verticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0); if (verticalVector.Y < 0 || (verticalVector.Y == 0 && verticalVector.X == -1)) { verticalVector = new XYZ(-verticalVector.X, -verticalVector.Y, verticalVector.Z); } var tag = doc.Create.NewTag(view, pipe, needLeader, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, midPoint + length * verticalVector); return(true); }); } if (false) { VLTransactionHelper.DelegateTransaction(doc, "一键标注", () => { //可以通过Tag的TaggedLocalElelemtId获取其对应的对象 //Tag是属于某View的 var pipesWithTag = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_PipeTags); pipesWithTag = pipesWithTag.WhereElementIsNotElementType(); var tagIds = pipesWithTag.Where(c => c.OwnerViewId == view.Id) .Select(c => (c as IndependentTag).TaggedLocalElementId).ToList().Distinct(); var pipes = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_PipeCurves); pipes = pipes.WhereElementIsNotElementType(); foreach (var pipe in pipes) { if (!tagIds.Contains(pipe.Id)) { var locationCurve = (pipe.Location as LocationCurve).Curve; var midPoint = (locationCurve.GetEndPoint(0) + locationCurve.GetEndPoint(1)) / 2; var tag = doc.Create.NewTag(view, pipe, false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, midPoint); } } return(true); }); } generateOnLineEdge = !generateOnLineEdge; var selectedIds = uiDoc.Selection.PickObjects(ObjectType.Element, new PipeFilter()); AnnotationCreater builder = new AnnotationCreater(); var result = builder.LoadFamilySymbols(doc, true); if (result) { result = VLTransactionHelper.DelegateTransaction(doc, "多管标注生成", () => { switch (builder.GenerateMultipleTagSymbol(doc, selectedIds.Select(c => c.ElementId), generateOnLineEdge ? MultiPipeTagLocation.OnLine : MultiPipeTagLocation.OnLineEdge)) { case AnnotationBuildResult.Success: return(true); case AnnotationBuildResult.NotParallel: case AnnotationBuildResult.NoLocationType: default: return(false); } }); } //if (!generateOnLineEdge) //{ // generateOnLineEdge = true; // var selectedIds = uiDoc.Selection.PickObjects(ObjectType.Element, new PipeFilter()); // AnnotationCreater creator = new AnnotationCreater(); // if (creator.LoadFamilySymbols(doc)) // { // switch (creator.GenerateMultipleTagSymbol(doc, selectedIds, MultiPipeTagLocation.OnLine)) // { // case AnnotationBuildResult.Success: // return Result.Succeeded; // case AnnotationBuildResult.NotParallel: // case AnnotationBuildResult.NoLocationType: // default: // return Result.Failed; // } // } //} VLTransactionHelper.DelegateTransaction(doc, "多管-一键标注", () => { return(true); }); VLTransactionHelper.DelegateTransaction(doc, "多管-包括链接进来的管道", () => { return(true); }); VLTransactionHelper.DelegateTransaction(doc, "多管-标注自动避让", () => { return(true); }); VLTransactionHelper.DelegateTransaction(doc, "修改标高的基面", () => { return(true); }); return(Result.Succeeded); }
public override void Execute() { var viewType = (CSAViewType)Enum.Parse(typeof(CSAViewType), ViewType.ToString()); switch (viewType) { case CSAViewType.Idle: View = new CompoundStructureAnnotationWindow(this); IntPtr rvtPtr = Autodesk.Windows.ComponentManager.ApplicationWindow; WindowInteropHelper helper = new WindowInteropHelper(View); helper.Owner = rvtPtr; View.ShowDialog(); break; case CSAViewType.Select: if (View.IsActive) { View.Close(); } using (PmSoft.Common.RevitClass.PickObjectsMouseHook MouseHook = new PmSoft.Common.RevitClass.PickObjectsMouseHook()) { MouseHook.InstallHook(PmSoft.Common.RevitClass.PickObjectsMouseHook.OKModeENUM.Objects); try { Model.TargetId = UIDocument.Selection.PickObject(ObjectType.Element , new VLClassesFilter(false, typeof(Wall), typeof(Floor), typeof(ExtrusionRoof), typeof(FootPrintRoof))).ElementId; MouseHook.UninstallHook(); ViewType = (int)CSAViewType.Generate; } catch (Exception ex) { MouseHook.UninstallHook(); ViewType = (int)CSAViewType.Idle; } } break; case CSAViewType.Generate: var doc = UIDocument.Document; if (VLTransactionHelper.DelegateTransaction(doc, "生成结构标注", () => { var element = doc.GetElement(Model.TargetId); var Collection = CSAContext.GetCollection(doc); //避免重复生成 由于一个对象可能在不同的视图中进行标注设置 所以还是需要重复生成的 var existedModel = Collection.Data.FirstOrDefault(c => c.TargetId.IntegerValue == Model.TargetId.IntegerValue); if (existedModel != null) { Collection.Data.Remove(existedModel); CSAContext.Creator.Clear(doc, existedModel); } var fontScale = 1 / VLConstraintsForCSA.OrientFontSizeScale * Model.CurrentFontSizeScale; Model.LineWidth = UnitHelper.ConvertToFoot(Model.CSALocationType.GetLineWidth() * fontScale, VLUnitType.millimeter); CSAContext.Creator.Generate(doc, Model, element); Collection.Data.Add(Model); Collection.Save(doc); return(true); })) { ViewType = (int)CSAViewType.Select; } else { ViewType = (int)CSAViewType.Idle; } break; case CSAViewType.Close: View.Close(); break; case CSAViewType.Closing: default: break; } }
public override void Execute() { var viewType = (MATViewType)Enum.Parse(typeof(MATViewType), ViewType.ToString()); switch (viewType) { case MATViewType.Idle: View = new MATWindow(this); View.ShowDialog(); break; case MATViewType.Close: View.Close(); //SaveSetting(); break; case MATViewType.Closing: //SaveSetting(); break; case MATViewType.PickSinglePipe_Pipe: View.Close(); if (!VLHookHelper.DelegateKeyBoardHook(() => { //业务逻辑处理 //选择符合类型的过滤 var targetType = Model.GetFilter(); Model.TargetIds = new List <ElementId>() { UIDocument.Selection.PickObject(ObjectType.Element, targetType, "请选择管道标注点").ElementId }; if (Model.TargetIds.Count > 0) { ViewType = (int)MATViewType.PickSinglePipe_Location; } })) { ViewType = (int)MATViewType.Idle; } Execute(); break; case MATViewType.PickSinglePipe_Location: if (!VLHookHelper.DelegateKeyBoardHook(() => { ////业务逻辑处理 //var target = Document.GetElement(Model.TargetIds.First()); //var targetLocation = target.Location as LocationCurve; //var p0 = targetLocation.Curve.GetEndPoint(0); //var p1 = targetLocation.Curve.GetEndPoint(1); //var pStart = new XYZ((p0.X + p1.X) / 2, (p0.Y + p1.Y) / 2, (p0.Z + p1.Z) / 2); //var pEnd = new VLPointPicker().PickPointWithLinePreview(UIApplication, pStart); //if (pEnd == null) // ViewType = MATViewType.Idle; //else // ViewType = MATViewType.GenerateSinglePipe; })) { ViewType = (int)MATViewType.Idle; } Execute(); break; case MATViewType.GenerateSinglePipe: if (VLTransactionHelper.DelegateTransaction(Document, "GenerateSinglePipe", (Func <bool>)(() => { var element = Document.GetElement(Model.TargetIds.First()); var Collection = MATContext.GetCollection(Document); //避免重复生成 由于一个对象可能在不同的视图中进行标注设置 所以还是需要重复生成的 var existedModels = Collection.Data.Where(c => c.TargetIds.Intersect(Model.TargetIds, new VLElementIdComparer()) != null); if (existedModels != null) { foreach (var existedModel in existedModels) { Collection.Data.Remove(existedModel); MATContext.Creator.Clear(Document, existedModel); } } MATContext.Creator.Generate(Document, Model, element); Collection.Data.Add(Model); Collection.Save(Document); return(true); }))) { ViewType = (int)MATViewType.PickSinglePipe_Pipe; } else { ViewType = (int)MATViewType.Idle; } Execute(); break; default: throw new NotImplementedException("功能未实现"); } }
public void UpdateDifference(Document doc, PBPASetting origin, bool needUserConfirm = true) { bool IsPunchUpdate = origin.TargetType_Punch; bool IsBranchPipeUpdate = origin.TargetType_BranchPipe; CheckDifference(origin); if (!IsSame) { if (!needUserConfirm || VLViewModel.ShowQuestion("前缀发生变化,是否更新所对应的标签") == DialogResult.OK) { SettingTextMemo = origin.CloneText(); VLTransactionHelper.DelegateTransaction(doc, "RegenerateAllFor_L", (Func <bool>)(() => { var collection = PBPAContext.GetCollection(doc); if (!IsSame_CenterPrefix) { if (IsPunchUpdate) { var targetType = PBPATargetType.Punch; var locationType = PBPALocationType.Center; RegenerateAllFor_Prefix(doc, collection, targetType, locationType); } if (IsBranchPipeUpdate) { var targetType = PBPATargetType.BranchPipe; var locationType = PBPALocationType.Center; RegenerateAllFor_Prefix(doc, collection, targetType, locationType); } } if (!IsSame_TopPrefix) { if (IsPunchUpdate) { var targetType = PBPATargetType.Punch; var locationType = PBPALocationType.Top; RegenerateAllFor_Prefix(doc, collection, targetType, locationType); } if (IsBranchPipeUpdate) { var targetType = PBPATargetType.BranchPipe; var locationType = PBPALocationType.Top; RegenerateAllFor_Prefix(doc, collection, targetType, locationType); } } if (!IsSame_BottomPrefix) { if (IsPunchUpdate) { var targetType = PBPATargetType.Punch; var locationType = PBPALocationType.Bottom; RegenerateAllFor_Prefix(doc, collection, targetType, locationType); } if (IsBranchPipeUpdate) { var targetType = PBPATargetType.BranchPipe; var locationType = PBPALocationType.Bottom; RegenerateAllFor_Prefix(doc, collection, targetType, locationType); } } collection.Save(doc); return(true); })); } } IsSame = true; }
public override void Execute() { PBPAModelCollection collection; var viewType = (PBPAViewType)Enum.Parse(typeof(PBPAViewType), ViewType.ToString()); switch (viewType) { case PBPAViewType.Idle: View = new PBPAWindow(this); View.ShowDialog(); break; case PBPAViewType.Close: View.Close(); SaveSetting(); break; case PBPAViewType.Closing: SaveSetting(); break; case PBPAViewType.RegenerateAllFor_L: VLTransactionHelper.DelegateTransaction(Document, "RegenerateAllFor_L", (Func <bool>)(() => { collection = PBPAContext.GetCollection(Document); for (int i = collection.Data.Count - 1; i >= 0; i--) { var model = collection.Data[i]; model.Document = Document; model.IsRegenerate = true; var element = Document.GetElement(model.TargetId); element.GetParameters(PBPAContext.SharedParameterPL).FirstOrDefault().Set(model.GetFull_L(element)); if (!PBPAContext.Creator.Regenerate(model)) { collection.Data.Remove(model); } } collection.Save(Document); return(true); })); ViewType = (int)PBPAViewType.Idle; break; case PBPAViewType.PickSingle_Target: UpdateSetting(); MemoHelper.UpdateDifference(Document, Setting, false); Model.Document = Document; Model.ViewId = Document.ActiveView.Id; View.Close(); if (!VLHookHelper.DelegateKeyBoardHook(() => { //业务逻辑处理 //选择符合类型的过滤 UpdateModelTargetType(); var targetType = Model.GetFilter(); var obj = UIDocument.Selection.PickObject(ObjectType.Element, targetType, "请选择标注点"); if (obj != null) { Model.TargetId = obj.ElementId; Model.TargetType = Model.IsPunch(Document.GetElement(obj.ElementId)) ? PBPATargetType.Punch : PBPATargetType.BranchPipe; ViewType = (int)PBPAViewType.PickSingle_End; Model.BodyStartPoint = obj.GlobalPoint; } })) { ViewType = (int)PBPAViewType.Idle; } //获取族内参数信息 if (!GetFamilySymbolInfo(Model.TargetId)) { ShowMessage("加载族信息失败"); ViewType = (int)PBPAViewType.Idle; Execute(); return; } Model.CurrentFontWidthSize = PBPAContext.FontManagement.CurrentFontWidthSize; Execute(); break; case PBPAViewType.PickSingle_End: //业务逻辑处理 if (!VLHookHelper.DelegateKeyBoardHook(() => { //var locationCurve = (target.Location as LocationCurve).Curve as Line; //XYZ vVector, pVector; //VLLocationHelper.GetVectors(locationCurve, CoordinateType.XY, out vVector, out pVector); #region 平面+立面支持 //CoordinateType coordinateType; //coordinateType = VLLocationHelper.GetCoordinateType(Document); //Model.CoordinateType = coordinateType; //var hVector = coordinateType.GetParallelVector(); //hVector = VLLocationHelper.GetVectorByQuadrant(hVector, QuadrantType.OneAndFour, coordinateType); //var vVector = VLLocationHelper.GetVerticalVector(hVector); //vVector = VLLocationHelper.GetVectorByQuadrant(vVector, QuadrantType.OneAndFour, coordinateType); #endregion VLCoordinateType coordinateType = VLCoordinateType.XY; Model.UpdateVector(coordinateType); var target = Document.GetElement(Model.TargetId); Model.UpdateLineWidth(target); var startPoint = Model.BodyStartPoint.ToWindowsPoint(coordinateType); var offSet = (Model.LineWidth * Model.ParallelVector).ToWindowsPoint(); //var endPoint = (Model.BodyStartPoint + Model.LineWidth * 1.02 * Model.ParallelVector).ToWindowsPoint(coordinateType); var pEnd = new VLPointPicker().PickPointWithPreview(UIApplication, coordinateType, (view) => { var mousePosition = System.Windows.Forms.Control.MousePosition; var midDrawP = new System.Windows.Point(mousePosition.X - view.Left, mousePosition.Y - view.Top); //中间选择点 var midPoint = view.ConvertToRevitPointFromDrawPoint(midDrawP); var startDrawP = view.ConvertToDrawPointFromRevitPoint(startPoint); //起点 var M_S = midPoint - Model.BodyStartPoint; if (Model.AnnotationType == PBPAAnnotationType.OneLine || Model.ParallelVector.CrossProductByCoordinateType(M_S, VLCoordinateType.XY) > 0) { var endPoint = startPoint.Plus(offSet); var endP = view.ConvertToDrawPointFromRevitPoint(endPoint); //终点 if (Math.Abs(startDrawP.X - midDrawP.X) < 2 && Math.Abs(startDrawP.Y - midDrawP.Y) < 2) { return; } var mid_s = midDrawP - startDrawP; mid_s.Normalize(); var midSDrawP = midDrawP - mid_s * view.co_s; var height = midDrawP - startDrawP; var endDrawP = endP + height; var mid_e = midDrawP - endDrawP; mid_e.Normalize(); var midEDrawP = midDrawP - mid_e * view.co_e; if (double.IsNaN(midEDrawP.X)) { return; } var canvas = view.canvas; canvas.Children.RemoveRange(0, canvas.Children.Count); var line = new System.Windows.Shapes.Line() { X1 = startDrawP.X, Y1 = startDrawP.Y, X2 = midSDrawP.X, Y2 = midSDrawP.Y, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(136, 136, 136)), StrokeThickness = 1 }; var line2 = new System.Windows.Shapes.Line() { X1 = midEDrawP.X, Y1 = midEDrawP.Y, X2 = endDrawP.X, Y2 = endDrawP.Y, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(136, 136, 136)), StrokeThickness = 1 }; System.Windows.Media.RenderOptions.SetBitmapScalingMode(line, System.Windows.Media.BitmapScalingMode.LowQuality); System.Windows.Media.RenderOptions.SetBitmapScalingMode(line2, System.Windows.Media.BitmapScalingMode.LowQuality); canvas.Children.Add(line); canvas.Children.Add(line2); Model.IsReversed = false; } else { var endPoint = startPoint.Minus(offSet); var endP = view.ConvertToDrawPointFromRevitPoint(endPoint); //终点 if (Math.Abs(startDrawP.X - midDrawP.X) < 2 && Math.Abs(startDrawP.Y - midDrawP.Y) < 2) { return; } var mid_s = midDrawP - startDrawP; mid_s.Normalize(); var midSDrawP = midDrawP - mid_s * view.co_s; var height = midDrawP - startDrawP; var endDrawP = endP + height; var mid_e = midDrawP - endDrawP; mid_e.Normalize(); var midEDrawP = midDrawP - mid_e * view.co_e; if (double.IsNaN(midEDrawP.X)) { return; } var canvas = view.canvas; canvas.Children.RemoveRange(0, canvas.Children.Count); var line = new System.Windows.Shapes.Line() { X1 = startDrawP.X, Y1 = startDrawP.Y, X2 = midSDrawP.X, Y2 = midSDrawP.Y, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(136, 136, 136)), StrokeThickness = 1 }; var line2 = new System.Windows.Shapes.Line() { X1 = midEDrawP.X, Y1 = midEDrawP.Y, X2 = endDrawP.X, Y2 = endDrawP.Y, Stroke = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(136, 136, 136)), StrokeThickness = 1 }; System.Windows.Media.RenderOptions.SetBitmapScalingMode(line, System.Windows.Media.BitmapScalingMode.LowQuality); System.Windows.Media.RenderOptions.SetBitmapScalingMode(line2, System.Windows.Media.BitmapScalingMode.LowQuality); canvas.Children.Add(line); canvas.Children.Add(line2); Model.IsReversed = true; } }); if (pEnd == null) { ViewType = (int)PBPAViewType.Idle; } else { Model.BodyEndPoint = pEnd.ToSame(Model.BodyStartPoint, coordinateType); ViewType = (int)PBPAViewType.GenerateSingle; } })) { ViewType = (int)PBPAViewType.Idle; } Execute(); break; case PBPAViewType.GenerateSingle: //生成处理 if (VLTransactionHelper.DelegateTransaction(Document, "GenerateSingle", (Func <bool>)(() => { #region 生成处理 collection = PBPAContext.GetCollection(Document); var existedModels = collection.Data.Where(c => Model.TargetId == c.TargetId).ToList(); //避免重复生成 if (existedModels != null) { for (int i = existedModels.Count() - 1; i >= 0; i--) { existedModels[i].Document = Document; collection.Data.Remove(existedModels[i]); existedModels[i].Clear(); } } if (!PBPAContext.Creator.Generate(Model)) { return(false); } collection.Data.Add(Model); collection.Save(Document); #endregion #region 共享参数设置 var element = Document.GetElement(Model.TargetId); element.GetParameters(PBPAContext.SharedParameterPL).FirstOrDefault().Set(Model.GetFull_L(element)); #endregion return(true); }))) { ViewType = (int)PBPAViewType.PickSingle_Target; } else { ViewType = (int)PBPAViewType.Idle; } Execute(); break; case PBPAViewType.GenerateAll: default: throw new NotImplementedException("功能未实现"); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var app = commandData.Application.Application; var uiDoc = commandData.Application.ActiveUIDocument; var doc = commandData.Application.ActiveUIDocument.Document; if (selectedId == null) { selectedId = uiDoc.Selection.PickObject(ObjectType.Element, new BeamFramingFilter()).ElementId; } string tagName = "梁平法_集中标_左对齐"; FamilySymbol tagSymbol = null; VLTransactionHelper.DelegateTransaction(doc, "加载族", () => { #region 加载族 //查找族类型 var symbols = new FilteredElementCollector(doc) .WherePasses(new ElementCategoryFilter(BuiltInCategory.OST_StructuralFramingTags)) .WherePasses(new ElementClassFilter(typeof(FamilySymbol))); var targetSymbol = symbols.FirstOrDefault(c => (c as FamilySymbol).FamilyName == tagName); if (targetSymbol != null) { tagSymbol = targetSymbol as FamilySymbol; } //空时加载族类型 if (tagSymbol == null) { var symbolFile = @"E:\WorkingSpace\Tasks\0526标注\梁平法_集中标_左对齐.rfa"; Family family; if (doc.LoadFamily(symbolFile, out family)) { //获取族类型集合Id var familySymbolIds = family.GetFamilySymbolIds(); foreach (var familySymbolId in familySymbolIds) { var e = doc.GetElement(familySymbolId) as FamilySymbol; if (e != null && e.FamilyName == tagName) { tagSymbol = e; break; } } } else { TaskDialogShow("加载族文件失败"); } } #endregion if (tagSymbol == null) { return(false); } #region 参数赋值 //如果上述两者获取到了对应的族 var view = doc.ActiveView; var element = doc.GetElement(selectedId); //参数赋值 BeamAnnotationData.LoadConfig(doc); var beamParameterNames = Enum.GetNames(typeof(BeamAnnotationParameters)); var parameter = element.GetParameters(nameof(BeamAnnotationParameters.梁名称)).FirstOrDefault(); if (parameter == null) { string shareFilePath = @"E:\WorkingSpace\Tasks\0526标注\标注_共享参数(全).txt"; var parameterHelper = new Utilities.ShareParameter(shareFilePath); foreach (var beamParameterName in beamParameterNames) { if (new List <string>() { nameof(BeamAnnotationParameters.梁名称) , nameof(BeamAnnotationParameters.箍筋直径) } .Contains(beamParameterName)) { AddSharedParameterByDefaulGroupName(doc, shareFilePath, BeamAnnotationParameterGroupName, beamParameterName, element.Category, true, Autodesk.Revit.DB.BuiltInParameterGroup.PG_TEXT); } //parameterHelper.AddShadeParameter(doc, shareFilePath, BeamAnnotationParameterGroupName, beamParameterName, element.Category, false, Autodesk.Revit.DB.BuiltInParameterGroup.PG_TEXT); else if (new List <string>() { nameof(BeamAnnotationParameters.梁宽) , nameof(BeamAnnotationParameters.梁高) } .Contains(beamParameterName)) { AddSharedParameterByDefaulGroupName(doc, shareFilePath, BeamAnnotationParameterGroupName, beamParameterName, element.Category, false, Autodesk.Revit.DB.BuiltInParameterGroup.PG_GEOMETRY); } //parameterHelper.AddShadeParameter(doc, BeamAnnotationParameterGroupName, beamParameterName, element.Category, true, Autodesk.Revit.DB.BuiltInParameterGroup.PG_GEOMETRY); else { AddSharedParameterByDefaulGroupName(doc, shareFilePath, BeamAnnotationParameterGroupName, beamParameterName, element.Category, true, Autodesk.Revit.DB.BuiltInParameterGroup.INVALID); } //parameterHelper.AddShadeParameter(doc, BeamAnnotationParameterGroupName, beamParameterName, element.Category, false, Autodesk.Revit.DB.BuiltInParameterGroup.INVALID); } } //参数赋值 element.GetParameters(nameof(BeamAnnotationParameters.梁名称)).FirstOrDefault().Set(BeamAnnotationData.BeamName); element.GetParameters(nameof(BeamAnnotationParameters.梁加腋)).FirstOrDefault().Set(BeamAnnotationData.BeamHaunching); element.GetParameters(nameof(BeamAnnotationParameters.梁加腋可见性)).FirstOrDefault().Set(Convert.ToInt32(BeamAnnotationData.BeamHaunchingVisibility)); element.GetParameters(nameof(BeamAnnotationParameters.梁箍筋)).FirstOrDefault().Set(BeamAnnotationData.Hooping); element.GetParameters(nameof(BeamAnnotationParameters.箍筋直径)).FirstOrDefault().Set(BeamAnnotationData.HoopingDiameter); element.GetParameters(nameof(BeamAnnotationParameters.梁纵筋)).FirstOrDefault().Set(BeamAnnotationData.LongitudinalBar); element.GetParameters(nameof(BeamAnnotationParameters.纵筋级别)).FirstOrDefault().Set(BeamAnnotationData.LongitudinalBarLevel); element.GetParameters(nameof(BeamAnnotationParameters.梁腰筋)).FirstOrDefault().Set(BeamAnnotationData.WaistBar); element.GetParameters(nameof(BeamAnnotationParameters.腰筋级别)).FirstOrDefault().Set(BeamAnnotationData.WaistBarLevel); element.GetParameters(nameof(BeamAnnotationParameters.梁顶绝对标高)).FirstOrDefault().Set(BeamAnnotationData.BeamAbsoluteTop); element.GetParameters(nameof(BeamAnnotationParameters.梁顶相对偏移)).FirstOrDefault().Set(BeamAnnotationData.BeamRelationalSkew); var symbol = (element as FamilyInstance).Symbol; symbol.GetParameters(nameof(BeamAnnotationParameters.梁宽)).FirstOrDefault().Set(BeamAnnotationData.BeamWidth); symbol.GetParameters(nameof(BeamAnnotationParameters.梁高)).FirstOrDefault().Set(BeamAnnotationData.BeamHeight); var familyDoc = doc.EditFamily(symbol.Family); #endregion #region 绘图处理 //绘图处理 double parallelLength = BeamAnnotationConstaints.parallelLength; int vecticalLength = BeamAnnotationConstaints.vecticalLength; int standardLength = BeamAnnotationConstaints.standardLength; string relatedLineField = BeamAnnotationConstaints.relatedLineField; string relatedTagField = BeamAnnotationConstaints.relatedTagField; string relatedBeamField = BeamAnnotationConstaints.relatedBeamField; string relatedViewField = BeamAnnotationConstaints.relatedViewField; view = doc.ActiveView; var beam = doc.GetElement(selectedId); //中点出线 var locationCurve = (beam.Location as LocationCurve).Curve; var midPoint = (locationCurve.GetEndPoint(0) + locationCurve.GetEndPoint(1)) / 2; var parallelVector = (locationCurve as Line).Direction; if (parallelVector.X < 0 || (parallelVector.X == 0 && parallelVector.Y == -1)) { parallelVector = new XYZ(-parallelVector.X, -parallelVector.Y, parallelVector.Z); } var vecticalVector = new XYZ(parallelVector.Y, -parallelVector.X, 0); var line = doc.Create.NewDetailCurve(view, Line.CreateBound(midPoint, midPoint + standardLength * vecticalVector)); //中点绘字 var tag1 = doc.Create.NewTag(view, beam, false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, midPoint); //确定长宽 var targetPoint = (locationCurve.GetEndPoint(0) + locationCurve.GetEndPoint(1)) / 2 + parallelLength * parallelVector + vecticalLength * vecticalVector; ////删除中点绘字 doc.Delete(tag1.Id); //综合移动 var tag2 = doc.Create.NewTag(view, beam, false, TagMode.TM_ADDBY_CATEGORY, TagOrientation.Horizontal, targetPoint); //关系存储 var collection = MyTestContext.GetCollection(doc); collection.Add(new BeamAnnotationEntity(view.Id.IntegerValue, beam.Id.IntegerValue, line.Id.IntegerValue, tag2.Id.IntegerValue)); MyTestContext.SaveCollection(doc); #endregion return(true); }); return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Hello World //TaskDialog.Show("VL title", "VL says Hello Revit"); var uiApp = commandData.Application; var app = commandData.Application.Application; var uiDoc = commandData.Application.ActiveUIDocument; var doc = commandData.Application.ActiveUIDocument.Document; #region 放置类型为"0762*2032 mm"的门 //首先通过类型过滤出 类型为门的族类型,找到名称相同的 string doorTypeName = "0762*2032 mm"; FamilySymbol doorType = null; var filter = new LogicalAndFilter( new ElementCategoryFilter(BuiltInCategory.OST_Doors), new ElementClassFilter(typeof(FamilySymbol)) ); var collector = new FilteredElementCollector(doc).WherePasses(filter); bool symbolFound = collector.FirstOrDefault(c => c.Name == doorTypeName) != null; //如果没有则通过文件加载族 if (symbolFound) { doorType = collector.FirstOrDefault(c => c.Name == doorTypeName) as FamilySymbol; } else { string file = @"familyFilePath"; Family family; if (doc.LoadFamily(file, out family)) { var validType = family.GetValidTypes().FirstOrDefault(c => { var symbol = (doc.GetElement(c) as FamilySymbol); if (symbol != null && symbol.Name == doorTypeName) { return(true); } return(false); }); if (validType != null) { doorType = doc.GetElement(validType) as FamilySymbol; symbolFound = true; } } } //使用族类型创建门 线性的门是有着LocationCurve的且LocationCurve.Curve为Line的元素 Wall wall = null; if (doorType != null) { Element element = new FilteredElementCollector(doc) .WherePasses(new ElementClassFilter(typeof(Wall))) .FirstOrDefault(c => { var locationCurve = c.Location as LocationCurve; if (locationCurve != null) { var line = locationCurve.Curve as Line; if (line != null) { return(true); } return(false); } return(false); }); if (element != null) { wall = element as Wall; } } //在墙的中心创建一个门 if (wall != null) { var line = (wall.Location as LocationCurve).Curve as Line; var wallLevel = doc.GetElement(wall.LevelId) as Level; XYZ midPoint = (line.GetEndPoint(0) + line.GetEndPoint(1)) / 2; var structureType = Autodesk.Revit.DB.Structure.StructuralType.NonStructural; FamilyInstance door = doc.Create.NewFamilyInstance(midPoint, doorType, wall, wallLevel, structureType); } #endregion #region 制墙类型 var wallElementId = 1111; wall = doc.GetElement(new ElementId(wallElementId)) as Wall; if (wall != null) { var wallType = wall.WallType; ElementType duplicatedType = wallType.Duplicate(wall.Name + "duplicated"); } #endregion #region 元素移动 VLTransactionHelper.DelegateTransaction(doc, "创建一根柱子", () => { //Revit文档的创建句柄 Autodesk.Revit.Creation.Document creator = doc.Create; XYZ origin = new XYZ(0, 0, 0); Level level = doc.GetElement(new ElementId(12122)) as Level; FamilySymbol columnType = doc.GetElement(new ElementId(12123)) as FamilySymbol; var structureType = Autodesk.Revit.DB.Structure.StructuralType.Column; FamilyInstance column = creator.NewFamilyInstance(origin, columnType, level, structureType); XYZ newPlace = new XYZ(10, 20, 30); ElementTransformUtils.MoveElement(doc, column.Id, newPlace); return(true); }); #endregion #region ElementTransformUtils //ElementTransformUtils.CopyElement(); //ElementTransformUtils.CopyElements(); //ElementTransformUtils.MirrorElement(); //ElementTransformUtils.MirrorElements(); //ElementTransformUtils.MoveElement(); //ElementTransformUtils.MoveElements(); //ElementTransformUtils.RotateElement(); //ElementTransformUtils.RotateElements(); #endregion #region 元素旋转 VLTransactionHelper.DelegateTransaction(doc, "ElementTransformUtils旋转方法", () => { LocationCurve wallLine = wall.Location as LocationCurve; XYZ p1 = wallLine.Curve.GetEndPoint(0); XYZ p2 = new XYZ(p1.X, p1.Y, 30); Line axis = Line.CreateBound(p1, p2); ElementTransformUtils.RotateElement(doc, wall.Id, axis, Math.PI / 3);//逆时针60° return(true); }); VLTransactionHelper.DelegateTransaction(doc, "LocationCurve,LocationPoint,自带的旋转方法", () => { LocationCurve locationCurve = wall.Location as LocationCurve;//线性坐标自带线 if (locationCurve != null) { Curve curve = locationCurve.Curve; var start = curve.GetEndPoint(0); Line axis = Line.CreateBound(start, start.Add(new XYZ(0, 0, 10))); locationCurve.Rotate(axis, Math.PI);//PI=180° } LocationPoint locationPoint = wall.Location as LocationPoint; if (locationPoint != null) { var start = locationPoint.Point; Line axis = Line.CreateBound(start, start.Add(new XYZ(0, 0, 10))); locationPoint.Rotate(axis, Math.PI); } return(true); }); #endregion #region 元素镜像 VLTransactionHelper.DelegateTransaction(doc, "元素镜像", () => { Plane plane = new Plane(XYZ.BasisX, XYZ.Zero); if (ElementTransformUtils.CanMirrorElement(doc, wall.Id)) { ElementTransformUtils.MirrorElement(doc, wall.Id, plane); } return(true); }); #endregion #region 元素删除 //var deleteElements = Document.Delete(@ElementIds); #endregion #region 元素组合 VLTransactionHelper.DelegateTransaction(doc, "元素组合", () => { List <ElementId> elementIds = new List <ElementId>() { new ElementId(1000), new ElementId(1001), new ElementId(1002), }; Group group = doc.Create.NewGroup(elementIds); return(true); }); #endregion #region 元素编辑 VLTransactionHelper.DelegateTransaction(doc, "创建参照平面", () => { XYZ bubbleEnd = new XYZ(0, 5, 5); XYZ freeEnd = new XYZ(5, 5, 5); XYZ cutVector = XYZ.BasisY; View view = doc.ActiveView; ReferencePlane referencePlane = doc.FamilyCreate.NewReferencePlane(bubbleEnd, freeEnd, cutVector, view); referencePlane.Name = "MyReferencePlane"; return(true); }); VLTransactionHelper.DelegateTransaction(doc, "创建参照线,由模型线-转>参照线", () => { ModelCurve modelCurve = doc.GetElement(new ElementId(1000)) as ModelCurve;//ModelCurve模型线 modelCurve.ChangeToReferenceLine(); //modelCurve.IsReferenceLine; return(true); }); VLTransactionHelper.DelegateTransaction(doc, "通过标高创建草图平面,然后在草图平面创建模型线", () => { Level level = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).FirstOrDefault() as Level; Line line = Line.CreateBound(XYZ.Zero, new XYZ(10, 10, 0)); SketchPlane sketchPlane = SketchPlane.Create(doc, level.Id); ModelCurve modelLine = doc.FamilyCreate.NewModelCurve(line, sketchPlane); return(true); }); VLTransactionHelper.DelegateTransaction(doc, "使用拉身体获取相应的草图平面", () => { Extrusion extrusion = doc.GetElement(new ElementId(11212)) as Extrusion; SketchPlane sketchPlane = extrusion.Sketch.SketchPlane; CurveArrArray sketchProfile = extrusion.Sketch.Profile; return(true); }); #endregion #region 族 string tagName = "梁平法_集中标_左对齐"; FamilySymbol tagSymbol = null; //查找族类型 var symbols = new FilteredElementCollector(doc) .WherePasses(new ElementClassFilter(typeof(FamilySymbol))) .WherePasses(new ElementCategoryFilter(BuiltInCategory.OST_StructuralFramingTags)); var targetSymbol = symbols.FirstOrDefault(c => c.Name == tagName); if (targetSymbol != null) { tagSymbol = targetSymbol as FamilySymbol; } //空时加载族类型 if (tagSymbol == null) { var symbolFile = @"E:\WorkingSpace\Tasks\0526标注\梁平法_集中标_左对齐.rfa"; Family family; if (doc.LoadFamily(symbolFile, out family)) { foreach (ElementId typeId in family.GetValidTypes()) { var validType = doc.GetElement(typeId) as FamilySymbol; if (validType != null && validType.Name == tagName) { tagSymbol = validType; break; } } } else { TaskDialogShow("加载族文件失败"); } } //如果上述两者获取到了对应的族 if (tagSymbol != null) { //doc.Create.NewFamilyInstance(, tagSymbol); } #endregion #region 建筑建模 VLTransactionHelper.DelegateTransaction(doc, "修改标高的基面", () => { var levelId = 111; Level level = doc.GetElement(new ElementId(levelId)) as Level; LevelType levelType = doc.GetElement(level.GetTypeId()) as LevelType; return(true); }); #endregion return(Result.Succeeded); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiApp = commandData.Application; var app = commandData.Application.Application; var uiDoc = commandData.Application.ActiveUIDocument; var doc = commandData.Application.ActiveUIDocument.Document; ////链接模板测试 //var linkFilter = new CategoryFilter(BuiltInCategory.OST_Floors, true); //Reference reference = uiDoc.Selection.PickObject(ObjectType.LinkedElement, linkFilter, "先选择一个链接文件"); //Element element = doc.GetElement(reference.ElementId); //if (element.Category.Name != "RVT 链接") // return Result.Cancelled; //var floors = uiDoc.Selection.PickObjects(ObjectType.LinkedElement, linkFilter, "在链接文件中选择板:").ToList(); ////194278 //element = doc.GetElement(new ElementId(194278)); //var linkInstance = doc.GetElement(reference.ElementId) as RevitLinkInstance; //if (linkInstance!=null) //{ // var linkDoc = linkInstance.GetLinkDocument(); // element = linkDoc.GetElement(new ElementId(194278)); //} //MessageHelper.TaskDialogShow("开始选择板"); //业务逻辑处理 VLTransactionHelper.DelegateTransaction(doc, "梁齐板", () => { Document linkDocument = null; IEnumerable <ElementId> floorIds = null; if (model.ContentType == ContentType.Document) { //基础板,OST_StructuralFoundation //结构楼板,OST_Floors floorIds = uiDoc.Selection.PickObjects(ObjectType.Element, new CategoryFilter(BuiltInCategory.OST_Floors), "选择楼板").Select(c => c.ElementId); if (floorIds == null || floorIds.Count() == 0) { return(false); } } else { var linkFilter = new CategoryFilter(BuiltInCategory.OST_Floors, true); Reference reference = uiDoc.Selection.PickObject(ObjectType.LinkedElement, linkFilter, "先选择一个链接文件"); Element element = doc.GetElement(reference.ElementId); if (element.Category.Name != "RVT 链接") { return(false); } linkDocument = (element as RevitLinkInstance).GetLinkDocument(); floorIds = uiDoc.Selection.PickObjects(ObjectType.LinkedElement, linkFilter, "在链接文件中选择板:").Select(c => c.LinkedElementId); model.Offset = (element as Instance).GetTotalTransform().Origin; ////链接元素测试 //foreach (var floor in floors) //{ // var f = doc.GetElement(floor.ElementId); // f = (element as RevitLinkInstance).GetLinkDocument().GetElement(floor.ElementId); //} } //MessageHelper.TaskDialogShow("开始选择梁"); var beamIds = uiDoc.Selection.PickObjects(ObjectType.Element, new CategoryFilter(BuiltInCategory.OST_StructuralFraming), "选择梁").Select(c => c.ElementId); if (beamIds == null || beamIds.Count() == 0) { return(false); } //ValidFaces collector = new ValidFaces(doc, model); ////对板按高程从高到底处理 //List<LevelFloor> levelFloors = new List<LevelFloor>(); //foreach (var floorId in floorIds) //{ // var floor = doc.GetElement(floorId) as Floor; // var level = doc.GetElement(floor.LevelId) as Level; // levelFloors.Add(new LevelFloor(level.Elevation, floor)); //} //List<Line> beamLines = collector.DealAll(null, new List<Line>(), levelFloors); //GraphicsDisplayerManager.Display(collector, levelFloors); #region 0803版本 OutLineManager0802 collector = new OutLineManager0802(doc, model); //对板按高程从高到底处理 List <LevelFloor> levelFloors = new List <LevelFloor>(); foreach (var floorId in floorIds) { if (model.ContentType == ContentType.Document) { var floor = doc.GetElement(floorId) as Floor; var level = doc.GetElement(floor.LevelId) as Level; levelFloors.Add(new LevelFloor(level.Elevation, floor)); } else { collector.LinkDocument = linkDocument; var floor = linkDocument.GetElement(floorId) as Floor; var level = linkDocument.GetElement(floor.LevelId) as Level; levelFloors.Add(new LevelFloor(level.Elevation, floor)); } } //依次对各个梁进行个板面的拆分处理 foreach (var beamId in beamIds) { var beam = doc.GetElement(beamId); var beamSymbol = (beam as FamilyInstance).Symbol; var beamLevel = doc.GetElement(beam.LevelId) as Level; var beamLine = (beam.Location as LocationCurve).Curve as Line; if (beamLine == null) { throw new NotImplementedException("暂不支持曲线梁"); } var start = new XYZ(beamLine.GetEndPoint(0).X, beamLine.GetEndPoint(0).Y, 0); var end = new XYZ(beamLine.GetEndPoint(1).X, beamLine.GetEndPoint(1).Y, 0); var beamLineZ0 = Line.CreateBound(start, end); GraphicsDisplayerManager.Display(collector, levelFloors); List <Line> beamLines = collector.DealAll(beam, new List <Line>() { beamLineZ0 }, levelFloors); //最终未贴合板的梁段生成 foreach (var ungenerateBeamLine in beamLines) { var sp0 = ungenerateBeamLine.GetEndPoint(0); var sp1 = ungenerateBeamLine.GetEndPoint(1); var fixedSP0 = VLGeometryHelper.VL_GetIntersectionOnLine(sp0, beamLine.GetEndPoint(0), beamLine.Direction); var fixedSP1 = VLGeometryHelper.VL_GetIntersectionOnLine(sp1, beamLine.GetEndPoint(0), beamLine.Direction); var sectionBeam = doc.Create.NewFamilyInstance(Line.CreateBound(fixedSP0, fixedSP1), beamSymbol, beamLevel, Autodesk.Revit.DB.Structure.StructuralType.Beam); collector.CreatedBeams.Add(sectionBeam); } collector.LinkBeamWithAngleGT180(beam); doc.Delete(beam.Id); } #endregion #region 0803前 ////添加板 //foreach (var floorId in floorIds) //{ // var floor = doc.GetElement(floorId) as Floor; // collector.Add(floor); //} ////计算梁的偏移处理 //foreach (var beamId in beamIds) //{ // var beam = doc.GetElement(beamId); // var fitLineCollection = collector.Fit(beam); // var seperatePoints = collector.Merge(fitLineCollection, new DirectionPoint((beam.Location as LocationCurve).Curve.GetEndPoint(0), ((beam.Location as LocationCurve).Curve as Line).Direction, false), new DirectionPoint((beam.Location as LocationCurve).Curve.GetEndPoint(1), ((beam.Location as LocationCurve).Curve as Line).Direction, false)); // collector.Adapt(doc, beam, seperatePoints.SeperatedLines); // //绘图分析 // GraphicsDisplayerManager.Display(@"E:\WorkingSpace\Outputs\Images\display2.png", seperatePoints, collector.LeveledOutLines); //} #endregion return(true); }); //model.ContentType = model.ContentType == ContentType.Document ? ContentType.LinkDocument : ContentType.Document; return(Result.Succeeded); }