Exemplo n.º 1
0
        private static void ShowExtrudeFeature()
        {
            //Inventor.Application inventorApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
            //PartDocument partDoc = (PartDocument)inventorApp.ActiveDocument;
            Inventor.Application inventorApp = null;
            try
            {
                //获取一个Inventor的参考
                inventorApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
            }
            catch
            {
                Console.WriteLine("没有正常连接到Inventor");
                return;
            }

            PartDocument partDoc = null;

            partDoc = (PartDocument)inventorApp.ActiveDocument;
            ExtrudeFeatures extrudeFeatures = partDoc.ComponentDefinition.Features.ExtrudeFeatures;

            for (int i = 0; i < extrudeFeatures.Count; i++)
            {
                Console.WriteLine(extrudeFeatures[1].Name);
            }
        }
Exemplo n.º 2
0
        /*
         * static void Main(string[] args)
         * {
         *  //GetExtrudeFeature();
         *  //ShowExtrudeFeature();
         *  //TestFunction();
         *  //SuppressOff();
         *
         *  //GetInventorApp();
         *  //AFunction();
         *  //EditDrawingDemensions();
         *  //防止闪退
         *  System.Console.ReadKey();
         * }
         */

        //拉伸特征、突出的特征
        private static void GetExtrudeFeature()
        {
            Inventor.Application inventorApp = null;
            try
            {
                //获取一个Inventor的参考
                inventorApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
            }
            catch
            {
                Console.WriteLine("没有正常连接到Inventor");
                //MessageBox.Show("没有正常连接到Inventor");
                return;
            }

            PartDocument partDoc = null;

            partDoc = (PartDocument)inventorApp.ActiveDocument;

            ExtrudeFeature extrude = null;

            //最后调用ExtrudeFeatures对象的Item属性,返回具有指定名称的ExtrudeFeature对象
            extrude = partDoc.ComponentDefinition.Features.ExtrudeFeatures[1];

            Console.WriteLine("Extrusion " + extrude.Name + " is suppressed:" + extrude.Suppressed);
        }
Exemplo n.º 3
0
        /**
         * C#读取和修改Inventor模型的属性
         */
        private static void AFunction()
        {
            Inventor.Application inventorApp = null;
            try
            {
                inventorApp = Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;
            }
            catch
            {
                var inventorType = Type.GetTypeFromProgID("Inventor.Application");
                inventorApp         = Activator.CreateInstance(inventorType) as Inventor.Application;
                inventorApp.Visible = true;
            }

            AssemblyDocument asmDoc = (AssemblyDocument)inventorApp.Documents.Open(@"Path", true);

            AssemblyComponentDefinition asmDef = asmDoc.ComponentDefinition;

            foreach (ComponentOccurrence oOcc in asmDef.Occurrences)
            {
                Document oDoc = (Document)oOcc.Definition.Document;
                // using GUID to find the "Summary Information"
                PropertySet oPS = oDoc.PropertySets["{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"];
                // using proID to find TITLE
                Inventor.Property oP = oPS.ItemByPropId[(int)PropertiesForSummaryInformationEnum.kTitleSummaryInformation];
                oP.Value = oP.Value + "new";
            }
        }
Exemplo n.º 4
0
        public void Deactivate()
        {
            // This method is called by Inventor when the AddIn is unloaded.
            // The AddIn will be unloaded either manually by the user or
            // when the Inventor session is terminated

            // TODO: Add ApplicationAddInServer.Deactivate implementation

            // Release objects.
            m_inventorApplication           = null;
            m_appEvents.OnActivateDocument -= new ApplicationEventsSink_OnActivateDocumentEventHandler(ApplicationEvents_OnActivateDocument);

            m_appEvents = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Exemplo n.º 5
0
        private static void SuppressOff()
        {
            Inventor.Application application = Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;
            PartDocument         partDoc     = application.Documents.Add(DocumentTypeEnum.kPartDocumentObject,
                                                                         application.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject,
                                                                                                                 SystemOfMeasureEnum.kDefaultSystemOfMeasure,
                                                                                                                 DraftingStandardEnum.kDefault_DraftingStandard, null),
                                                                         true) as PartDocument;
            PartFeature partFeature = null;

            for (int i = 0; i < partDoc.ComponentDefinition.Features.Count; i++)
            {
                if (partFeature.Suppressed)
                {
                    partFeature.Suppressed = false;
                }
            }
        }
