/// <summary> /// Add and register the sever on Revit startup. /// </summary> public ExternalDBApplicationResult OnStartup(ControlledApplication application) { ExternalService plumbingFixtureService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.PipePlumbingFixtureFlowService); Pipe.PlumbingFixtureFlowServer flowServer = new Pipe.PlumbingFixtureFlowServer(); if (plumbingFixtureService != null) { plumbingFixtureService.AddServer(flowServer); } ExternalService pipePressureDropService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.PipePressureDropService); Pipe.PipePressureDropServer pressureDropServer = new Pipe.PipePressureDropServer(); if (pipePressureDropService != null) { pipePressureDropService.AddServer(pressureDropServer); } ExternalService ductPressureDropService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.DuctPressureDropService); Duct.DuctPressureDropServer ductPressureDropServer = new Duct.DuctPressureDropServer(); if (ductPressureDropService != null) { ductPressureDropService.AddServer(ductPressureDropServer); } return(ExternalDBApplicationResult.Succeeded); }
/// <summary> /// Use this method to report any problems that occurred while the user was browsing for External Resources. /// Revit will call this method each time the end user browses to a new folder location, or selects an item /// and clicks Open. /// </summary> public void HandleBrowseResult(ExternalResourceUIBrowseResultType resultType, string browsingItemPath) { if (resultType == ExternalResourceUIBrowseResultType.Success) { return; } String resultString = resultType.ToString("g"); // While executing its SetupBrowserData() method, the "DB server" - SampleExternalResourceServer - can store // detailed information about browse failures that occurred (user not logged in, network down, etc.). // Subsequently, when Revit calls this method, the details can be read from the DB server and reported to the user. ExternalService externalResourceService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.ExternalResourceService); if (externalResourceService == null) { System.Windows.Forms.MessageBox.Show("External Resource Service unexpectedly not found."); return; } SampleExternalResourceDBServer myDBServer = externalResourceService.GetServer(GetDBServerId()) as SampleExternalResourceDBServer; if (myDBServer == null) { System.Windows.Forms.MessageBox.Show("Cannot get SampleExternalResourceDBServer from ExternalResourceService."); return; } // ... Retrieve detailed failure information from SampleExternalResourceServer here. String message = String.Format("The browse result for <{0}> was: <{1}>.", browsingItemPath, resultString); System.Windows.Forms.MessageBox.Show(message); }
/// <summary> /// Same as AddRevitElementServer(), but for multiple elements. /// </summary> /// <param name="uidoc"></param> public void AddMultipleRevitElementServers(UIDocument uidoc) { IList <Reference> references = uidoc.Selection.PickObjects(ObjectType.Element, "Select elements to duplicate with DirectContext3D"); ExternalService directContext3DService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.DirectContext3DService); MultiServerService msDirectContext3DService = directContext3DService as MultiServerService; IList <Guid> serverIds = msDirectContext3DService.GetActiveServerIds(); // Create one server per element. foreach (Reference reference in references) { Element elem = uidoc.Document.GetElement(reference); RevitElementDrawingServer revitServer = new RevitElementDrawingServer(uidoc, elem, m_offset); directContext3DService.AddServer(revitServer); m_servers.Add(revitServer); serverIds.Add(revitServer.GetServerId()); } msDirectContext3DService.SetActiveServers(serverIds); m_documents.Add(uidoc.Document); uidoc.UpdateAllOpenViews(); }
static void Start() { objectPreviews = new Dictionary <Guid, DocumentPreviewServer>(); using (var service = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.DirectContext3DService) as MultiServerService) { var activeServerIds = service.GetActiveServerIds(); foreach (var o in ActiveDocument.Objects) { if (!ObjectPrimitive.IsSupportedObject(o, true)) { continue; } var preview = new DocumentPreviewServer(o); var serverId = preview.GetServerId(); objectPreviews.Add(serverId, preview); service.AddServer(preview); activeServerIds.Add(serverId); } service.SetActiveServers(activeServerIds); } Revit.RefreshActiveView(); }
/// <summary> /// Add and register the server on Revit startup. /// </summary> public Result OnStartup(UIControlledApplication application) { MultiServerService ductService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.DuctFittingAndAccessoryPressureDropUIService) as MultiServerService; if (ductService == null) { return(Result.Succeeded); } Duct.CoefficientFromTablePressureDropUIServer UserTableUIServer = new Duct.CoefficientFromTablePressureDropUIServer(); ductService.AddServer(UserTableUIServer); //pipe UI servers MultiServerService pipeService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.PipeFittingAndAccessoryPressureDropUIService) as MultiServerService; if (pipeService == null) { return(Result.Succeeded); } Pipe.KFactorTablePipePressureDropUIServer pipeKFactorUIServer = new Pipe.KFactorTablePipePressureDropUIServer(); pipeService.AddServer(pipeKFactorUIServer); return(Result.Succeeded); }
/// <summary> /// Cleans up by unregistering the servers corresponding to the specified document, /// or all servers if the document is not provided. /// </summary> /// <param name="document">The document whose servers should be removed, or null.</param> /// <param name="updateViews">Update views of the affected document(s).</param> private static void unregisterServers(Document document, string _addinId, bool updateViews) { ExternalServiceId externalDrawerServiceId = ExternalServices.BuiltInExternalServices.DirectContext3DService; var externalDrawerService = ExternalServiceRegistry.GetService(externalDrawerServiceId) as MultiServerService; if (externalDrawerService == null) { return; } foreach (var registeredServerId in externalDrawerService.GetRegisteredServerIds()) { var server = externalDrawerService.GetServer(registeredServerId) as GeometryDrawServer; if (server == null) { continue; } if (!sameDoc(document, server) || !sameAddin(_addinId, server)) { continue; } externalDrawerService.RemoveServer(registeredServerId); } Servers.RemoveAll(server => sameAddin(_addinId, server) && sameDoc(document, server)); if (updateViews) { UIDocument uidoc = APP.UIApp.ActiveUIDocument; if (uidoc != null) { uidoc.UpdateAllOpenViews(); } } }
private void AddDuctFittingAndAccessoryPressureDropServers() { MultiServerService service = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.DuctFittingAndAccessoryPressureDropService) as MultiServerService; if (service == null) { return; } List <Guid> activeServerIds = new List <Guid>(); // User table server is the default server, and it's already set to active, so it should be set active again. Duct.UserTableDuctPressureDropServer UserTableServer = new Duct.UserTableDuctPressureDropServer(); if (UserTableServer != null) { service.AddServer(UserTableServer); activeServerIds.Add(UserTableServer.GetServerId()); } IList <Guid> currentActiveServerIds = service.GetActiveServerIds(); // currentActiveServerIds.Remove(service.GetDefaultServerId()); activeServerIds.AddRange(currentActiveServerIds); service.SetActiveServers(activeServerIds); }
virtual public void Unregister() { using (var service = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.DirectContext3DService) as MultiServerService) { var activeServerIds = service.GetActiveServerIds(); activeServerIds.Remove(GetServerId()); service.SetActiveServers(activeServerIds); service.RemoveServer(GetServerId()); } }
/// <summary> /// Cleans up by unregistering the servers corresponding to the specified document, or all servers if the document is not provided. /// </summary> /// <param name="document">The document whose servers should be removed, or null.</param> /// <param name="updateViews">Update views of the affected document(s).</param> public void unregisterServers(Document document, bool updateViews) { ExternalServiceId externalDrawerServiceId = ExternalServices.BuiltInExternalServices.DirectContext3DService; var externalDrawerService = ExternalServiceRegistry.GetService(externalDrawerServiceId) as MultiServerService; if (externalDrawerService == null) { return; } foreach (var registeredServerId in externalDrawerService.GetRegisteredServerIds()) { var externalDrawServer = externalDrawerService.GetServer(registeredServerId) as RevitElementDrawingServer; if (externalDrawServer == null) { continue; } if (document != null && !document.Equals(externalDrawServer.Document)) { continue; } externalDrawerService.RemoveServer(registeredServerId); } if (document != null) { m_servers.RemoveAll(server => document.Equals(server.Document)); if (updateViews) { UIDocument uidoc = new UIDocument(document); uidoc.UpdateAllOpenViews(); } m_documents.Remove(document); } else { m_servers.Clear(); if (updateViews) { foreach (var doc in m_documents) { UIDocument uidoc = new UIDocument(doc); uidoc.UpdateAllOpenViews(); } } m_documents.Clear(); } }
/// <summary> /// The action taken on application initialization. /// </summary> /// <param name="sender">The sender.</param> /// <param name="eventArgs">The event args.</param> private void OnApplicationInitialized(object sender, EventArgs eventArgs) { SingleServerService service = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.IFCImporterService) as SingleServerService; if (service != null) { Importer importer = new Importer(); service.AddServer(importer); service.SetActiveServer(importer.GetServerId()); } else { throw new InvalidOperationException("Failed to get IFC importer service."); } }
/// <summary> /// Registers an instance of a SampleExternalResourceUIServer with the ExternalService /// of type ExternalResourceUIService. /// </summary> /// <param name="application">An object that is passed to the external application /// which contains the controlled application.</param> /// <returns>Return the status of the external application. A result of Succeeded /// means that the external application was able to register the IExternalResourceUIServer. /// </returns> public Result OnStartup(UIControlledApplication application) { ExternalService externalResourceUIService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.ExternalResourceUIService); if (externalResourceUIService == null) { return(Result.Failed); } // Create an instance of your IExternalResourceUIServer and register it with the ExternalResourceUIService. IExternalResourceUIServer sampleUIServer = new SampleExternalResourceUIServer(); externalResourceUIService.AddServer(sampleUIServer); return(Result.Succeeded); }
private void ApplicationInitialized(object sender, ApplicationInitializedEventArgs e) { // Register the IFC Entity selection server SingleServerService entUIService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.IFCEntityTreeUIService) as SingleServerService; if (entUIService != null) { try { IFCEntityTree.BrowseIFCEntityServer browseIFCEntityServer = new IFCEntityTree.BrowseIFCEntityServer(); entUIService.AddServer(browseIFCEntityServer); entUIService.SetActiveServer(browseIFCEntityServer.GetServerId()); } catch {} } }
/// <summary> /// Unregister this server. Will check if is registered before proceed. /// </summary> /// <param name="_server"></param> public static void UnregisterServer(GeometryDrawServer _server) { ExternalServiceId externalDrawerServiceId = ExternalServices.BuiltInExternalServices.DirectContext3DService; var externalDrawerService = ExternalServiceRegistry.GetService(externalDrawerServiceId) as MultiServerService; if (externalDrawerService == null) { return; } else { var id = _server.GetServerId(); if (externalDrawerService.IsRegisteredServerId(id)) { externalDrawerService.RemoveServer(id); } } }
private void OnApplicationInitialized(object sender, EventArgs e) { // https://www.autodesk.com/autodesk-university/class/DirectContext3D-API-Displaying-External-Graphics-Revit-2017 var service = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.DirectContext3DService) as MultiServerService; if (service != null) { HyparLogger.Debug("Registering the hypar service for drawing..."); var hyparServer = new HyparDirectContextServer(HyparLogger); service.AddServer(hyparServer); var active = service.GetActiveServerIds(); active.Add(hyparServer.GetServerId()); service.SetActiveServers(active); } else { HyparLogger.Debug("Could not find the Direct3DContextService."); } }
/// <summary> /// Implements the OnStartup event /// /// </summary> /// <param name="application"></param> /// <returns></returns> public Result OnStartup(UIControlledApplication application) { // Register CurveElement updater with revit to trigger regen in rebar for selected lines CurveElementRegenUpdater updater = new CurveElementRegenUpdater(application.ActiveAddInId); UpdaterRegistry.RegisterUpdater(updater); ElementClassFilter modelLineFilter = new ElementClassFilter(typeof(CurveElement)); UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), modelLineFilter, Element.GetChangeTypeAny()); //Register the RebarUpdateServer ExternalService service = ExternalServiceRegistry.GetService(m_server.GetServiceId()); if (service != null) { service.AddServer(m_server); return(Result.Succeeded); } return(Result.Succeeded); }
public ExternalDBApplicationResult OnStartup(Autodesk.Revit.ApplicationServices.ControlledApplication application) { try { ExternalService externalResourceService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.ExternalResourceService); if (externalResourceService == null) { return(ExternalDBApplicationResult.Failed); } IExternalResourceServer keynoteServer = new KeynoteServer(application); externalResourceService.AddServer(keynoteServer); return(ExternalDBApplicationResult.Succeeded); } catch (Exception ex) { string message = ex.Message; } return(ExternalDBApplicationResult.Succeeded); }
static void Stop() { using (var service = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.DirectContext3DService) as MultiServerService) { var activeServerIds = service.GetActiveServerIds(); foreach (var preview in objectPreviews) { activeServerIds.Remove(preview.Key); } service.SetActiveServers(activeServerIds); foreach (var preview in objectPreviews) { service.RemoveServer(preview.Key); preview.Value.ClearPrimitives(); } } objectPreviews = null; Revit.RefreshActiveView(); }
/// <summary> /// Register server to Revit external service registry. /// Will check if same server already registered. /// Can only be called from valid API context. /// </summary> /// <param name="server"></param> public static void RegisterServer(GeometryDrawServer server) { ExternalService directContext3DService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.DirectContext3DService); if (directContext3DService.IsRegisteredServerId(server.GetServerId())) { return; } directContext3DService.AddServer(server); Servers.Add(server); MultiServerService msDirectContext3DService = directContext3DService as MultiServerService; IList <Guid> serverIds = msDirectContext3DService.GetActiveServerIds(); serverIds.Add(server.GetServerId()); // Add the new server to the list of active servers. msDirectContext3DService.SetActiveServers(serverIds); }
private void AddPipeFittingAndAccessoryPressureDropServers() { MultiServerService service = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.PipeFittingAndAccessoryPressureDropService) as MultiServerService; if (service == null) { return; } List <Guid> activeServerIds = new List <Guid>(); Pipe.UserKFactorTablePipePressureDropServer kFactorTablePipeServer = new Pipe.UserKFactorTablePipePressureDropServer(); if (kFactorTablePipeServer != null) { service.AddServer(kFactorTablePipeServer); } activeServerIds.AddRange(service.GetActiveServerIds()); service.SetActiveServers(activeServerIds); }
/// <summary> /// Picks a Revit element and creates a corresponding DirectContext3D server that will draw the element's graphics at a fixed offset from the original location. /// </summary> /// <param name="uidoc"></param> public void AddRevitElementServer(UIDocument uidoc) { Reference reference = uidoc.Selection.PickObject(ObjectType.Element, "Select an element to duplicate with DirectContext3D"); Element elem = uidoc.Document.GetElement(reference); // Create the server and register it with the DirectContext3D service. ExternalService directContext3DService = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.DirectContext3DService); RevitElementDrawingServer revitServer = new RevitElementDrawingServer(uidoc, elem, m_offset); directContext3DService.AddServer(revitServer); m_servers.Add(revitServer); MultiServerService msDirectContext3DService = directContext3DService as MultiServerService; IList <Guid> serverIds = msDirectContext3DService.GetActiveServerIds(); serverIds.Add(revitServer.GetServerId()); // Add the new server to the list of active servers. msDirectContext3DService.SetActiveServers(serverIds); m_documents.Add(uidoc.Document); uidoc.UpdateAllOpenViews(); }
private bool getFittingInfo(MEPSection section, DataTable fittingTB, bool forHTML = false) { if (fittingTB == null || section == null) { return(false); } PressureLossReportHelper helper = PressureLossReportHelper.instance; if (helper == null || helper.ReportData == null) { return(false); } List <string> fittingFields = new List <string>(); if (helper.ReportData.FittingFields != null) { getFields(fittingFields); } if (forHTML) { helper.addColumns(fittingTB, fittingFields.Count); } else { helper.addColumns(fittingTB, fittingFields.Count + 2); } List <FamilyInstance> fittings = new List <FamilyInstance>(); SectionsInfo.getSectionElements(section, null, fittings, null, null); if (fittings.Count < 1) { return(false); } int nIndex = 0; foreach (FamilyInstance fitting in fittings) { List <string> paramVals = new List <string>(); if (!forHTML) { if (nIndex == 0) { paramVals.Add(section.Number.ToString()); } else { paramVals.Add(" "); } } foreach (string fieldName in fittingFields) { try { PressureLossParameter PLParam = helper.getPressureLossParamByName(helper.ReportData.FittingFields, fieldName); if (PLParam == null) { continue; } string strVal = ReportConstants.emptyValue; if ((PLParam.GetFrom & (int)SectionMemberType.Section) > 0) { strVal = SectionsInfo.getSectionInfoByParamName(section, fieldName, PLParam.GetFrom, fitting.Id); } else if ((PLParam.GetFrom & (int)SectionMemberType.Fitting) > 0) { if (helper.Domain == ReportResource.pipeDomain && fieldName == LabelUtils.GetLabelFor(BuiltInParameter.RBS_PIPE_FITTING_LOSS_METHOD_SERVER_PARAM)) { string strValGUID = fitting.get_Parameter(fieldName).AsString(); Guid serverGUID = new Guid(strValGUID); //convert the GUID to server name //get the service first, and then get the server MultiServerService service = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.PipeFittingAndAccessoryPressureDropService) as MultiServerService; if (service != null && serverGUID != null) { IExternalServer server = service.GetServer(new Guid(strValGUID)); if (server != null) { strVal = server.GetName(); } } } else if (helper.Domain == ReportResource.ductDomain && fieldName == LabelUtils.GetLabelFor(BuiltInParameter.RBS_DUCT_FITTING_LOSS_METHOD_SERVER_PARAM)) { string strValGUID = fitting.get_Parameter(fieldName).AsString(); Guid serverGUID = new Guid(strValGUID); //convert the GUID to server name //get the service first, and then get the server MultiServerService service = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.DuctFittingAndAccessoryPressureDropService) as MultiServerService; if (service != null && serverGUID != null) { IExternalServer server = service.GetServer(new Guid(strValGUID)); if (server != null) { strVal = server.GetName(); } } } else if (fieldName == ReportResource.elementId) { strVal = fitting.Id.ToString(); } else { strVal = helper.getParamValue(fitting.get_Parameter(fieldName)); } } else if ((PLParam.GetFrom & (int)SectionMemberType.Type) > 0) { strVal = getFittingSymbolInfoByParamName(fitting, fieldName); } paramVals.Add(strVal); } catch { //... } } if (!forHTML) //for csv, the last column is section pressure loss report { string strVal = ReportConstants.mergeValue; if (nIndex == 0) { strVal = helper.getTotalPressureLossByType(section, SectionMemberType.Fitting); } paramVals.Add(strVal); } nIndex++; helper.addRow(fittingTB, paramVals); } return(true); }
private static void RegisterServer(IExternalServer server) { ExternalService service = ExternalServiceRegistry.GetService(server.GetServiceId()); service.AddServer(server); }
/// <summary> /// Updates the entity in the pipe fitting and accessory pressure drop UI data. /// </summary> /// <param name="data"> /// The pipe fitting and accessory pressure drop UI data. /// </param> /// <param name="dbServerId"> /// The corresponding DB server Id of the UI server. /// </param> /// <param name="schemaField"> /// The schema field to be updated. /// </param> /// <param name="newValue"> /// The new value to be set to the schema field. /// </param> /// <returns> /// True if the entity in the UI data is updated, false otherwise. /// </returns> public static bool UpdateEntities(PipeFittingAndAccessoryPressureDropUIData data, Guid dbServerId, string schemaField, string newValue) { bool isUpdated = false; ExternalService service = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.PipeFittingAndAccessoryPressureDropService); if (service == null) { return(isUpdated); } IPipeFittingAndAccessoryPressureDropServer dbServer = service.GetServer(dbServerId) as IPipeFittingAndAccessoryPressureDropServer; if (dbServer == null) { return(isUpdated); } Schema schema = dbServer.GetDataSchema(); if (schema == null) { return(isUpdated); } Field field = schema.GetField(schemaField); if (field == null) { return(isUpdated); } Entity entity = new Entity(schema); entity.Set <string>(field, newValue); IList <PipeFittingAndAccessoryPressureDropUIDataItem> uiDataItems = data.GetUIDataItems(); foreach (PipeFittingAndAccessoryPressureDropUIDataItem uiDataItem in uiDataItems) { Entity oldEntity = uiDataItem.GetEntity(); if (oldEntity == null && entity == null) { continue; } if (oldEntity == null || entity == null) { uiDataItem.SetEntity(entity); isUpdated = true; continue; } if ((!oldEntity.IsValid()) && (!entity.IsValid())) { continue; } if ((!oldEntity.IsValid()) || (!entity.IsValid())) { uiDataItem.SetEntity(entity); isUpdated = true; continue; } string oldValue = oldEntity.Get <string>(schemaField); if (oldValue != newValue) { uiDataItem.SetEntity(entity); isUpdated = true; continue; } } return(isUpdated); }