示例#1
8
		public CSimpleInteraction(Inventor.Application oApplication)
		{
			
			mApplication = oApplication;
			
			//Initialize events
			mInteractionEvents = mApplication.CommandManager.CreateInteractionEvents();
			mSelectEvents = mInteractionEvents.SelectEvents;
			
			//Set event handler VB.Net Style
			mSelectEvents.OnSelect += new Inventor.SelectEventsSink_OnSelectEventHandler(this.mSelectEvents_OnSelect);
			mInteractionEvents.OnTerminate += new Inventor.InteractionEventsSink_OnTerminateEventHandler(this.mInteractionEvents_OnTerminate);
			
			//Clear filter and set new ones if needed
			mSelectEvents.ClearSelectionFilter();
			
			//Always Disable mouse move if not needed for performances
			mSelectEvents.MouseMoveEnabled = false;
			mSelectEvents.Enabled = true;
			mSelectEvents.SingleSelectEnabled = true;
			
			//Remember to Start/Stop the interaction event
			mInteractionEvents.Start();
			
		}
        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            // This 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;

            // TODO: Add ApplicationAddInServer.Activate implementation.
            // e.g. event initialization, command creation etc.

            int largeIconSize = 0;
            if (m_inventorApplication.UserInterfaceManager.InterfaceStyle == InterfaceStyleEnum.kRibbonInterface) {
             largeIconSize = 32;
            } else {
             largeIconSize = 24;
            }

        ControlDefinitions controlDefs = m_inventorApplication.CommandManager.ControlDefinitions;
        stdole.IPictureDisp smallPicture1 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon1.ico").ToBitmap());
        stdole.IPictureDisp largePicture1 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon1.ico").ToBitmap());
        m_TreeViewBrowser = controlDefs.AddButtonDefinition("HierarchyPane", "BrowserSample:HierarchyPane", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId,null ,null , smallPicture1, largePicture1);
        m_TreeViewBrowser.OnExecute+= new ButtonDefinitionSink_OnExecuteEventHandler(m_TreeViewBrowser_OnExecute);



        stdole.IPictureDisp smallPicture2 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon2.ico").ToBitmap());
        stdole.IPictureDisp largePicture2 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon2.ico").ToBitmap());
        m_ActiveXBrowser = controlDefs.AddButtonDefinition("ActiveXPane", "BrowserSample:ActiveXPane", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId, null ,null , smallPicture2, largePicture2);
        m_ActiveXBrowser.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(m_ActiveXBrowser_OnExecute);

        stdole.IPictureDisp smallPicture3 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon3.ico").ToBitmap());
        stdole.IPictureDisp largePicture3 = AxHostConverter.ImageToPictureDisp(new Icon(@"Resources\Icon3.ico").ToBitmap());
        m_DoBrowserEvents = controlDefs.AddButtonDefinition("DoBrowserEvents", "BrowserSample:DoBrowserEvents", CommandTypesEnum.kNonShapeEditCmdType, m_ClientId,null ,null , smallPicture3, largePicture3);
    m_DoBrowserEvents.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(m_DoBrowserEvents_OnExecute);

       
             // Get the assembly ribbon.
             Inventor.Ribbon partRibbon = m_inventorApplication.UserInterfaceManager.Ribbons["Part"];
             // Get the "Part" tab.
             Inventor.RibbonTab partTab = partRibbon.RibbonTabs[1];
             Inventor.RibbonPanel partPanel = partTab.RibbonPanels[1];
             partPanel.CommandControls.AddButton(m_TreeViewBrowser, true);
             partPanel.CommandControls.AddButton(m_DoBrowserEvents);
             partPanel.CommandControls.AddButton(m_ActiveXBrowser);

          

        }
 public QubeItToolsChangeProcessor(Inventor.Application inventorApplication, IChangeProcessorParent parentClass, string internalName,
     string commandName, string clientID)
 {
     _inventorApplication = inventorApplication;
     _parentClass = parentClass;
     _clientID = clientID;
     _changeDefInternalName = internalName;
     _changeDefCommandName = commandName;
 }
示例#4
1
		public Form1(Inventor.Application oApplication)
		{
			
			// This call is required by the Windows Form Designer.
			InitializeComponent();
			
			// Add any initialization after the InitializeComponent() call.
			mApplication = oApplication;
			
		}
			public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
			{
				
				m_inventorApplication = addInSiteObject.Application;
				
				m_ApplicationEvents = m_inventorApplication.ApplicationEvents;
                m_ApplicationEvents.OnOpenDocument += this.m_ApplicationEvents_OnOpenDocument;
				
				mControlForm = new Form1(m_inventorApplication);
				mControlForm.ShowModeless();
				
			}
        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            // This 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;

            // TODO: Add ApplicationAddInServer.Activate implementation.
            // e.g. event initialization, command creation etc.
            System.Windows.Forms.MessageBox.Show("I am loaded!!", "Hello World AddIn");
        }
示例#7
1
        public Form1(Inventor.Application oApp)
        {
            InitializeComponent();

            // Add any initialization after the InitializeComponent() call.
            mAngleBox = new DigitTextBox();
            mAngleBox.Name = "AngleBox";
            mAngleBox.Location = new System.Drawing.Point(80, 197);
            mAngleBox.Size = new System.Drawing.Size(48, 30);
            mAngleBox.TabIndex = 3;
            mAngleBox.Text = "";

            this.Controls.Add(mAngleBox);

            mApp = oApp;
        }
 public EditNetRequest(Inventor.Application application, iFeature ifeature, string portName, string netName)
 {
     m_selectiFeature      = ifeature;
     m_inventorApplication = application;
     m_selectportName      = portName;
     m_netName             = netName;
 }
示例#9
0
        /// <summary>
        /// Gets an existing Inventor.Application instance, and creates a new instance if one cannot be retrieved.
        /// VB.net/iLogic example: <code>Dim oApp As Application = ApplicationShim.Instance()</code>
        /// </summary>
        /// <remarks>
        /// C# example: <code>Application app = ApplicationShim.Instance()</code>
        /// </remarks>
        /// <returns>Inventor.Application</returns>
        public static Inventor.Application Instance()
        {
            Inventor.Application app = null;

            try
            {
                return((Inventor.Application)Marshal.GetActiveObject("Inventor.Application"));
            }
            catch (Exception e)
            {
                // is inventor not visible/in interactive mode?
            }

            //perhaps inventor needs to be started...
            if (app == null)
            {
                try //to start inventor
                {
                    Type appType = Type.GetTypeFromProgID("Inventor.Application");
                    app         = (Inventor.Application)Activator.CreateInstance(appType);
                    app.Visible = true;
                    return(app);
                }
                catch (Exception e2)
                {
                    throw new SystemException("Unable to start Inventor.  Error message: " + e2.Message, e2);
                }
            }

            return(null);
        }
        public Form1()
        {
            InitializeComponent();

            try
            {
                _InvApplication = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;
            }

            catch
            {
                Type inventorAppType = System.Type.GetTypeFromProgID("Inventor.Application");
                _InvApplication = System.Activator.CreateInstance(inventorAppType) as Inventor.Application;
            }

            _InvApplication.Visible = true;

            string addInCLSID = "{28e1f9bc-44fb-464c-ba98-e9c14c7eed44}";

            Inventor.ApplicationAddIn addIn = _InvApplication.ApplicationAddIns.get_ItemById(addInCLSID.ToUpper());

            //Make sure addin is activated
            if (!addIn.Activated)
            {
                addIn.Activate();
            }

            _InvAddInInterface = addIn.Automation as HelloWorldCSharp.AutomationInterface;
        }