Exemplo n.º 6
0
        /*编辑工程图,修改标注尺寸*/
        private static void EditDrawingDemensions()
        {
            Inventor.Application inventorApp = null;
            try
            {
                inventorApp = Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;
            }
            catch
            {
                var inventorType = Type.GetTypeFromProgID("Inventor.Application");
                inventorApp         = Activator.CreateInstance(inventorType) as Inventor.Application;
                inventorApp.Visible = true;
            }

            //DrawingDocument drawingDocument = (DrawingDocument)inventorApp.ActiveDocument;
            DrawingDocument drawingDocument = inventorApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,
                                                                        inventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject,
                                                                                                                SystemOfMeasureEnum.kDefaultSystemOfMeasure,
                                                                                                                DraftingStandardEnum.kDefault_DraftingStandard,
                                                                                                                null),
                                                                        true) as DrawingDocument;
            Sheet sheet   = drawingDocument.ActiveSheet;
            long  counter = 1;

            foreach (DrawingDimension drawingDimension in sheet.DrawingDimensions)
            {
                drawingDimension.Text.FormattedText = " (Metric)";
                counter = counter + 1;
            }

            //设置对集合中第一个常规维度的引用
            GeneralDimension generalDimension = sheet.DrawingDimensions.GeneralDimensions[1];  //在VBA中是GeneralDimensions.Item[1]

            //设置对该维度的维度样式的引用
            DimensionStyle dimStyle = generalDimension.Style;

            //修改维度样式的一些属性
            //这将修改所有使用此样式的尺寸
            dimStyle.LinearPrecision    = LinearPrecisionEnum.kFourDecimalPlacesLinearPrecision;   //精度(长度):小数点后四位
            dimStyle.AngularPrecision   = AngularPrecisionEnum.kFourDecimalPlacesAngularPrecision; //精度(角度):小数点后四位
            dimStyle.LeadingZeroDisplay = false;
            dimStyle.Tolerance.SetToSymmetric(0.02);
        }
Exemplo n.º 7
0
        private static void GetInventorApplication()
        {
            try
            {
                //Marshal.GetActiveObject 从运行对象表(ROT)获取指定对象的运行实例

                //获取一个Inventor的参考
                inventorApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
                //Console.WriteLine("查找到可用的实例");
            }
            catch
            {
                try
                {
                    Console.WriteLine("没有正常连接到Inventor");
                    //创建新实例
                    ///在线认证需要输入172.20.133.35,如果不能正常访问外网,则Inventor打不开,会导致创建Inventor实例失败
                    Type inventorAppType = Type.GetTypeFromProgID("Inventor.Application");
                    //Console.WriteLine(inventorAppType.GUID.ToString());
                    //Console.WriteLine("重新创建一个Inventor实例");
                    inventorApp = Activator.CreateInstance(inventorAppType) as Application;
                    //Console.WriteLine("创建新Inventor实例完毕");
                }
                catch
                {
                    Console.WriteLine("创建新实例失败");
                    Process.GetCurrentProcess().Close();    //Diagnostics.Process 获取新的Process组件并将其与当前活动的进程关联
                }
            }
            finally
            {
                if (inventorApp != null)
                {
                    Console.WriteLine("生成了Inventor实例并显示Inventor");
                    inventorApp.ApplicationEvents.OnQuit += ApplicationEvents_OnQuit;
                    //inventorApp.WindowState = WindowsSizeEnum.kMaximize;  //将Inventor窗口大小设置为最大窗口
                    inventorApp.WindowState     = WindowsSizeEnum.kNormalWindow;
                    inventorApp.Visible         = false;
                    inventorApp.SilentOperation = true;
                }
            }
        }
