示例#1
0
        private void AddMainButtonToRibbon()
        {
            ControlDefinitions ctrlDefs = InventorApp.CommandManager.ControlDefinitions;
            var  currAssembly           = System.Reflection.Assembly.GetExecutingAssembly();
            Icon icon32        = Resources.shaft_32x32;
            Icon icon16        = Resources.shaft_16x16;
            var  pictureDisp32 = PictureDispConverter.ToIPictureDisp(icon32);
            var  pictureDisp16 = PictureDispConverter.ToIPictureDisp(icon16);

            this.mainButtonDefinition = ctrlDefs.AddButtonDefinition(
                DisplayName: "Shaft",
                InternalName: "Autodesk:InventorShaftGenerator:MainCtrl",
                Classification: CommandTypesEnum.kEditMaskCmdType,
                ClientId: AdnInventorUtilities.AddInGuid,
                ToolTipText: "Shaft Component Generator",
                StandardIcon: pictureDisp16,
                LargeIcon: pictureDisp32
                );
            this.mainButtonDefinition.OnExecute += OnMainButtonExecute;

            Ribbon    assebmlyRibbon = InventorApp.UserInterfaceManager.Ribbons["Assembly"];
            RibbonTab asmDesingTab   = assebmlyRibbon.RibbonTabs["id_TabDesign"];

            var panel3 = asmDesingTab.RibbonPanels.Add(
                DisplayName: "Tools Panel",
                InternalName: "Autodesk:InventorShaftGenerator:PartToolsPanel",
                ClientId: AdnInventorUtilities.AddInGuid);

            panel3.CommandControls.AddButton(
                ButtonDefinition: this.mainButtonDefinition,
                UseLargeIcon: true
                );
        }
    // Converts an image into an IPictureDisp.
    public static stdole.IPictureDisp ToIPictureDisp(Image image)
    {
        Bitmap bitmap = (image is Bitmap) ? (Bitmap)image : new Bitmap(image);

        PICTDESC.Bitmap pictBit = new PICTDESC.Bitmap(bitmap);
        return(PictureDispConverter.OleCreatePictureIndirect(pictBit, ref iPictureDispGuid, true));
    }
示例#3
0
        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);
            }
        }
示例#4
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Creates ClientFeature that holds our dimension graphics
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        void CreateClientFeature(Point point1, Point point2, Point dimText, Vector normal)
        {
            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            Document document = InvApp.ActiveDocument;

            ComponentDefinition compDef =
                AdnInventorUtilities.GetCompDefinition(document);

            object features =
                AdnInventorUtilities.GetProperty(compDef, "Features");

            ClientFeatures clientFeatures =
                AdnInventorUtilities.GetProperty(features, "ClientFeatures")
                as ClientFeatures;

            ClientFeatureDefinition cfDef =
                clientFeatures.CreateDefinition(
                    "Dimension Feature",
                    null, null, null);

            ClientFeature clientFeature =
                clientFeatures.Add(cfDef, AdnInventorUtilities.AddInGuid);

            cfDef = clientFeature.Definition;

            cfDef.HighlightClientGraphicsWithFeature = true;

            NativeBrowserNodeDefinition nodeDef =
                clientFeature.BrowserNode.BrowserNodeDefinition as NativeBrowserNodeDefinition;

            stdole.IPictureDisp pic =
                PictureDispConverter.ToIPictureDisp(Resources.dimlinear);

            ClientNodeResource res =
                document.BrowserPanes.ClientNodeResources.Add(
                    AdnInventorUtilities.AddInGuid,
                    document.BrowserPanes.ClientNodeResources.Count + 1,
                    pic);

            nodeDef.OverrideIcon = res;

            _clientGraphicsMng.SetGraphicsSource(clientFeature);

            DrawDimension(point1, point2, dimText, normal);

            _clientGraphicsMng.UpdateView();
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Description: Displays a PointGraphics using custom bitmap image.
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        static public void PointGraphicsDemo()
        {
            PartDocument doc =
                AdnInventorUtilities.InvApplication.ActiveDocument
                as PartDocument;

            string clientId = "{Add-in Guid}";

            ClientGraphics   graphics = null;
            GraphicsDataSets dataSets = null;

            try
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection[clientId];
                dataSets = doc.GraphicsDataSetsCollection[clientId];
            }
            catch
            {
                graphics = doc.ComponentDefinition.ClientGraphicsCollection.Add(clientId);
                dataSets = doc.GraphicsDataSetsCollection.Add(clientId);
            }

            GraphicsNode node = graphics.AddNode(graphics.Count + 1);

            GraphicsCoordinateSet coordSet = dataSets.CreateCoordinateSet(dataSets.Count + 1);

            double[] coords = new double[]
            {
                5.0, 0.0, 0.0
            };

            coordSet.PutCoordinates(ref coords);

            GraphicsImageSet imageSet = dataSets.CreateImageSet(dataSets.Count + 1);

            stdole.IPictureDisp image =
                PictureDispConverter.ToIPictureDisp(Resources.PointImage);

            imageSet.Add(1, image, null, -1, -1);

            PointGraphics pointGraphPrimitive = node.AddPointGraphics();

            pointGraphPrimitive.CoordinateSet = coordSet;
            pointGraphPrimitive.SetCustomImage(imageSet, 1);

            doc.Views[1].Update();
        }