示例#11
0
        public ArduinoControl()
        {
            InitializeComponent();

            this.TopMost = true;

            getAvailableComPorts();
            initializeSerialPorts();



            try
            {
                inventorApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");

                assembly = (AssemblyDocument)inventorApp.ActiveDocument;

                assembly.ComponentDefinition.Parameters.ModelParameters[inventorModelParameterPart1].Value = 0;
                assembly.ComponentDefinition.Parameters.ModelParameters[inventorModelParameterPart2].Value = 0;
                assembly.Update();
            }
            catch (Exception)
            {
                MessageBox.Show("cannot connect to Inventor");
            }
        }
示例#12
0
 public FieldSaver(Inventor.Application currentApplication, ArrayList fieldDataList)
 {
     tempReader              = new TempReader((AssemblyDocument)currentApplication.ActiveDocument, fieldDataList);
     tempWriter              = new TempWriter(currentApplication, ((AssemblyDocument)currentApplication.ActiveDocument).Thumbnail, fieldDataList);
     jointResolver           = new JointResolver(currentApplication, tempReader.getSTLDict());
     this.currentApplication = currentApplication;
 }
示例#13
0
        void DoDemo()
        {
            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            _interactionManager = new AdnInteractionManager(InvApp);

            _interactionManager.Initialize();

            _interactionManager.OnTerminateEvent +=
                new AdnInteractionManager.OnTerminateHandler(OnTerminateEvent);

            _interactionManager.MouseEvents.OnMouseDown +=
                new MouseEventsSink_OnMouseDownEventHandler(MouseEvents_OnMouseDown);

            _interactionManager.Start("Click points anywhere in model window: ");

            _clientGraphicsMng = new AdnClientGraphicsManager(
                AdnInventorUtilities.InvApplication,
                AdnInventorUtilities.AddInGuid);

            _clientGraphicsMng.SetGraphicsSource(
                _interactionManager.InteractionEvents);

            _lineStripGraph = null;
        }
示例#14
0
	private void Form1_Load(object sender, System.EventArgs e)
	{

		try {
			mApp = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
             

            foreach (ApplicationAddIn oAddIn in mApp.ApplicationAddIns)
            {
				try {
					//Fills up at runtime our addins combobox
					if ((oAddIn.AddInType == ApplicationAddInTypeEnum.kTranslationApplicationAddIn)) {
						ComboAddinsItem newItem = new ComboAddinsItem(oAddIn.DisplayName, oAddIn.ClassIdString);
						ComboAddIns.Items.Add(newItem);
					}

				} catch {
					//Exception can be thrown if "AddInType", "DisplayName" or "ClassIdString" properties
					//are not implemented. For a custom addin for example.
					continue;
				}

			}

			ComboAddIns.SelectedIndex = 0;


		} catch (Exception ex) {
			System.Windows.Forms.MessageBox.Show("Error: Inventor must be running...");
			Button1.Enabled = false;
			return;

		}

	}
示例#15
0
        public void WriteSTLFiles(string outputfolder)
        {
            Inventor.Application _invApp    = Links[0].Application;
            TranslatorAddIn      stptrans   = (TranslatorAddIn)_invApp.ApplicationAddIns.ItemById["{533E9A98-FC3B-11D4-8E7E-0010B541CD80}"];
            TranslationContext   stpcontext = _invApp.TransientObjects.CreateTranslationContext();

            NameValueMap stpoptions = _invApp.TransientObjects.CreateNameValueMap();

            Links.Reverse();

            foreach (Link oAsmComp in Links.Skip(1))
            {
                dynamic test = oAsmComp.ReferencedDocumentDescriptor.ReferencedDocument;

                if (stptrans.HasSaveCopyAsOptions[test, stpcontext, stpoptions])
                {
                    stpoptions.Value["ExportUnits"] = 6;
                    stpoptions.Value["Resolution"]  = 2;
                    stpcontext.Type = IOMechanismEnum.kFileBrowseIOMechanism;

                    DataMedium stpdata = _invApp.TransientObjects.CreateDataMedium();
                    stpdata.FileName = outputfolder + "\\" + oAsmComp.Name + ".stl";
                    stptrans.SaveCopyAs(test, stpcontext, stpoptions, stpdata);
                }
            }
        }
示例#16
0
        public void PartDocument_IsReturned()
        {
            Inventor.Application app = ApplicationShim.Instance();
            var      path            = app.DesignProjectManager.ActiveDesignProject.TemplatesPath;
            Document doc             = app.Documents.Add(DocumentTypeEnum.kPartDocumentObject, path + "Standard.ipt", true);

            var doc2 = doc.ReturnSpecificDocumentObject();

            //var tt = doc2.GetPropertyValue("Author");
            var tt = PropertyShim.GetPropertyValue(doc2, "Author");
            //only exists in ParDocuments
            PartComponentDefinition test = null;

            try
            {
                test = doc2.ComponentDefinition;
            }
            catch { }

            try
            {
                Assert.IsNotNull(test);
            }
            finally { doc.Close(true); }
        }
示例#17
0
        public InventorCamera()
        {
            if (invApp == null)
            {
                try
                {
                    invApp  = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
                    started = true;
                }
                catch (Exception ex)
                {
                    started = false;
                    invApp  = null;
                    return;
                }
            }
            if (invApp.Documents.Count == 0)
            {
                opened = false;
                return;
            }

            if (invApp.ActiveDocument.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject || invApp.ActiveDocument.DocumentType == DocumentTypeEnum.kPartDocumentObject || invApp.ActiveDocument.DocumentType == DocumentTypeEnum.kPresentationDocumentObject)
            {
                FindType();
                opened = true;
                oView  = invApp.ActiveView;
                oTG    = invApp.TransientGeometry;
                ReturnHome();
                oCamera = oView.Camera;
            }
        }
示例#18
0
        public static string WorkspacePath()
        {
            Inventor.Application app = ApplicationShim.Instance();
            var path = app.DesignProjectManager.ActiveDesignProject.WorkspacePath;

            return(path);
        }
