AnsweredAssumed Answered

Pop Up DataCard when file created (similar to template option) C#

Question asked by Sean Donnelly on Apr 19, 2017

Hello, I have had a few answers so far that have really helped me learn this stuff so thank you all for the assistance! This is a great community and I can't wait to contribute myself sometime.

 

To the point... I am using a menu command API to right click a solidworks file, grab the variables, search for a similar file with a different extension, grab a variable from there and create a NEW file from a template file and check it in. This new file currently receives all of the values and works great! The code is below. My issue, however, is that I am not sure how to implement the IEdmCardView63 (I've seen the example, but that's with an open windows form and not a class library).

 

I want a popup window to appear (similar to how this can be done with a template) after all of the variables were added, but before the file is checked in. This way, the user can add any field if it is blank or modify a field if they choose. When the user selects "OK" or "Save", the form closes, saves the updates to the filecard, and checks in the file.

 

I hope this made sense. Thanks again!

 

public void OnCmd(ref EdmCmd poCmd, ref Array ppoData)

        {

            if (poCmd.meCmdType == EdmCmdType.EdmCmd_Menu) //This makes sure the addin was called on a menu right click 

            {

                if (poCmd.mlCmdID == 100) //This makes sure the menu command ID was 100, which means your addin was the one called 

                {

                    //Let's get moving, it's our turn! 

                    IEdmVault12 myVault = (IEdmVault12)poCmd.mpoVault; //Cast the vault to an Iedmvault12 object for latest functionality 

                    string Mymessage = null;//instantiate a string message 

                    //string StrID = null;//instantiate the ID of the object 

                    if ((((EdmCmdData)ppoData.GetValue(0)).mlObjectID1) != 0) //mlObjectID1 will be 0 if a folder was selected and the ID of the file if a file was selected during a menu command 

                    {

                        //Mymessage = Mymessage + "File: (ID=";

                        IEdmFile5 myfile = (IEdmFile10)myVault.GetObject(EdmObjectType.EdmObject_File, (((EdmCmdData)ppoData.GetValue(0)).mlObjectID1));//Get the file object 

 

 

                        string fileNoExt = Path.GetFileNameWithoutExtension(myfile.Name);

                       

                        IEdmEnumeratorVariable10 myvars = default(IEdmEnumeratorVariable10); //Set the enumeratorvariable object 

                        myvars = (IEdmEnumeratorVariable10)myfile.GetEnumeratorVariable(); //Cast the enumeratorvariable object to the file 

                        object CreatedBy = null; //Create a variable to hold the model no. 

                        object Desc1 = null;

                        object Desc2 = null;

                        object Rev = null;

 

 

                        myvars.GetVar("CreatedBy", "@", out CreatedBy); //Use the GetVar method 

                        myvars.GetVar("CAD_Description", "@", out Desc1);

                        myvars.GetVar("CAD_Description1", "@", out Desc2);

                        myvars.GetVar("CAD_Revision", "@", out Rev);

 

 

                        myvars.CloseFile(false); //Always close the file when done accessing card variables to avoid runtime errors 

                                                 //Mymessage = Mymessage + "File ID: " + myfile.ID + System.Environment.NewLine; //Create a message with the File ID 

 

 

                        Mymessage = Mymessage + "CreatedBy: " + CreatedBy + System.Environment.NewLine; //Add the model no. variable 

                        Mymessage = Mymessage + "Description: " + Desc1 + System.Environment.NewLine;

                        Mymessage = Mymessage + "Description1: " + Desc2 + System.Environment.NewLine;

                        Mymessage = Mymessage + "Revision: " + Rev + System.Environment.NewLine;

 

 

                        MessageBox.Show(Mymessage); //Show the message box! 

 

 

                        MessageBox.Show("Get template path");

                        string templPath = @"C:\SeanVault\Templates\template.item.cvd";

                        string newPath = @"C:\SeanVault\Inspection Files";

                        string filename = fileNoExt + " Rev " + Rev.ToString() + ".insp";

                        IEdmFile5 templateFile = default(IEdmFile5);

                        IEdmFolder5 srcFolder = null;

                        templateFile = myVault.GetFileFromPath(templPath, out srcFolder);

 

 

                        MessageBox.Show("Get destination path");

                        IEdmFolder5 destFolder = default(IEdmFolder5);

                        destFolder = myVault.GetFolderFromPath(newPath);

                        if (destFolder == null)

                            return;

 

 

 

 

                        int fileID = 0;

                        fileID = destFolder.CopyFile(templateFile.ID, srcFolder.ID, 0, filename, (int)EdmCopyFlag.EdmCpy_Simple);

                       

                        Interaction.MsgBox("Copied file successfully to new file with ID, " + fileID);

 

 

                                                                       

                        IEdmFile5 newFile = default(IEdmFile5);

                        IEdmFile5 itemFile = default(IEdmFile5);

 

 

                        newPath = newPath + "\\" + filename;

 

 

                        //Search for file with .item extension

                        IEdmSearch5 Search = default(IEdmSearch5);

                        Search = (IEdmSearch5)myVault.CreateUtility(EdmUtility.EdmUtil_Search);

 

 

                        Search.FindFiles = true;

                        //Search.StartFolderID = 102; //Regular Items ID

                        Search.FileName = fileNoExt + ".item";

                        IEdmSearchResult5 Result = default(IEdmSearchResult5);

                       

 

 

                        Result = Search.GetFirstResult();

                        object StockingType = null; //Create a variable to hold the model no.

                        if (Result != null)

                        {

                            MessageBox.Show("Result exists. Begin! Path = " + Result.Path);

                            itemFile = myVault.GetFileFromPath(Result.Path, out srcFolder);

                            IEdmEnumeratorVariable10 itemVars = default(IEdmEnumeratorVariable10); //Set the enumeratorvariable object 

                            itemVars = (IEdmEnumeratorVariable10)itemFile.GetEnumeratorVariable(); //Cast the enumeratorvariable object to the file 

                            //breaks

                            itemVars.GetVar("ITEM_StockingType", "", out StockingType); //Use the GetVar method 

                            //itemVars.GetVar("CAD_Description", "@", out Desc1);

                            //itemVars.GetVar("CAD_Description1", "@", out Desc2);

                            //itemVars.GetVar("CAD_Revision", "@", out Rev);

                            MessageBox.Show("5");

                            myvars.CloseFile(false); //Always close the file when done accessing card variables to avoid runtime errors 

                                                     //Mymessage = Mymessage + "File ID: " + myfile.ID + System.Environment.NewLine; //Create a message with the File ID 

                        }

 

 

                        newFile = myVault.GetFileFromPath(newPath, out srcFolder);

                        //update variables

                        IEdmEnumeratorVariable10 myNewVars = default(IEdmEnumeratorVariable10); //Set the enumeratorvariable object 

                        myNewVars = (IEdmEnumeratorVariable10)newFile.GetEnumeratorVariable(); //Cast the enumeratorvariable object to the file 

 

 

                        MessageBox.Show(Rev.ToString() + "," + StockingType.ToString());

 

 

                        myNewVars.SetVar("ITEM_RevisionNumber", "", Rev.ToString());

                        myNewVars.SetVar("ITEM_DescriptionLine1", "", Desc1.ToString());

                        myNewVars.SetVar("ITEM_DescriptionLine2", "", Desc2.ToString());

 

 

                        if (StockingType.ToString() != null)

                        {

                            myNewVars.SetVar("ITEM_StockingType", "", StockingType.ToString());

                        }

 

 

                        myvars.CloseFile(false); //Always close the file when done accessing card variables to avoid runtime errors 

                                                 //Mymessage = Mymessage + "File ID: " + myfile.ID + System.Environment.NewLine; //Create a message with the File ID 

 

 

                       

                        //Check-in new file

                        newFile.UnlockFile(0,"Created and checked-in with Sean's API.");

 

 

                        //myvars.SetVar("CAD_Weight","@", "This Worked");

 

 

                        //Mymessage = Mymessage + "File name: " + ((EdmCmdData)ppoData.GetValue(0)).mbsStrData1 + System.Environment.NewLine; //Add the file name 

 

 

                    }

                }

            }

        }

Outcomes