示例#6
0
        private void AddMenuItem(Office.CommandBar imenu)
        {
            try
            {
                Application.ScreenUpdating = true;
                //Application.rev
                if (imenu == null)
                {
                    _oCommand = Application.CommandBars.Add("TVC-QD", Office.MsoBarPosition.msoBarTop, Type.Missing, Type.Missing);
                    //_oCommand.Name = "TVC-QD";
                    _oCommand.Visible = true;
                }
                else
                {
                    _oCommand = imenu;
                }

                _oPop         = (Office.CommandBarPopup)_oCommand.Controls.Add(Office.MsoControlType.msoControlPopup, Type.Missing, Type.Missing, 1, true);
                _oPop.Caption = "TVC-QD";
                _oPop.Enabled = true;


                _oBtn = (Office.CommandBarButton)_oPop.CommandBar.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, 1, true);
                _oBtn.DescriptionText = _oBtn.Caption = "Balance";
                _oBtn.Click          += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(_oBtn_Click);
                _oBtn.Picture         = PictureDispConverter.ToIPictureDisp(Properties.Resources.blance);

                _oBtnComment         = (Office.CommandBarButton)_oPop.CommandBar.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, 1, true);
                _oBtnComment.Caption = "Comment";
                _oBtnComment.Click  += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(_oBtnComment_Click);
                _oBtnComment.Picture = PictureDispConverter.ToIPictureDisp(Properties.Resources.comment);

                _oBtnAnalysis         = (Office.CommandBarButton)_oPop.CommandBar.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, 1, true);
                _oBtnAnalysis.Caption = "Analysis";
                _oBtnAnalysis.Click  += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(_oBtnAnalysis_Click);
                _oBtnAnalysis.Picture = PictureDispConverter.ToIPictureDisp(Properties.Resources.analysis);

                _oBtnConnect         = (Office.CommandBarButton)_oPop.CommandBar.Controls.Add(Office.MsoControlType.msoControlButton, Type.Missing, Type.Missing, 1, true);
                _oBtnConnect.Caption = "Connection";
                _oBtnConnect.Click  += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(_oBtnConnect_Click);
                _oBtnConnect.Picture = PictureDispConverter.ToIPictureDisp(Properties.Resources.connect);
            }
            catch (Exception ex)
            {
                BUS.CommonControl.AddLog("ErroLog", __documentDirectory + "\\Log", "Addin : " + ex.Message + "\n\t" + ex.Source + "\n\t" + ex.StackTrace);
            }
        }
 // Converts an Icon into an IPictureDisp.
 public static stdole.IPictureDisp ToIPictureDisp(Icon icon)
 {
     PICTDESC.Icon pictIcon = new PICTDESC.Icon(icon);
     return(PictureDispConverter.OleCreatePictureIndirect(pictIcon, ref iPictureDispGuid, true));
 }