示例#19
0
        public AddAssembly()
        {
            this.Location = new System.Drawing.Point(450, 350);
            InitializeComponent();
            this.TopMost = true;

            //Used to access StandardAddInServer's exposed API
            try
            {
                mApplication = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;
            }

            catch
            {
                Type inventorAppType = System.Type.GetTypeFromProgID("Inventor.Application");
                mApplication = System.Activator.CreateInstance(inventorAppType) as Inventor.Application;
            }
            mApplication.Visible = true;


            //Iterates through Inventor Add-Ins collection
            foreach (ApplicationAddIn oAddIn in mApplication.ApplicationAddIns)
            {
                //Looks for StandardAddInServer's Class ID;
                if (oAddIn.ClassIdString == "{E50BE244-9F7B-4B94-8F87-8224FABA8CA1}")
                {
                    //Calls Automation property
                    mAddInInterface = (AutomationInterface)oAddIn.Automation;
                }
            }
        }
示例#20
0
        public PartDocument openDocument()
        {
            Inventor.Application m_inventorApp = null;

            // Try to get an active instance of Inventor
            try
            {
                m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;
            }
            catch
            {
            }

            // If not active, create a new Inventor session
            if (m_inventorApp == null)
            {
                Type inventorAppType = System.Type.GetTypeFromProgID("Inventor.Application");
                m_inventorApp = System.Activator.CreateInstance(inventorAppType) as Inventor.Application;
            }

            // test complete



            PartDocument partDocument;

            partDocument = m_inventorApp.Documents.Open("C:\\Users\\Emre\\Desktop\\AppInventor\\Skech.ipt",
                                                        true) as PartDocument;

            return(partDocument);
        }
示例#21
0
        internal static Inventor.Document CreatePartDocument()
        {
            Inventor.Application app = ApplicationShim.Instance();
            var path = app.DesignProjectManager.ActiveDesignProject.TemplatesPath;

            return(app.Documents.Add(DocumentTypeEnum.kPartDocumentObject, path + "Standard.ipt", true));
        }
示例#22
0
 public void Deactivate()
 {
     // TODO Dispose in InventorServices
     inventorApplication = null;
     GC.Collect();
     GC.WaitForPendingFinalizers();
 }
    private void Form1_Load(object sender, System.EventArgs e)
    {
        try {
            mApp = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");


            foreach (ApplicationAddIn oAddIn in mApp.ApplicationAddIns)
            {
                try {
                    //Fills up at runtime our addins combobox
                    if ((oAddIn.AddInType == ApplicationAddInTypeEnum.kTranslationApplicationAddIn))
                    {
                        ComboAddinsItem newItem = new ComboAddinsItem(oAddIn.DisplayName, oAddIn.ClassIdString);
                        ComboAddIns.Items.Add(newItem);
                    }
                } catch {
                    //Exception can be thrown if "AddInType", "DisplayName" or "ClassIdString" properties
                    //are not implemented. For a custom addin for example.
                    continue;
                }
            }

            ComboAddIns.SelectedIndex = 0;
        } catch (Exception ex) {
            System.Windows.Forms.MessageBox.Show("Error: Inventor must be running...");
            Button1.Enabled = false;
            return;
        }
    }
示例#24
0
        public void BadInput_Empty()
        {
            Inventor.Application app = ApplicationShim.Instance();
            var test = string.Empty;

            Assert.IsFalse(PathShim.IsContentCenterPath(test, ref app));
        }
示例#25
0
        public void BadInput_Wrong()
        {
            Inventor.Application app = ApplicationShim.Instance();
            string test = @"C:\Windows\";

            Assert.IsFalse(PathShim.IsContentCenterPath(test, ref app));
        }
示例#26
0
        public IMate(Inventor.Document oDoc, string name = "", string typ = "", string offset = "")
        {
            invApp = (Inventor.Application)oDoc.Parent;
            Doc    = (Document)oDoc.ActivatedObject;
            if (Doc == null)
            {
                Doc = oDoc;
            }
            CmdMgr = invApp.CommandManager;
            objs   = invApp.TransientObjects.CreateObjectCollection();
            InitializeComponent();
            XML    n;
            string filePath = @"C:\ProgramData\Autodesk\Inventor Addins\Imate.xml";

            if (!System.IO.File.Exists(filePath))
            {
                MessageBox.Show("Отсутствует файл " + filePath);
            }
            n    = new InvDoc.XML(filePath);
            data = new List <XMLData>();
            data = n.ReadXML("Imates");
            foreach (XMLData s in data)
            {
                this.comboBox3.Items.Add(s.val);
            }
            this.comboBox2.Text = offset;
            this.comboBox1.Text = typ;
            this.comboBox3.Text = name;
            //this.Deactivate += (sender, e) => MessageBox.Show("Deactivated!");
        }
示例#27
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        void InsertAsSurfaceGraphics(Matrix transfo)
        {
            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            Document document = InvApp.ActiveDocument;

            ComponentDefinition compDef =
                AdnInventorUtilities.GetCompDefinition(document);

            _clientGraphicsMng.SetGraphicsSource(InvApp.ActiveDocument);

            Dictionary <SurfaceBody, SurfaceBody> surfaceBodies =
                AdnInventorUtilities.GetTransientBodies(
                    AdnInventorUtilities.GetCompDefinition(_componentDocument));

            foreach (KeyValuePair <SurfaceBody, SurfaceBody> pair in surfaceBodies)
            {
                SurfaceGraphics surfGraph = _clientGraphicsMng.DrawSurface(pair.Value);

                GraphicsNode node = surfGraph.Parent;

                node.Transformation = transfo;
                node.Selectable     = true;

                StyleSourceTypeEnum styleSourceType;
                node.RenderStyle = pair.Key.GetRenderStyle(out styleSourceType);
            }
        }
示例#28
0
        // Create Ribbon items based on a Stream name, typically an embedded resource xml file
        public static void CreateRibbon(Inventor.Application app, Type addinType, string resourcename)
        {
            System.IO.Stream xmlres =
                addinType.Assembly.GetManifestResourceStream(resourcename);

            new AdnRibbonBuilder(app, addinType.GUID.ToString("B")).DoCreateRibbon(xmlres);
        }
