| | |
| | | using Autodesk.Revit.DB; |
| | | using Autodesk.Revit.DB.Plumbing; |
| | | using Autodesk.Revit.UI; |
| | | using HStation.RevitDev.RevitDataExport.Service; |
| | | using HStation.RevitDev.RevitDataExport.Utility; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Windows; |
| | | |
| | | namespace HStation.RevitDev.RevitDataExport.Entity |
| | | { |
| | | public class ExternalEvent_CreateInstance : IExternalEventHandler |
| | | { |
| | | ExternalEvent m_createInstanceMonitor = null; |
| | | ExternalEvent_CloseInstanceMonitor m_closeInstanceMonitor = null; |
| | | |
| | | public string RfaPath { get; set; } = null; |
| | | |
| | | public void Execute(UIApplication app) |
| | | { |
| | | if (app == null || RfaPath == null || !File.Exists(RfaPath)) { return; } |
| | | |
| | | UIDocument uiDoc = app.ActiveUIDocument; |
| | | Document doc = uiDoc.Document; |
| | | Family family = null; |
| | | FamilySymbol symbol = null; |
| | | |
| | | LoadFamilyFile(doc, ref family, ref symbol); |
| | | if (family == null || symbol == null) { return; } |
| | | |
| | | PlacementFamilyInstance(uiDoc, symbol); |
| | | m_closeInstanceMonitor = new ExternalEvent_CloseInstanceMonitor(); |
| | | m_createInstanceMonitor = ExternalEvent.Create(m_closeInstanceMonitor); |
| | | m_createInstanceMonitor.Raise(); |
| | | } |
| | | |
| | | private static void PlacementFamilyInstance(UIDocument uiDoc, FamilySymbol symbol) |
| | | { |
| | | if (uiDoc.CanPlaceElementType(symbol)) |
| | | { |
| | | try |
| | | { |
| | | uiDoc.PromptForFamilyInstancePlacement(symbol, new PromptForFamilyInstancePlacementOptions()); |
| | | } |
| | | catch (Autodesk.Revit.Exceptions.OperationCanceledException e) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | MessageBox.Show("无法放置此类族!"); |
| | | } |
| | | } |
| | | |
| | | private void LoadFamilyFile(Document doc, ref Family family, ref FamilySymbol symbol) |
| | | { |
| | | using (Transaction trans = new Transaction(doc, "创建族实例")) |
| | | { |
| | | trans.Start(); |
| | | try |
| | | { |
| | | if (!doc.LoadFamily(RfaPath, new FamilyLoadOption(), out family)) |
| | | { |
| | | //说明文档中已经存在, 需要搜索整个文档 |
| | | var elems = SearchService.SearchElements(doc, typeof(Family), Path.GetFileNameWithoutExtension(RfaPath)); |
| | | if (elems != null && elems.Count > 0) |
| | | { |
| | | family = elems[0] as Family; |
| | | } |
| | | } |
| | | if (family == null) |
| | | { |
| | | trans.Commit(); |
| | | return; |
| | | } |
| | | |
| | | var symbolId = family.GetFamilySymbolIds().FirstOrDefault(); |
| | | symbol = doc.GetElement(symbolId) as FamilySymbol; |
| | | if (symbol == null) |
| | | { |
| | | trans.Commit(); |
| | | return; |
| | | } |
| | | symbol.Activate(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | } |
| | | trans.Commit(); |
| | | } |
| | | } |
| | | |
| | | public string GetName() |
| | | { |
| | | return "Create Family Instance"; |
| | | } |
| | | } |
| | | |
| | | public class ExternalEvent_CreatePipe : IExternalEventHandler |
| | | { |
| | | UIApplication m_app = null; |
| | | |
| | | public void Execute(UIApplication app) |
| | | { |
| | | m_app = app; |
| | | PipeUpdater updater = new PipeUpdater(Common.GlobalResource.UpdaterGuid); |
| | | updater.Register(); |
| | | |
| | | RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.Pipe); |
| | | if (m_app.CanPostCommand(id)) |
| | | { |
| | | m_app.PostCommand(id); |
| | | } |
| | | } |
| | | |
| | | public string GetName() |
| | | { |
| | | return "Create Pipe"; |
| | | } |
| | | } |
| | | |
| | | public class ExternalEvent_ClosePipeMonitor : IExternalEventHandler |
| | | { |
| | | public void Execute(UIApplication app) |
| | | { |
| | | Common.GlobalResource.PipePlacing = false; |
| | | PipeUpdater updater = new PipeUpdater(Common.GlobalResource.UpdaterGuid); |
| | | updater.RemoveRegister(); |
| | | } |
| | | |
| | | public string GetName() |
| | | { |
| | | return "Create Pipe"; |
| | | } |
| | | } |
| | | |
| | | public class ExternalEvent_CloseInstanceMonitor : IExternalEventHandler |
| | | { |
| | | public void Execute(UIApplication app) |
| | | { |
| | | Common.GlobalResource.InstancePlacing = false; |
| | | } |
| | | |
| | | public string GetName() |
| | | { |
| | | return "CloseInstanceMonitor"; |
| | | } |
| | | } |
| | | } |
| | | using Autodesk.Revit.DB;
|
| | | using Autodesk.Revit.UI;
|
| | | using HStation.RevitDev.RevitDataExport.Common;
|
| | | using HStation.RevitDev.RevitDataExport.Service;
|
| | | using System;
|
| | | using System.IO;
|
| | | using System.Linq;
|
| | | using System.Windows;
|
| | |
|
| | | namespace HStation.RevitDev.RevitDataExport.Entity
|
| | | {
|
| | | public class ExternalEvent_CreateInstance : IExternalEventHandler
|
| | | {
|
| | | public string RfaPath { get; set; } = null;
|
| | |
|
| | | private bool m_isFirstTrigger = true;
|
| | |
|
| | | private UIApplication m_app = null;
|
| | |
|
| | | public void Execute(UIApplication app)
|
| | | {
|
| | | if (app == null || RfaPath == null || !File.Exists(RfaPath)) { return; }
|
| | | m_app = app;
|
| | | m_app.Idling += App_Idling;
|
| | | UIDocument uiDoc = app.ActiveUIDocument;
|
| | | Document doc = uiDoc.Document;
|
| | | Family family = null;
|
| | | FamilySymbol symbol = null;
|
| | |
|
| | | LoadFamilyFile(doc, ref family, ref symbol);
|
| | | if (family == null || symbol == null) { return; }
|
| | |
|
| | | PlacementFamilyInstance(uiDoc, symbol);
|
| | | }
|
| | |
|
| | | private void App_Idling(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e)
|
| | | {
|
| | | if (m_isFirstTrigger)
|
| | | {
|
| | | m_isFirstTrigger = false;
|
| | | }
|
| | | else
|
| | | {
|
| | | GlobalResource.InstancePlacing = false;
|
| | | m_app.Idling -= App_Idling;
|
| | | m_isFirstTrigger = true;
|
| | | }
|
| | | }
|
| | |
|
| | | private static void PlacementFamilyInstance(UIDocument uiDoc, FamilySymbol symbol)
|
| | | {
|
| | | if (uiDoc.CanPlaceElementType(symbol))
|
| | | {
|
| | | try
|
| | | {
|
| | | uiDoc.PromptForFamilyInstancePlacement(symbol, new PromptForFamilyInstancePlacementOptions());
|
| | | }
|
| | | catch (Autodesk.Revit.Exceptions.OperationCanceledException e)
|
| | | {
|
| | | return;
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | MessageBox.Show("无法放置此类族!");
|
| | | }
|
| | | }
|
| | |
|
| | | private void LoadFamilyFile(Document doc, ref Family family, ref FamilySymbol symbol)
|
| | | {
|
| | | using (Transaction trans = new Transaction(doc, "创建族实例"))
|
| | | {
|
| | | trans.Start();
|
| | | try
|
| | | {
|
| | | if (!doc.LoadFamily(RfaPath, new FamilyLoadOption(), out family))
|
| | | {
|
| | | //说明文档中已经存在, 需要搜索整个文档
|
| | | var elems = SearchService.SearchElements(doc, typeof(Family), Path.GetFileNameWithoutExtension(RfaPath));
|
| | | if (elems != null && elems.Count > 0)
|
| | | {
|
| | | family = elems[0] as Family;
|
| | | }
|
| | | }
|
| | | if (family == null)
|
| | | {
|
| | | trans.Commit();
|
| | | return;
|
| | | }
|
| | |
|
| | | var symbolId = family.GetFamilySymbolIds().FirstOrDefault();
|
| | | symbol = doc.GetElement(symbolId) as FamilySymbol;
|
| | | if (symbol == null)
|
| | | {
|
| | | trans.Commit();
|
| | | return;
|
| | | }
|
| | | symbol.Activate();
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | |
|
| | | }
|
| | | trans.Commit();
|
| | | }
|
| | | }
|
| | |
|
| | | public string GetName()
|
| | | {
|
| | | return "Create Family Instance";
|
| | | }
|
| | | }
|
| | |
|
| | | public class ExternalEvent_CreatePipe : IExternalEventHandler
|
| | | {
|
| | | UIApplication m_app = null;
|
| | | bool m_isFirstTrigger = true;
|
| | |
|
| | | public void Execute(UIApplication app)
|
| | | {
|
| | | m_app = app;
|
| | | app.Idling += App_Idling;
|
| | |
|
| | | RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.Pipe);
|
| | | if (m_app.CanPostCommand(id))
|
| | | {
|
| | | m_app.PostCommand(id);
|
| | | }
|
| | | }
|
| | |
|
| | | private void App_Idling(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e)
|
| | | {
|
| | | if (m_isFirstTrigger)
|
| | | {
|
| | | m_isFirstTrigger = false;
|
| | | }
|
| | | else
|
| | | {
|
| | | GlobalResource.PipePlacing = false;
|
| | | m_app.Idling -= App_Idling;
|
| | | m_isFirstTrigger = true;
|
| | | }
|
| | | }
|
| | |
|
| | | public string GetName()
|
| | | {
|
| | | return "Create Pipe";
|
| | | }
|
| | | }
|
| | | }
|