示例#8
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Simple example using Inventor API directly
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        public static void ClientFeatureDemo()
        {
            string clientId = AdnInventorUtilities.AddInGuid;

            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            Document document = InvApp.ActiveDocument;

            // We will use late binding to retrieve ClientFeatures collection,
            // so we dont need to write specific code for PartDocument and
            // AssemblyDocument
            ComponentDefinition compDef =
                AdnInventorUtilities.GetCompDefinition(document);

            object features =
                AdnInventorUtilities.GetProperty(compDef, "Features");

            ClientFeatures clientFeatures =
                AdnInventorUtilities.GetProperty(features, "ClientFeatures")
                as ClientFeatures;

            ClientFeatureDefinition cfDef =
                clientFeatures.CreateDefinition("Graphics Feature", null, null, null);

            ClientFeature clientFeature =
                clientFeatures.Add(cfDef, clientId);

            NativeBrowserNodeDefinition nodeDef =
                clientFeature.BrowserNode.BrowserNodeDefinition as NativeBrowserNodeDefinition;

            stdole.IPictureDisp pic =
                PictureDispConverter.ToIPictureDisp(Resources.PointImage);

            ClientNodeResource res =
                document.BrowserPanes.ClientNodeResources.Add(
                    clientId,
                    document.BrowserPanes.ClientNodeResources.Count + 1,
                    pic);

            nodeDef.OverrideIcon = res;

            cfDef = clientFeature.Definition;

            cfDef.HighlightClientGraphicsWithFeature = true;

            GraphicsDataSets sets =
                cfDef.GraphicsDataSetsCollection.Add2(clientId, true);

            GraphicsCoordinateSet coordSet = sets.CreateCoordinateSet(1);

            double[] coords = new double[]
            {
                0.0, 0.0, 0.0,
                5.0, 0.0, 0.0,
                2.5, 5.0, 0.0
            };

            coordSet.PutCoordinates(ref coords);

            ClientGraphics cg =
                cfDef.ClientGraphicsCollection.Add(clientId);

            GraphicsNode node = cg.AddNode(1);

            node.RenderStyle = document.RenderStyles["Green (Flat)"];

            TriangleGraphics primitive = node.AddTriangleGraphics();

            primitive.CoordinateSet = coordSet;

            InvApp.ActiveView.Update();
        }