Exemplo n.º 8
0
        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            try
            {
                //the Activate method is called by Inventor when it loads the addin
                //the AddInSiteObject provides access to the Inventor Application object
                //the FirstTime flag indicates if the addin is loaded for the first time

                //initialize AddIn members
                m_inventorApplication = addInSiteObject.Application;
                InvAddIn.Button.InventorApplication = m_inventorApplication;

                //initialize event delegates
                m_userInterfaceEvents = m_inventorApplication.UserInterfaceManager.UserInterfaceEvents;

                UserInterfaceEventsSink_OnResetCommandBarsEventDelegate = new UserInterfaceEventsSink_OnResetCommandBarsEventHandler(UserInterfaceEvents_OnResetCommandBars);
                m_userInterfaceEvents.OnResetCommandBars += UserInterfaceEventsSink_OnResetCommandBarsEventDelegate;

                UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate = new UserInterfaceEventsSink_OnResetEnvironmentsEventHandler(UserInterfaceEvents_OnResetEnvironments);
                m_userInterfaceEvents.OnResetEnvironments += UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate;

                UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate = new UserInterfaceEventsSink_OnResetRibbonInterfaceEventHandler(UserInterfaceEvents_OnResetRibbonInterface);
                m_userInterfaceEvents.OnResetRibbonInterface += UserInterfaceEventsSink_OnResetRibbonInterfaceEventDelegate;

                //load image icons for UI items
                IPictureDisp createMasterMIcon = AxHostConverter.ImageToPictureDisp(Resources.CreateMasterM.ToBitmap());
                IPictureDisp createMasterMICON = AxHostConverter.ImageToPictureDisp(Resources.CreateMasterM.ToBitmap());

                IPictureDisp helpIcon = AxHostConverter.ImageToPictureDisp(Resources.icon1.ToBitmap());
                IPictureDisp helpICON = AxHostConverter.ImageToPictureDisp(Resources.icon1.ToBitmap());

                //retrieve the GUID for this class
                GuidAttribute addInCLSID;
                addInCLSID = (GuidAttribute)GuidAttribute.GetCustomAttribute(typeof(StandardAddInServer), typeof(GuidAttribute));
                string addInCLSIDString;
                addInCLSIDString = "{" + addInCLSID.Value + "}";

                //create buttons
                ButtON = new BenjaminButton(
                    "MasterModel", "MasterModel:StandardAddInServer:BenjaminBUTTON", CommandTypesEnum.kShapeEditCmdType,
                    addInCLSIDString, "Create a Master Model File",
                    "keep the model simple", createMasterMIcon, createMasterMICON, ButtonDisplayEnum.kDisplayTextInLearningMode, false);
                //ButtON.HeySherlock = (PartDocument) m_inventorApplication.ActiveDocument;
                Help = new BenjaminButton(
                    "How to", "Help:StandardAddInServer:BenjaminBUTTON", CommandTypesEnum.kShapeEditCmdType,
                    addInCLSIDString, "Help Creating a Master Model File",
                    "keep the model simple", helpIcon, helpICON, ButtonDisplayEnum.kDisplayTextInLearningMode, true);
                //create the command category
                CommandCategory MasterMCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("Master Model", "MasterModel:StandardAddInServer:BenjaminBUTTON", addInCLSIDString);

                MasterMCmdCategory.Add(ButtON.ButtonDefinition);
                MasterMCmdCategory.Add(Help.ButtonDefinition);

                if (firstTime == true)
                {
                    //access user interface manager
                    UserInterfaceManager userInterfaceManager;
                    userInterfaceManager = m_inventorApplication.UserInterfaceManager;

                    InterfaceStyleEnum interfaceStyle;
                    interfaceStyle = userInterfaceManager.InterfaceStyle;

                    //create the UI for classic interface
                    if (interfaceStyle == InterfaceStyleEnum.kClassicInterface)
                    {
                        //create toolbar
                        CommandBar MasterCommander;
                        MasterCommander = userInterfaceManager.CommandBars.Add("Master Model", "MasterModel:StandardAddInServer:BenjaminBUTTONToolbar", CommandBarTypeEnum.kRegularCommandBar, addInCLSIDString);

                        //add buttons to toolbar
                        MasterCommander.Controls.AddButton(ButtON.ButtonDefinition, 0);
                        MasterCommander.Controls.AddButton(Help.ButtonDefinition, 0);

                        //Get the 2d sketch environment base object
                        Inventor.Environment partToolEnvironment;
                        partToolEnvironment = userInterfaceManager.Environments["PMxPartSkEnvironment"];

                        //make this command bar accessible in the panel menu for the Tool environment.
                        partToolEnvironment.PanelBar.CommandBarList.Add(MasterCommander);
                    }
                    //create the UI for ribbon interface
                    else
                    {
                        //get the ribbon associated with part document
                        Inventor.Ribbons ribbons;
                        ribbons = userInterfaceManager.Ribbons;

                        Inventor.Ribbon partRibbon;
                        partRibbon = ribbons["Part"];

                        //get the tabs associated with part ribbon
                        RibbonTabs ribbonTabs;
                        ribbonTabs = partRibbon.RibbonTabs;

                        //get the Tool tab
                        RibbonTab partToolRibbonTab;
                        partToolRibbonTab = ribbonTabs["id_TabTools"];

                        //create a new panel with the tab
                        RibbonPanels ribbonPanels;
                        ribbonPanels = partToolRibbonTab.RibbonPanels;

                        partToolMasterRibbonPanel = ribbonPanels.Add("Master Model", "MasterModel:StandardAddInServer:BenjaminBUTTONRibbonPanel", "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false);

                        //add controls to the MasterModel panel
                        CommandControls partToolMasterRibbonPanelCtrls;
                        partToolMasterRibbonPanelCtrls = partToolMasterRibbonPanel.CommandControls;

                        //add the buttons to the ribbon panel
                        CommandControl MasterMoRiPaCtrl;
                        MasterMoRiPaCtrl = partToolMasterRibbonPanelCtrls.AddButton(ButtON.ButtonDefinition, false, true, "", false);
                        MasterMoRiPaCtrl = partToolMasterRibbonPanelCtrls.AddButton(Help.ButtonDefinition, false, true, "", false);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Exemplo n.º 9
0
        public ScreenshotForm(Application oApp)
        {
            InitializeComponent();

            if (oApp == null)
            {
                MessageBox.Show("Error: Inventor Application is null");
                return;
            }

            m_inventorApplication = oApp;

            //initialize the option as eApplication
            oSelectOption = SelectOptionsEnum.eApplication;

            //disable window button
            ButtonWindow.Enabled = false;

            //Param for selecting application
            oSelectParam_App = new clsSelectParam(m_inventorApplication.Left, m_inventorApplication.Top, m_inventorApplication.Width, m_inventorApplication.Height);

            //params for selecting document
            if (m_inventorApplication.ActiveView != null)
            {
                oSelectParam_Doc = new clsSelectParam(m_inventorApplication.ActiveView.Left, m_inventorApplication.ActiveView.Top, m_inventorApplication.ActiveView.Width, m_inventorApplication.ActiveView.Height);
            }

            //params for selecting window, wait the user to input
            oSelectParam_Win = new clsSelectParam();

            ComboBoxBG.SelectedIndex   = 0;
            ComboBoxFG.SelectedIndex   = 0;
            ComboBoxGray.SelectedIndex = 0;

            //picurebox's mode is StretchImage
            PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;

            //original size values of the dialog
            //the third and forth are for newer values
            this.Tag = this.Width.ToString() + "," + this.Height.ToString() + "," + "0" + "," + "0";

            try
            {
                foreach (Control oCtrl in this.Controls)
                {
                    //size values of the sub-control
                    oCtrl.Tag = oCtrl.Left.ToString() + "," + oCtrl.Top.ToString() + "," + oCtrl.Width.ToString() + "," + oCtrl.Height.ToString();

                    if (oCtrl.Name == "GroupBoxSelectOp" || oCtrl.Name == "GroupBoxSettings" || oCtrl.Name == "GroupBoxOutput")
                    {
                        foreach (Control oSubCtrl in oCtrl.Controls)
                        {
                            oSubCtrl.Tag = oSubCtrl.Left.ToString() + "," + oSubCtrl.Top.ToString() + "," + oSubCtrl.Width.ToString() + "," + oSubCtrl.Height.ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }