Esempio n. 1
0
        /////////////////////////////////////////////////////////////
        // Use: Prompts user to locate thread sketch template, if
        //      not found automatically.
        /////////////////////////////////////////////////////////////
        private string GetThreadTemplatePath()
        {
            try
            {
                string pathInit =
                    Assembly.GetExecutingAssembly().Location;

                FileInfo fi = new FileInfo(pathInit);

                Inventor.FileDialog fileDlg = null;
                _Application.CreateFileDialog(out fileDlg);

                fileDlg.Filter           = "Inventor Parts (*.ipt)|*.ipt";
                fileDlg.FilterIndex      = 1;
                fileDlg.DialogTitle      = "Select Thread Template";
                fileDlg.InitialDirectory =
                    fi.DirectoryName + "\\Thread Templates";
                fileDlg.FileName                   = "BSW Template.ipt";
                fileDlg.MultiSelectEnabled         = false;
                fileDlg.OptionsEnabled             = false;
                fileDlg.CancelError                = true;
                fileDlg.SuppressResolutionWarnings = true;

                fileDlg.ShowOpen();

                return(fileDlg.FileName);
            }
            catch
            {
                return(string.Empty);
            }
        }
Esempio n. 2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text.Length > 0)
            {
                PartDocument oDoc = (PartDocument)mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject,
                                                                     mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject),
                                                                     true);

                //Author property is contained in "Inventor Summary Information" Set
                PropertySet oPropertySet = oDoc.PropertySets["{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"];

                //Using Inventor.Property to avoid confusion
                Inventor.Property oProperty = oPropertySet["Author"];

                oProperty.Value = TextBox1.Text;

                //Get "Inventor User Defined Properties" set
                oPropertySet = oDoc.PropertySets["{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"];

                //Create new property
                oProperty = oPropertySet.Add("Parts R Us", "Supplier", null);

                //Save document, prompt user for filename
                FileDialog oDLG = null;
                mApp.CreateFileDialog(out oDLG);

                oDLG.FileName    = @"C:\Temp\NewPart.ipt";
                oDLG.Filter      = "Inventor Files (*.ipt)|*.ipt";
                oDLG.DialogTitle = "Save Part";

                oDLG.ShowSave();

                if (oDLG.FileName != "")
                {
                    oDoc.SaveAs(oDLG.FileName, false);
                    oDoc.Close(true);
                }
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Use: Displays Open Dialog and returns filename selected by user
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        public static string ShowOpenDialog(string title, string filter)
        {
            try
            {
                Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

                string pathInit = InvApp.DesignProjectManager.ActiveDesignProject.WorkspacePath;

                if (pathInit == string.Empty)
                {
                    pathInit = System.Environment.GetFolderPath(
                        System.Environment.SpecialFolder.Desktop);
                }

                System.IO.FileInfo fi = new System.IO.FileInfo(pathInit);

                Inventor.FileDialog fileDlg = null;
                InvApp.CreateFileDialog(out fileDlg);

                fileDlg.Filter                     = filter;
                fileDlg.FilterIndex                = 1;
                fileDlg.DialogTitle                = title;
                fileDlg.InitialDirectory           = fi.DirectoryName;
                fileDlg.FileName                   = "";
                fileDlg.MultiSelectEnabled         = false;
                fileDlg.OptionsEnabled             = false;
                fileDlg.CancelError                = true;
                fileDlg.SuppressResolutionWarnings = true;

                fileDlg.ShowOpen();

                return(fileDlg.FileName);
            }
            catch
            {
                return(string.Empty);
            }
        }
Esempio n. 4
0
        //Add an occurrence, prompts user to select an existing Inventor Part or Assembly
        private void Button3_Click(object sender, EventArgs e)
        {
            if (((mApp.ActiveDocument != null)))
            {
                if ((mApp.ActiveDocument.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject))
                {
                    AssemblyDocument oAsm = mApp.ActiveDocument as AssemblyDocument;

                    FileDialog oDLG = null;
                    mApp.CreateFileDialog(out oDLG);

                    //oDLG.FileName = "C:\Temp\"
                    oDLG.Filter      = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt";
                    oDLG.DialogTitle = "Insert occurrence";

                    oDLG.ShowOpen();

                    if ((!string.IsNullOrEmpty(oDLG.FileName)))
                    {
                        Matrix pos     = mApp.TransientGeometry.CreateMatrix();
                        var    oNewOcc = oAsm.ComponentDefinition.Occurrences.Add(oDLG.FileName, pos);


                        mApp.ActiveView.Update();
                    }
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("An Assembly document must be active...", "Error");
                    return;
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("An Assembly document must be active...", "Error");
                return;
            }
        }