示例#9
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Example using the AdnClientGraphicsManager
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        public static void DemoMng()
        {
            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            Document document = InvApp.ActiveDocument;

            // We will use late binding to retrieve ClientFeatures collection,
            // so we dont need to write specific code for PartDocument and
            // AssemblyDocument
            ComponentDefinition compDef =
                AdnInventorUtilities.GetCompDefinition(document);

            object features =
                AdnInventorUtilities.GetProperty(compDef, "Features");

            ClientFeatures clientFeatures =
                AdnInventorUtilities.GetProperty(features, "ClientFeatures")
                as ClientFeatures;

            ClientFeatureDefinition cfDef =
                clientFeatures.CreateDefinition("Graphics Feature", null, null, null);

            ClientFeature clientFeature =
                clientFeatures.Add(cfDef, AdnInventorUtilities.AddInGuid);

            cfDef = clientFeature.Definition;

            cfDef.HighlightClientGraphicsWithFeature = true;

            NativeBrowserNodeDefinition nodeDef =
                clientFeature.BrowserNode.BrowserNodeDefinition as NativeBrowserNodeDefinition;

            stdole.IPictureDisp pic =
                PictureDispConverter.ToIPictureDisp(Resources.PointImage);

            ClientNodeResource res =
                document.BrowserPanes.ClientNodeResources.Add(
                    AdnInventorUtilities.AddInGuid,
                    document.BrowserPanes.ClientNodeResources.Count + 1,
                    pic);

            nodeDef.OverrideIcon = res;

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

            clientGraphicsMng.SetGraphicsSource(clientFeature);

            Random rd = new Random();

            TriangleGraphics graphics = clientGraphicsMng.DrawTriangle(
                new double[] { rd.Next(0, 10), rd.Next(0, 10), rd.Next(0, 10) },
                new double[] { rd.Next(0, 10), rd.Next(0, 10), rd.Next(0, 10) },
                new double[] { rd.Next(0, 10), rd.Next(0, 10), rd.Next(0, 10) },
                null);

            int id = clientGraphicsMng.WorkingGraphics.GetDataSetFreeId();

            GraphicsColorSet colorSet =
                clientGraphicsMng.WorkingGraphics.GraphicsDataSets.CreateColorSet(id);

            colorSet.Add(1, (byte)rd.Next(0, 255), (byte)rd.Next(0, 255), (byte)rd.Next(0, 255));

            graphics.ColorSet = colorSet;

            clientGraphicsMng.UpdateView();
        }
        private void EnsureSolutionsModule()
        {
            try
            {
                //Declarations
                Outlook.Folder solutionRoot;
                Outlook.Folder solutionCalendar;
                Outlook.Folder solutionContacts;
                Outlook.Folder solutionTasks;
                bool           firstRun        = false;
                Outlook.Folder rootStoreFolder =
                    Application.Session.DefaultStore.GetRootFolder()
                    as Outlook.Folder;
                //If solution root folder does not exist, create it
                //Note that solution root
                //could also be in PST or custom store
                try
                {
                    solutionRoot =
                        rootStoreFolder.Folders["Solution Demo"]
                        as Outlook.Folder;
                }
                catch
                {
                    firstRun = true;
                }

                if (firstRun == true)
                {
                    solutionRoot =
                        rootStoreFolder.Folders.Add("Solution Demo",
                                                    Outlook.OlDefaultFolders.olFolderInbox)
                        as Outlook.Folder;
                    solutionCalendar = solutionRoot.Folders.Add(
                        "Solution Calendar",
                        Outlook.OlDefaultFolders.olFolderCalendar)
                                       as Outlook.Folder;
                    solutionContacts = solutionRoot.Folders.Add(
                        "Solution Contacts",
                        Outlook.OlDefaultFolders.olFolderContacts)
                                       as Outlook.Folder;
                    solutionTasks = solutionRoot.Folders.Add(
                        "Solution Tasks",
                        Outlook.OlDefaultFolders.olFolderTasks)
                                    as Outlook.Folder;
                }
                else
                {
                    solutionRoot =
                        rootStoreFolder.Folders["Solution Demo"]
                        as Outlook.Folder;
                    solutionCalendar = solutionRoot.Folders[
                        "Solution Calendar"]
                                       as Outlook.Folder;
                    solutionContacts = solutionRoot.Folders[
                        "Solution Contacts"]
                                       as Outlook.Folder;
                    solutionTasks = solutionRoot.Folders[
                        "Solution Tasks"]
                                    as Outlook.Folder;
                }
                //Get the icons for the solution
                stdole.StdPicture rootPict =
                    PictureDispConverter.ToIPictureDisp(
                        Properties.Resources.BRIDGE)
                    as stdole.StdPicture;
                stdole.StdPicture calPict =
                    PictureDispConverter.ToIPictureDisp(
                        Properties.Resources.umbrella)
                    as stdole.StdPicture;
                stdole.StdPicture contactsPict =
                    PictureDispConverter.ToIPictureDisp(
                        Properties.Resources.group)
                    as stdole.StdPicture;
                stdole.StdPicture tasksPict =
                    PictureDispConverter.ToIPictureDisp(
                        Properties.Resources.SUN)
                    as stdole.StdPicture;
                //Set the icons for solution folders
                solutionRoot.SetCustomIcon(rootPict);
                solutionCalendar.SetCustomIcon(calPict);
                solutionContacts.SetCustomIcon(contactsPict);
                solutionTasks.SetCustomIcon(tasksPict);
                //Obtain a reference to the SolutionsModule
                Outlook.Explorer explorer = Application.ActiveExplorer();
                solutionsModule =
                    explorer.NavigationPane.Modules.GetNavigationModule(
                        Outlook.OlNavigationModuleType.olModuleSolutions)
                    as Outlook.SolutionsModule;
                //Add the solution and hide folders in default modules
                solutionsModule.AddSolution(solutionRoot,
                                            Outlook.OlSolutionScope.olHideInDefaultModules);
                //The following code sets the position and visibility
                //of the SolutionsModule
                if (solutionsModule.Visible == false)
                {
                    //Set Visibile to true
                    solutionsModule.Visible = true;
                }
                if (solutionsModule.Position != 5)
                {
                    //Move SolutionsModule to Position = 5
                    solutionsModule.Position = 5;
                }
                //Create instance variable for Outlook.NavigationPane
                Outlook.NavigationPane navPane = explorer.NavigationPane;
                if (navPane.DisplayedModuleCount != 5)
                {
                    //Ensure that Solutions Module button is large
                    navPane.DisplayedModuleCount = 5;
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.Message);
            }
        }