示例#29
0
        public void Deactivate()
        {
            //the Deactivate 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

            try
            {
                m_userInterfaceEvents.OnResetCommandBars  -= UserInterfaceEventsSink_OnResetCommandBarsEventDelegate;
                m_userInterfaceEvents.OnResetEnvironments -= UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate;

                UserInterfaceEventsSink_OnResetCommandBarsEventDelegate  = null;
                UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate = null;
                m_userInterfaceEvents = null;
                if (m_partSketchSlotRibbonPanel != null)
                {
                    m_partSketchSlotRibbonPanel.Delete();
                }

                //release inventor Application object
                Marshal.ReleaseComObject(m_inventorApplication);
                m_inventorApplication = null;

                GC.WaitForPendingFinalizers();
                GC.Collect();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
示例#30
0
        /// <summary>
        /// Create a button from inventor using Image file as icon
        /// </summary>
        /// <param name="app"></param>
        /// <param name="displayName"></param>
        /// <param name="internalName"></param>
        /// <param name="commandType"></param>
        /// <param name="clientId"></param>
        /// <param name="description"></param>
        /// <param name="tooltip"></param>
        /// <param name="standardIcon"></param>
        /// <param name="largeIcon"></param>
        /// <param name="buttonDisplayType"></param>
        public Button(Inventor.Application app,
                      string displayName,
                      string internalName,
                      CommandTypesEnum commandType,
                      string clientId,
                      string description,
                      string tooltip,
                      object standardIcon,
                      object largeIcon,
                      ButtonDisplayEnum buttonDisplayType)
        {
            try
            {
                _buttonDefinition = app.CommandManager
                                    .ControlDefinitions
                                    .AddButtonDefinition(displayName,
                                                         internalName,
                                                         commandType,
                                                         clientId,
                                                         description,
                                                         tooltip,
                                                         standardIcon,
                                                         largeIcon,
                                                         buttonDisplayType);

                _buttonDefinition.Enabled         = true;
                _buttonDef_OnExecuteEventDelegate = new ButtonDefinitionSink_OnExecuteEventHandler(Button_OnExecute);
                _buttonDefinition.OnExecute      += _buttonDef_OnExecuteEventDelegate;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                throw new ApplicationException(ex.Message);
            }
        }
示例#31
0
        // Function for checking if the active document is of given type
        public static bool DocumentChecker(DataTypes allowedDocument, Inventor.Application inventorObject)
        {
            bool isValid;

            switch (allowedDocument)
            {
            case DataTypes.Assembly:
                isValid = inventorObject.ActiveDocumentType == DocumentTypeEnum.kAssemblyDocumentObject ? true : false;
                break;

            case DataTypes.Drawing:
                isValid = inventorObject.ActiveDocumentType == DocumentTypeEnum.kDrawingDocumentObject ? true : false;
                break;

            case DataTypes.Part:
                isValid = inventorObject.ActiveDocumentType == DocumentTypeEnum.kPartDocumentObject ? true : false;
                break;

            default:
                isValid = false;
                break;
            }

            return(isValid);
        }
示例#32
0
        public void CreateSetThatDoesntExist()
        {
            Inventor.Application app = ApplicationShim.Instance();
            var      path            = app.DesignProjectManager.ActiveDesignProject.TemplatesPath;
            Document doc             = app.Documents.Add(DocumentTypeEnum.kPartDocumentObject, path + "Standard.ipt", true);

            //try to remove an attributeSet that does not exist.  Will this crash?
            AttributeShim.CreateAttributeSet(doc, "testSet");


            bool result = false;

            foreach (AttributeSet i in doc.AttributeSets)
            {
                if (i.Name.Equals("testSet"))
                {
                    result = true;
                }
            }
            try
            {
                Assert.IsTrue(result);
            }
            finally { doc.Close(true); }
        }
示例#33
0
        public void GoodInput()
        {
            Inventor.Application app = ApplicationShim.Instance();

            var designProject = app.DesignProjectManager.ActiveDesignProject;
            var libraryPaths  = designProject.LibraryPaths;

            var i = libraryPaths.Count + 1;

            libraryPaths.Add("temporary path", @"C:\");

            string test = libraryPaths[1].Path;

            test = PathShim.TrimEndingDirectorySeparator(test);

            try
            {
                Assert.IsTrue(test.IsLibraryPath(app));
            }
            finally
            {
                libraryPaths[i].Delete();
                Marshal.ReleaseComObject(app);
                app = null;
            }
        }
示例#34
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        // The public static method to start the demo
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        public static void Demo()
        {
            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            object selection = InvApp.CommandManager.Pick(
                SelectionFilterEnum.kPartBodyFilter,
                "Select a SurfaceBody: ");

            if (selection == null)
            {
                return;
            }

            SurfaceBody body = selection as SurfaceBody;

            AdnClientGraphicsManager clientGraphicsMng = new AdnClientGraphicsManager(
                InvApp,
                AdnInventorUtilities.AddInGuid);

            GraphicsNode node = clientGraphicsMng.CreateNewGraphicsNode();

            foreach (Edge edge in body.Edges)
            {
                CurveGraphics graphic = clientGraphicsMng.DrawCurve(edge.Geometry, node);

                graphic.LineWeight         = 5.0;
                graphic.Parent.RenderStyle = InvApp.ActiveDocument.RenderStyles["Red"];
            }

            clientGraphicsMng.UpdateView();
        }
示例#35
0
        public void RemovesNonExisting_noCrash()
        {
            Inventor.Application app = ApplicationShim.Instance();
            var      path            = app.DesignProjectManager.ActiveDesignProject.TemplatesPath;
            Document doc             = app.Documents.Add(DocumentTypeEnum.kPartDocumentObject, path + "Standard.ipt", true);

            //create the test AttributeSet
            AttributeSet attributeSet = doc.AttributeSets.Add("testSet");

//            Inventor.Attribute attribute = attributeSet.Add("testAttribute", ValueTypeEnum.kStringType, "test string");

            AttributeShim.RemoveAttribute(doc, "testSet", "testAttribute");

            bool result = false;

            foreach (Inventor.Attribute i in doc.AttributeSets["testSet"])
            {
                if (i.Name.Equals("testAttribute"))
                {
                    result = true;
                }
            }

            try
            {
                Assert.IsFalse(result);
            }
            finally { doc.Close(true); }
        }
示例#36
0
        public Panel(Inventor.Application invApp, ButtonDefinition btnDef, string ribbonName, string ribbonTabName, string displayName, string intName, string m_guid)
        {
            UserInterfaceManager userInterfaceManager;

            userInterfaceManager = invApp.UserInterfaceManager;
            Ribbons ribbons;

            ribbons = userInterfaceManager.Ribbons;
            Ribbon ribbon;

            ribbon = ribbons[ribbonName];
            RibbonTabs ribbonTabs;

            ribbonTabs = ribbon.RibbonTabs;
            RibbonTab ribbonTab;

            ribbonTab = ribbonTabs[ribbonTabName];
            RibbonPanels ribbonPanels;

            ribbonPanels = ribbonTab.RibbonPanels;
            RibbonPanel ribbonPanel;

            ribbonPanel = ribbonPanels.Add(displayName, intName, m_guid, "", false);
            //CommandControls commandControls;
            m_commandControls = ribbonPanel.CommandControls;
            m_commandControl  = m_commandControls.AddButton(btnDef);
        }
示例#37
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                _InvApplication = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
            }
            catch (Exception ex)
            {
                MessageBox.Show("make sure an Inventor instance is launched!");
                return;
            }

            // Add any initialization after the InitializeComponent() call.
            _macros = new Macros(_InvApplication);

            MemberInfo[] methods = _macros.GetType().GetMembers();

            foreach (MemberInfo member in methods)
            {
                if ((member.DeclaringType.Name == "Macros" & member.MemberType == MemberTypes.Method))
                {
                    ComboBoxMacros.Items.Add(member.Name);
                }
            }

            if (ComboBoxMacros.Items.Count > 0)
            {
                ComboBoxMacros.SelectedIndex = 0;
                button1.Enabled = true;
            }
        }
        public iFeatureFormRequest(Inventor.Application application, Face face, string filepath, string filename, string codename, string codenumber, string indexname, string checkfootprint, double xdistance, double ydistance, Inventor.Point point, double angle, DataGridView dataport)
        {
            m_inventorApplication = application;
            m_selsectFace         = face;
            //---------------------------------------------------------------------------
            //数据库连接参数
            this.filepath       = filepath;
            this.filename       = filename;
            this.codename       = codename;
            this.codenumber     = codenumber;
            this.indexname      = indexname;
            this.checkfootprint = checkfootprint;
            //---------------------------------------------------------------------------
            //插入点的信息
            this.Xposition = xdistance;
            this.Yposition = ydistance;

            this.m_Point        = point;
            this.rotateAngle    = angle;
            this.m_dataportView = dataport;
            assembly            = System.Reflection.Assembly.GetExecutingAssembly();
            FileInfo asmFile = new FileInfo(assembly.Location);

            deFaultpath = asmFile.DirectoryName;
            //---------------------------------------------------------------------------
            m_connectToaccess = new ConnectToAccess(filepath, filename, codename, indexname, codenumber);
        }
示例#39
0
        public Form1()
        {
            InitializeComponent();

            try
            {
                _InvApplication = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;
            }

            catch
            {
                Type inventorAppType = System.Type.GetTypeFromProgID("Inventor.Application");
                _InvApplication = System.Activator.CreateInstance(inventorAppType) as Inventor.Application;
            }

            _InvApplication.Visible = true;

            string addInCLSID = "{28e1f9bc-44fb-464c-ba98-e9c14c7eed44}";

            Inventor.ApplicationAddIn addIn = _InvApplication.ApplicationAddIns.get_ItemById(addInCLSID.ToUpper());

            //Make sure addin is activated
            if (!addIn.Activated)
            {
                addIn.Activate();
            }

            _InvAddInInterface = addIn.Automation as HelloWorldCSharp.AutomationInterface;
        }
示例#40
0
 public RotateRequest(Inventor.Application application, Face face, iFeature ifeature, double angle)
 {
     m_inventorApplication = application;
     m_selectFace          = face;
     m_selectiFeature      = ifeature;
     m_Angle = angle;
 }
 public static void InventorStart()
 {
     if (quietCheck() == false) {
         Type invAppType = Type.GetTypeFromProgID("Inventor.Application");
         _invApp = (Inventor.Application)System.Activator.CreateInstance(invAppType);
         _invApp.Visible = true;
         _started = true;
     }
     else
     {
         MessageBox.Show("Inventor is already running!");
     }
 }
        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;

              GC.Collect();
              GC.WaitForPendingFinalizers();
        }
 public static bool InventorCheck()
 {
     try
     {
         _invApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
         return true;
     }
     catch (Exception ex)
     {
         /* Slight varaition in that I do not automatically start the application */
         MessageBox.Show("Please start inventor manually, or select start inventor from the file menu!");
         return false;
     }
 }
        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            // This 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;

              // TODO: Add ApplicationAddInServer.Activate implementation.
              // e.g. event initialization, command creation etc.
              var cmdMgr = m_inventorApplication.CommandManager;
              m_btnDef = cmdMgr.ControlDefinitions.AddButtonDefinition(
            "ShowWpfDialog", "ShowWpfDialog", CommandTypesEnum.kQueryOnlyCmdType);
              m_btnDef.OnExecute += ctrlDef_OnExecute;
              m_btnDef.AutoAddToGUI();
        }
        public RectangleConfigButton()
        {
            this.invApplication = StandardAddInServer.InventorApplication;
            ClientButtonInternalName = StandardAddInServer.AddInServerId + "RectangleConfigButton";

            try
            {
                CreateButtonDefinition();
                buttonEventsLibrary = new ButtonEventsLib(ButtonDefinition);
                buttonEventsLibrary.OnExecuteDelegate += RectangleConfigButtonOnExecute;
                buttonEventsLibrary.ButtonDef.OnExecute += buttonEventsLibrary.OnExecuteDelegate;
            }
            catch (Exception e)
            {
                var dialogResult = MessageBox.Show("Rectangle Config Button did not implement properly.\n\n" + e.ToString());
            }
        }
