Beispiel #1
0
        // ****************
        // Public
        #region Public Methods

        /// <summary>
        /// Initialize an Inventor and prepare variables
        /// </summary>
        public InventorAPI()
        {
            try
            {
                // Trying to seize control of the inventory application
                InventorApplication = (Application)Marshal.
                                      GetActiveObject("Inventor.Application");
            }
            catch (Exception)
            {
                try
                {
                    // If the application could not be intercepted, it will
                    // be thrown out that there is no such application. Let's
                    // try to create an application manually
                    Type _inventorApplicationType = Type.
                                                    GetTypeFromProgID("Inventor.Application");

                    InventorApplication = (Application)Activator.
                                          CreateInstance(_inventorApplicationType);
                    InventorApplication.Visible = true;
                }
                catch (Exception)
                {
                    // If nothing happened, we’ll discard the message that
                    // the inventory is not installed, or for some reason
                    // did not manage to reach it.
                    PluginReporter.Instance().Add(
                        PluginReporter.TypeError.ErrorAPI,
                        "Failed to start Inventor.");
                }
            }

            Initialization(InventorApplication);
        }
Beispiel #2
0
        /// <summary>
        /// The method of initializing the assembly document
        /// </summary>
        /// <param name="InventorApplication"> Link to the application </param>
        public void Initialization(Application InventorApplication)
        {
            if (InventorApplication == null)
            {
                PluginReporter.Instance().Add(
                    PluginReporter.TypeError.ErrorAPI,
                    "Failed to start Inventor");
                return;
            }

            // In the open application, create a metric assembly
            _partDoc = (PartDocument)InventorApplication.Documents.Add
                           (DocumentTypeEnum.kPartDocumentObject,
                           InventorApplication.FileManager.
                           GetTemplateFile(DocumentTypeEnum.kPartDocumentObject,
                                           SystemOfMeasureEnum.kMetricSystemOfMeasure));

            // Document description
            _partDef = _partDoc.ComponentDefinition;

            // Initialize the geometry method
            _transGeometry = InventorApplication.TransientGeometry;
        }