示例#46
0
        public Form_ShaftPparts()
        {
            InitializeComponent();

               tbWidth.Text = "0";
               tbHeight.Text = "0";

               comboBoxStartEdgeType.SelectedItem = "Standart";
               comboBoxEndEdgeType.SelectedItem = "Standart";

               try
               {
             ThisApplication = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
               }
               catch
               {
               // Если Inventor не запустился
               System.Windows.Forms.MessageBox.Show("Need to start an Inventor session - Exiting");
               return;
               }
        }
 public InventorController()
 {
     isConstructed=false;
     try
     {
         inventorApplication = (Inventor.Application)
         System.Runtime.InteropServices.Marshal.
         GetActiveObject("Inventor.Application");
         assemblyDoc = (AssemblyDocument)inventorApplication.ActiveDocument;
         assemblyComp = assemblyDoc.ComponentDefinition;
         parameterList = getParameterList();
         isConstructed = true;
         createConstraintList();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Write(ex.Message);
         return;
     }
     isConstructed = true;
 }
示例#48
0
        private void Form1_Load(object sender, EventArgs e)
        {
            DigitTextBox1 = new DigitTextBox();
            DigitTextBox1.Name = "DigitTextBox1";
            DigitTextBox1.Location = new System.Drawing.Point(80, 15);
            DigitTextBox1.Size = new System.Drawing.Size(80, 10);
            DigitTextBox1.TabIndex = 1;
            DigitTextBox1.Text = "";

            DigitTextBox2 = new DigitTextBox();
            DigitTextBox2.Name = "DigitTextBox2";
            DigitTextBox2.Location = new System.Drawing.Point(80, 40);
            DigitTextBox2.Size = new System.Drawing.Size(80, 10);
            DigitTextBox2.TabIndex = 2;
            DigitTextBox2.Text = "";

            this.Controls.Add(DigitTextBox1);
            this.Controls.Add(DigitTextBox2);

            try //Try to get an active instance of Inventor
            {
                try
                {
                    m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;
                }
                catch
                {
                    Type inventorAppType = System.Type.GetTypeFromProgID("Inventor.Application");

                    m_inventorApp = System.Activator.CreateInstance(inventorAppType) as Inventor.Application;

                    //Must be set visible explicitly
                    m_inventorApp.Visible = true;
                }
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("Error: couldn't create Inventor instance");
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////
        // Use: AdnClientGraphicsManager Constructor
        //
        //////////////////////////////////////////////////////////////////////////////////////
        public AdnClientGraphicsManager(Inventor.Application Application, string clientId)
        {
            _Application = Application;

            _clientId = clientId;

            _workingDocument = _Application.ActiveDocument;

            Transacting = true;

            _mode = AdnGraphicModeEnum.kDocumentGraphics;

            InteractionGraphicsMode = AdnInteractionGraphicsModeEnum.kPreviewGraphics;
        }
 private static bool quietCheck()
 {
     try
     {
         _invApp = (Inventor.Application)Marshal.GetActiveObject("Inventor.Application");
         return true;
     }
     catch (Exception ex)
     {
         /* Slight varaition in that I do not automatically start the application */
         return false;
     }
 }
        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            // This 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;

            // TODO: Add ApplicationAddInServer.Activate implementation.
            // e.g. event initialization, command creation etc.
            // Connect to the user-interface events to handle a ribbon reset.

            {
                m_uiEvents = m_inventorApplication.UserInterfaceManager.UserInterfaceEvents;
                m_uiEvents.OnResetRibbonInterface +=m_uiEvents_OnResetRibbonInterface;

                stdole.IPictureDisp largeIcon = PictureDispConverter.ToIPictureDisp(InvAddIn.Resource1.Large);
                stdole.IPictureDisp smallIcon = PictureDispConverter.ToIPictureDisp(InvAddIn.Resource1.Small);
                Inventor.ControlDefinitions controlDefs = m_inventorApplication.CommandManager.ControlDefinitions;
                m_sampleButton1 = controlDefs.AddButtonDefinition("License check", "Entitlement API", CommandTypesEnum.kShapeEditCmdType, AddInClientID(), "Entitlement api", "Entitlement api", smallIcon, largeIcon);
                m_sampleButton1.OnExecute +=m_sampleButton1_OnExecute;

                // Add to the user interface, if it's the first time.
                if (firstTime)
                {
                    AddToUserInterface();
                }
            }
        }
示例#52
0
        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            // This 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;

            // TODO: Add ApplicationAddInServer.Activate implementation.
            // e.g. event initialization, command creation etc.
            String strAddInGUID = "{" + ((GuidAttribute)System.Attribute.GetCustomAttribute(typeof(StandardAddInServer), typeof(GuidAttribute))).Value + "}";

            buttonDefinition = m_inventorApplication.CommandManager.ControlDefinitions.AddButtonDefinition(
              "Chapter1AddInBD",
              "Chapter1AddInBD_Internal",
              Inventor.CommandTypesEnum.kShapeEditCmdType,
              strAddInGUID,
              "Chapter1AddInBD_Description",
              "Chapter1AddInBD_Tooltip",
              System.Type.Missing,
              System.Type.Missing,
              Inventor.ButtonDisplayEnum.kAlwaysDisplayText);
            buttonDefinition.OnExecute += new ButtonDefinitionSink_OnExecuteEventHandler(ButtonDefinition_OnExecute);

            if (firstTime)
            {
                Inventor.CommandBar commandBar = m_inventorApplication.UserInterfaceManager.CommandBars.Add(
                  "Chapter1AddInCB",
                  "Chapter1AddInCB_Internal",
                  Inventor.CommandBarTypeEnum.kRegularCommandBar,
                  strAddInGUID);
                commandBar.Controls.AddButton(buttonDefinition, 0);
                commandBar.Visible = true;
            }
        }
示例#53
0
 public Macros(Inventor.Application oApp)
 {
     _InvApplication = oApp;
 }
示例#54
0
        public static void Initialize(Inventor.Application Application, Type addinType)
        {
            InvApplication = Application;

            AddInGuid = addinType.GUID.ToString("B");
        }
示例#55
0
 public void Deactivate()
 {
     // TODO Dispose in InventorServices
     inventorApplication = null;
     GC.Collect();
     GC.WaitForPendingFinalizers();
 }
示例#56
0
        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {        
            try
            {
                SetupDynamoPaths();
                inventorApplication = addInSiteObject.Application;
                PersistenceManager.InventorApplication = inventorApplication;
                userInterfaceManager = inventorApplication.UserInterfaceManager;

                //initialize event delegates
                userInterfaceEvents = inventorApplication.UserInterfaceManager.UserInterfaceEvents;

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

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

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

                appEvents = inventorApplication.ApplicationEvents;
                appEvents.OnActivateDocument += appEvents_OnActivateDocument;
                appEvents.OnDeactivateDocument += appEvents_OnDeactivateDocument;

                Icon dynamoIcon = Resources.logo_square_32x32;

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

                dynamoAddinButton = new DynamoInventorAddinButton(
                        buttonDisplayName, buttonInternalName, CommandTypesEnum.kShapeEditCmdType,
                        addInCLSIDString, "Initialize Dynamo.",
                        "Dynamo is a visual programming environment for Inventor.", dynamoIcon, dynamoIcon, ButtonDisplayEnum.kDisplayTextInLearningMode);

                CommandCategory assemblyUtilitiesCategory = inventorApplication.CommandManager.CommandCategories.Add(commandCategoryDisplayName, commandCategoryInternalName, addInCLSID);
                assemblyUtilitiesCategory.Add(dynamoAddinButton.ButtonDefinition);

                if (firstTime == true)
                {
                    InterfaceStyleEnum interfaceStyle;
                    interfaceStyle = userInterfaceManager.InterfaceStyle;

                    if (interfaceStyle == InterfaceStyleEnum.kClassicInterface)
                    {
                        CommandBar assemblyUtilityCommandBar;

                        assemblyUtilityCommandBar = userInterfaceManager.CommandBars.Add(commandBarDisplayName,
                                                                                         commandBarInternalName,
                                                                                         CommandBarTypeEnum.kRegularCommandBar,
                                                                                         addInCLSID);
                    }

                    else
                    {   
                        Inventor.Ribbons ribbons = userInterfaceManager.Ribbons;
                        Inventor.Ribbon assemblyRibbon = ribbons["Assembly"];
                        RibbonTabs ribbonTabs = assemblyRibbon.RibbonTabs;
                        RibbonTab assemblyRibbonTab = ribbonTabs["id_AddInsTab"];
                        RibbonPanels ribbonPanels = assemblyRibbonTab.RibbonPanels;
                        assemblyRibbonPanel = ribbonPanels.Add(ribbonPanelDisplayName, ribbonPanelInternalName, "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false);
                        CommandControls assemblyRibbonPanelCtrls = assemblyRibbonPanel.CommandControls;
                        CommandControl assemblyCmdBtnCmdCtrl = assemblyRibbonPanelCtrls.AddButton(dynamoAddinButton.ButtonDefinition, true, true, "", false); 

                        Inventor.Ribbon partRibbon = ribbons["Part"];
                        RibbonTabs partRibbonTabs = partRibbon.RibbonTabs;
                        RibbonTab modelRibbonTab = partRibbonTabs["id_AddInsTab"];
                        RibbonPanels partRibbonPanels = modelRibbonTab.RibbonPanels;
                        partRibbonPanel = partRibbonPanels.Add(ribbonPanelDisplayName, ribbonPanelInternalName, "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false);
                        CommandControls partRibbonPanelCtrls = partRibbonPanel.CommandControls;
                        CommandControl partCmdBtnCmdCtrl = partRibbonPanelCtrls.AddButton(dynamoAddinButton.ButtonDefinition, true, true, "", false);

                        Inventor.Ribbon drawingRibbon = ribbons["Drawing"];
                        RibbonTabs drawingRibbonTabs = drawingRibbon.RibbonTabs;
                        RibbonTab drawingRibbonTab = drawingRibbonTabs["id_AddInsTab"];
                        RibbonPanels drawingRibbonPanels = drawingRibbonTab.RibbonPanels;
                        drawingRibbonPanel = drawingRibbonPanels.Add(ribbonPanelDisplayName, ribbonPanelInternalName, "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "", false);
                        CommandControls drawingRibbonPanelCtrls = drawingRibbonPanel.CommandControls;
                        CommandControl drawingCmdBtnCmdCtrl = drawingRibbonPanelCtrls.AddButton(dynamoAddinButton.ButtonDefinition, true, true, "", false);  
                    }
                }
            }

            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
        public void Deactivate()
        {
            //the Deactivate 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

            try
            {
                m_userInterfaceEvents.OnResetCommandBars -= UserInterfaceEventsSink_OnResetCommandBarsEventDelegate;
                m_userInterfaceEvents.OnResetEnvironments -= UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate;

                UserInterfaceEventsSink_OnResetCommandBarsEventDelegate = null;
                UserInterfaceEventsSink_OnResetEnvironmentsEventDelegate = null;
                m_userInterfaceEvents = null;
                if (m_partSketchSlotRibbonPanel != null )
                {
                    m_partSketchSlotRibbonPanel.Delete();
                }

                //release inventor Application object
                Marshal.ReleaseComObject(m_inventorApplication);
                m_inventorApplication = null;

                GC.WaitForPendingFinalizers();
                GC.Collect();
            }
            catch(Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
        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;
                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
                Icon addSlotOptionIcon = new Icon(this.GetType(), "AddSlotOption.ico");
                Icon drawSlotIcon =  new Icon(this.GetType(), "DrawSlot.ico");
                Icon toggleSlotStateIcon = new Icon(this.GetType(), "ToggleSlotState.ico");

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

                //create the comboboxes
                m_slotWidthComboBoxDefinition = m_inventorApplication.CommandManager.ControlDefinitions.AddComboBoxDefinition("Slot Width", "Autodesk:SimpleAddIn:SlotWidthCboBox", CommandTypesEnum.kShapeEditCmdType, 100, addInCLSIDString, "Slot width", "Slot width", Type.Missing, Type.Missing, ButtonDisplayEnum.kDisplayTextInLearningMode);
                m_slotHeightComboBoxDefinition = m_inventorApplication.CommandManager.ControlDefinitions.AddComboBoxDefinition("Slot Height", "Autodesk:SimpleAddIn:SlotHeightCboBox", CommandTypesEnum.kShapeEditCmdType, 100, addInCLSIDString, "Slot height", "Slot height", Type.Missing, Type.Missing, ButtonDisplayEnum.kDisplayTextInLearningMode);

                //add some initial items to the comboboxes
                m_slotWidthComboBoxDefinition.AddItem("1 cm", 0);
                m_slotWidthComboBoxDefinition.AddItem("2 cm", 0);
                m_slotWidthComboBoxDefinition.AddItem("3 cm", 0);
                m_slotWidthComboBoxDefinition.AddItem("4 cm", 0);
                m_slotWidthComboBoxDefinition.AddItem("5 cm", 0);
                m_slotWidthComboBoxDefinition.ListIndex = 1;
                m_slotWidthComboBoxDefinition.ToolTipText = m_slotWidthComboBoxDefinition.Text;
                m_slotWidthComboBoxDefinition.DescriptionText = "Slot width: " + m_slotWidthComboBoxDefinition.Text;

                SlotWidthComboBox_OnSelectEventDelegate = new ComboBoxDefinitionSink_OnSelectEventHandler(SlotWidthComboBox_OnSelect);
                m_slotWidthComboBoxDefinition.OnSelect += SlotWidthComboBox_OnSelectEventDelegate;

                m_slotHeightComboBoxDefinition.AddItem("1 cm", 0);
                m_slotHeightComboBoxDefinition.AddItem("2 cm", 0);
                m_slotHeightComboBoxDefinition.AddItem("3 cm", 0);
                m_slotHeightComboBoxDefinition.AddItem("4 cm", 0);
                m_slotHeightComboBoxDefinition.AddItem("5 cm", 0);
                m_slotHeightComboBoxDefinition.ListIndex = 1;
                m_slotHeightComboBoxDefinition.ToolTipText = m_slotHeightComboBoxDefinition.Text;
                m_slotHeightComboBoxDefinition.DescriptionText = "Slot height: " + m_slotHeightComboBoxDefinition.Text;

                SlotHeightComboBox_OnSelectEventDelegate = new ComboBoxDefinitionSink_OnSelectEventHandler(SlotHeightComboBox_OnSelect);
                m_slotHeightComboBoxDefinition.OnSelect += SlotHeightComboBox_OnSelectEventDelegate;

                //create buttons
                m_addSlotOptionButton = new AddSlotOptionButton(
                    "Add Slot width/height", "Autodesk:SimpleAddIn:AddSlotOptionCmdBtn", CommandTypesEnum.kShapeEditCmdType,
                    addInCLSIDString, "Adds option for slot width/height",
                    "Add slot option", addSlotOptionIcon, addSlotOptionIcon, ButtonDisplayEnum.kDisplayTextInLearningMode);

                m_drawSlotButton = new DrawSlotButton(
                    "Draw Slot", "Autodesk:SimpleAddIn:DrawSlotCmdBtn", CommandTypesEnum.kShapeEditCmdType,
                    addInCLSIDString, "Create slot sketch graphics",
                    "Draw Slot", drawSlotIcon, drawSlotIcon, ButtonDisplayEnum.kDisplayTextInLearningMode);

                m_toggleSlotStateButton = new ToggleSlotStateButton(
                    "Toggle Slot State", "Autodesk:SimpleAddIn:ToggleSlotStateCmdBtn", CommandTypesEnum.kShapeEditCmdType,
                    addInCLSIDString, "Enables/Disables state of slot command",
                    "Toggle Slot State", toggleSlotStateIcon, toggleSlotStateIcon, ButtonDisplayEnum.kDisplayTextInLearningMode);

                //create the command category
                CommandCategory slotCmdCategory = m_inventorApplication.CommandManager.CommandCategories.Add("Slot", "Autodesk:SimpleAddIn:SlotCmdCat", addInCLSIDString);

                slotCmdCategory.Add(m_slotWidthComboBoxDefinition);
                slotCmdCategory.Add(m_slotHeightComboBoxDefinition);
                slotCmdCategory.Add(m_addSlotOptionButton.ButtonDefinition);
                slotCmdCategory.Add(m_drawSlotButton.ButtonDefinition);
                slotCmdCategory.Add(m_toggleSlotStateButton.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 slotCommandBar;
                        slotCommandBar = userInterfaceManager.CommandBars.Add("Slot", "Autodesk:SimpleAddIn:SlotToolbar", CommandBarTypeEnum.kRegularCommandBar, addInCLSIDString);

                        //add comboboxes to toolbar
                        slotCommandBar.Controls.AddComboBox(m_slotWidthComboBoxDefinition, 0);
                        slotCommandBar.Controls.AddComboBox(m_slotHeightComboBoxDefinition, 0);

                        //add buttons to toolbar
                        slotCommandBar.Controls.AddButton(m_addSlotOptionButton.ButtonDefinition, 0);
                        slotCommandBar.Controls.AddButton(m_drawSlotButton.ButtonDefinition, 0);
                        slotCommandBar.Controls.AddButton(m_toggleSlotStateButton.ButtonDefinition, 0);

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

                        //make this command bar accessible in the panel menu for the 2d sketch environment.
                        partSketchEnvironment.PanelBar.CommandBarList.Add(slotCommandBar);
                    }
                    //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 tabls associated with part ribbon
                        RibbonTabs ribbonTabs;
                        ribbonTabs = partRibbon.RibbonTabs;

                        RibbonTab partSketchRibbonTab;
                        partSketchRibbonTab = ribbonTabs["id_TabSketch"];

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

                        m_partSketchSlotRibbonPanel = ribbonPanels.Add("Slot", "Autodesk:SimpleAddIn:SlotRibbonPanel", "{DB59D9A7-EE4C-434A-BB5A-F93E8866E872}", "",  false);

                        //add controls to the slot panel
                        CommandControls partSketchSlotRibbonPanelCtrls;
                        partSketchSlotRibbonPanelCtrls = m_partSketchSlotRibbonPanel.CommandControls;

                        //add the combo boxes to the ribbon panel
                        CommandControl slotWidthCmdCboBoxCmdCtrl;
                        slotWidthCmdCboBoxCmdCtrl = partSketchSlotRibbonPanelCtrls.AddComboBox(m_slotWidthComboBoxDefinition, "", false);

                        CommandControl slotHeightCmdCboBoxCmdCtrl;
                        slotHeightCmdCboBoxCmdCtrl = partSketchSlotRibbonPanelCtrls.AddComboBox(m_slotHeightComboBoxDefinition, "", false);

                        //add the buttons to the ribbon panel
                        CommandControl drawSlotCmdBtnCmdCtrl;
                        drawSlotCmdBtnCmdCtrl = partSketchSlotRibbonPanelCtrls.AddButton(m_drawSlotButton.ButtonDefinition, false, true, "", false);

                        CommandControl slotOptionCmdBtnCmdCtrl;
                        slotOptionCmdBtnCmdCtrl = partSketchSlotRibbonPanelCtrls.AddButton(m_addSlotOptionButton.ButtonDefinition, false, true, "", false);

                        CommandControl toggleSlotStateCmdBtnCmdCtrl;
                        toggleSlotStateCmdBtnCmdCtrl = partSketchSlotRibbonPanelCtrls.AddButton(m_toggleSlotStateButton.ButtonDefinition, false,true, "", false);

                    }
                }

                MessageBox.Show ("To access the commands of the sample addin, activate a 2d sketch of a part \n document and select the \"AddInSlot\" toolbar within the panel menu");
            }
            catch(Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
示例#59
-1
        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            _addInSiteObject = addInSiteObject;

            // This 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.
            _Application = addInSiteObject.Application;

            AdnInventorUtilities.Initialize(_Application, this.GetType());

            ControlDefinitions ctrlDefs =
               _Application.CommandManager.ControlDefinitions;

            System.Drawing.Icon Icon32 = Resources.CGAUDemo_32x32;
            System.Drawing.Icon Icon16 = Resources.CGAUDemo_16x16;

            object IPictureDisp32 = PictureDispConverter.ToIPictureDisp(Icon32);
            object IPictureDisp16 = PictureDispConverter.ToIPictureDisp(Icon16);

            try
            {
                _MainControlButtonDef = 
                    ctrlDefs["Autodesk:AdskCGAUDemo:MainCtrl"] as ButtonDefinition;
            }
            catch
            {
                _MainControlButtonDef =
                    ctrlDefs.AddButtonDefinition(
                        "   Demo   \n   Control   ",
                        "Autodesk:AdskCGAUDemo:MainCtrl",
                        CommandTypesEnum.kEditMaskCmdType,
                        AdnInventorUtilities.AddInGuid,
                        "Client Graphics Demo AU",
                        "Client Graphics Demo AU",
                        IPictureDisp16,
                        IPictureDisp32,
                        ButtonDisplayEnum.kDisplayTextInLearningMode);
            }

            _MainControlButtonDef.OnExecute += 
                new ButtonDefinitionSink_OnExecuteEventHandler(MainControlButtonDef_OnExecute);

            if (firstTime)
            {
                Ribbon partRibbon = _Application.UserInterfaceManager.Ribbons["Part"];
                Ribbon asmRibbon = _Application.UserInterfaceManager.Ribbons["Assembly"];
                Ribbon dwgRibbon = _Application.UserInterfaceManager.Ribbons["Drawing"];

                AddToRibbon(partRibbon, AdnInventorUtilities.AddInGuid);
                AddToRibbon(asmRibbon, AdnInventorUtilities.AddInGuid);
                AddToRibbon(dwgRibbon, AdnInventorUtilities.AddInGuid);
            } 
        }
示例#60
-1
        /////////////////////////////////////////////////////////////
        // Constructor
        //
        /////////////////////////////////////////////////////////////
        public AdnInteractionManager(Inventor.Application Application)
        {
            _Application = Application;

            _InteractionEvents = null;

            _SelectedEntities = new List<System.Object>();

            _PreSelectFilters = new List<ObjectTypeEnum>();
        }