[SW PDM Add-in] Prevent Check-in / Create Reference dialogs

Programming and macros
Austin Schukar
Posts: 98
Joined: Thu Mar 18, 2021 11:19 am
Answers: 1
Location: St. Louis, MO
x 288
x 56

[SW PDM Add-in] Prevent Check-in / Create Reference dialogs

Unread post by Austin Schukar »

New to PDM API, and am working on a add-in to create custom references to legacy data. Everything seems to be working well, but I want to make the process a little quicker/fluid. Is there a way to prevent the dialog boxes from showing when a file has a newly created a reference?
image.png
by bnemec » Wed Jun 09, 2021 11:24 am
Can I assume you are checking in from the API? Or does the user initiate the check in then you have an add-in with a hook on before check in that does the custom refs?

The IEdmFile5::UnlockFile() function takes an options flag value. I haven't used this one specifically so I'm not sure which one you want to use. The times I've used flags the jargon is foreign to me so it's a bit of trial and error mixed with web searches on the terms to see what others have done.

http://help.solidworks.com/2019/english ... kFlag.html

hope that's more help than hindrance.

Edit: Sorry, I misunderstood. I thought it was the Reference File Dialog from the check in that was showing up. After a second look at the image I realized its the add custom ref that's showing the RFD. Can you share what code you have? Just looking at the example in the help, I'm wondering if you can try commenting out the .ShowDlg() call, wouldn't need the CreateTree then which is a requisite to ShowDlg(). Not sure this will work though, IIRC I've ran into situations where the next action fails if the ShowDlg is not called.

Code: Select all

                //Add the file that is copied to the clipboard as a custom reference to the selected file
                foreach (int ID in ppoFileIdArray)
                {
                    addCustRefs.AddReferencesClipboard(ID);
                    addCustRefs.CreateTree((int)EdmCreateReferenceFlags.Ecrf_Nothing);
                    addCustRefs.ShowDlg(this.Handle.ToInt32());
                    retCode = addCustRefs.CreateReferences();
                }
Go to full post
Austin
User avatar
bnemec
Posts: 1963
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2577
x 1427

Re: [SW PDM Add-in] Prevent Check-in / Create Reference dialogs

Unread post by bnemec »

Can I assume you are checking in from the API? Or does the user initiate the check in then you have an add-in with a hook on before check in that does the custom refs?

The IEdmFile5::UnlockFile() function takes an options flag value. I haven't used this one specifically so I'm not sure which one you want to use. The times I've used flags the jargon is foreign to me so it's a bit of trial and error mixed with web searches on the terms to see what others have done.

http://help.solidworks.com/2019/english ... kFlag.html

hope that's more help than hindrance.

Edit: Sorry, I misunderstood. I thought it was the Reference File Dialog from the check in that was showing up. After a second look at the image I realized its the add custom ref that's showing the RFD. Can you share what code you have? Just looking at the example in the help, I'm wondering if you can try commenting out the .ShowDlg() call, wouldn't need the CreateTree then which is a requisite to ShowDlg(). Not sure this will work though, IIRC I've ran into situations where the next action fails if the ShowDlg is not called.

Code: Select all

                //Add the file that is copied to the clipboard as a custom reference to the selected file
                foreach (int ID in ppoFileIdArray)
                {
                    addCustRefs.AddReferencesClipboard(ID);
                    addCustRefs.CreateTree((int)EdmCreateReferenceFlags.Ecrf_Nothing);
                    addCustRefs.ShowDlg(this.Handle.ToInt32());
                    retCode = addCustRefs.CreateReferences();
                }
Ulf Stockburger
Posts: 4
Joined: Thu Mar 25, 2021 8:20 am
Answers: 0
Location: Germany
x 3
Contact:

Re: [SW PDM Add-in] Prevent Check-in / Create Reference dialogs

Unread post by Ulf Stockburger »

Austin Schukar
Posts: 98
Joined: Thu Mar 18, 2021 11:19 am
Answers: 1
Location: St. Louis, MO
x 288
x 56

Re: [SW PDM Add-in] Prevent Check-in / Create Reference dialogs

Unread post by Austin Schukar »

bnemec wrote: Wed Jun 09, 2021 11:24 am Can I assume you are checking in from the API? Or does the user initiate the check in then you have an add-in with a hook on before check in that does the custom refs?

The IEdmFile5::UnlockFile() function takes an options flag value. I haven't used this one specifically so I'm not sure which one you want to use. The times I've used flags the jargon is foreign to me so it's a bit of trial and error mixed with web searches on the terms to see what others have done.

http://help.solidworks.com/2019/english ... kFlag.html

hope that's more help than hindrance.

Edit: Sorry, I misunderstood. I thought it was the Reference File Dialog from the check in that was showing up. After a second look at the image I realized its the add custom ref that's showing the RFD. Can you share what code you have? Just looking at the example in the help, I'm wondering if you can try commenting out the .ShowDlg() call, wouldn't need the CreateTree then which is a requisite to ShowDlg(). Not sure this will work though, IIRC I've ran into situations where the next action fails if the ShowDlg is not called.

Code: Select all

                //Add the file that is copied to the clipboard as a custom reference to the selected file
                foreach (int ID in ppoFileIdArray)
                {
                    addCustRefs.AddReferencesClipboard(ID);
                    addCustRefs.CreateTree((int)EdmCreateReferenceFlags.Ecrf_Nothing);
                    addCustRefs.ShowDlg(this.Handle.ToInt32());
                    retCode = addCustRefs.CreateReferences();
                }
Thanks for the quick response, Ben. I'm mimicking the portion of this example that adds the custom references.

https://help.solidworks.com/2021/englis ... Redirect=1

I'll fiddle with some dialogs and let you know!
Austin
Austin Schukar
Posts: 98
Joined: Thu Mar 18, 2021 11:19 am
Answers: 1
Location: St. Louis, MO
x 288
x 56

Re: [SW PDM Add-in] Prevent Check-in / Create Reference dialogs

Unread post by Austin Schukar »

Ulf Stockburger wrote: Wed Jun 09, 2021 11:39 am Maybe this will help you. https://github.com/erppdm/SWPAW/tree/ma ... les/Demo09

BiI SAP-PDM
Thanks for this resource. I will give it a look! Looks a bit different than mine.

Code: Select all

                IEdmAddCustomRefs addCustRefs = (IEdmAddCustomRefs)vault.CreateUtility(EdmUtility.EdmUtil_AddCustomRefs);
                Int32[] ppoFileIdArray = new Int32[parentFilePaths.Count];
                IEdmFile5 file = null;
                IEdmFolder5 parentFolder = null;
                int i = 0;
                foreach (string FileName in parentFilePaths)
                {
                    file = vault.GetFileFromPath(FileName, out parentFolder);
                    if (!file.IsLocked)
                    {
                        file.LockFile(parentFolder.ID, poCmd.mlParentWnd, (int)EdmLockFlag.EdmLock_Simple);
                    }
                    ppoFileIdArray[i] = file.ID;
                    i++;
                }
                Boolean retCode = false;

                //Add the file that is copied to the clipboard as a custom reference to the selected file
                foreach (int ID in ppoFileIdArray)
                {
                    addCustRefs.AddReferencesClipboard(ID);
                    addCustRefs.CreateTree((int)EdmCreateReferenceFlags.Ecrf_Nothing);
                    //addCustRefs.ShowDlg(poCmd.mlParentWnd);
                    retCode = addCustRefs.CreateReferences();
                }

                // Check in the file
                file.UnlockFile(poCmd.mlParentWnd, "Custom reference added");
Austin
Austin Schukar
Posts: 98
Joined: Thu Mar 18, 2021 11:19 am
Answers: 1
Location: St. Louis, MO
x 288
x 56

Re: [SW PDM Add-in] Prevent Check-in / Create Reference dialogs

Unread post by Austin Schukar »

Feeling a bit silly. My code literally tells me what it's doing, and I just glazed over it.

Commented the two dialogs and now they don't show. Maybe I should take a break from debugging...

Code: Select all

                //Add the file that is copied to the clipboard as a custom reference to the selected file
                foreach (int ID in ppoFileIdArray)
                {
                    addCustRefs.AddReferencesClipboard(ID);
                    addCustRefs.CreateTree((int)EdmCreateReferenceFlags.Ecrf_Nothing);
                    //addCustRefs.ShowDlg(poCmd.mlParentWnd);
                    retCode = addCustRefs.CreateReferences();
                }

                // Check in the file
                file.UnlockFile(poCmd.mlParentWnd, "Custom reference added");

                //Display current custom file references
                //retCode = addCustRefs.ShowEditReferencesDlg(ref ppoFileIdArray, poCmd.mlParentWnd);

Thanks again for the suggestion, Ben. Sometimes I have to ask stupid questions to get smart answers.

Marked your suggestion correct as it was the easiest, but I think Ulf's was an excellent suggestion as well. I just am too lazy to implement a different method.
Austin
User avatar
bnemec
Posts: 1963
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2577
x 1427

Re: [SW PDM Add-in] Prevent Check-in / Create Reference dialogs

Unread post by bnemec »

Austin Schukar wrote: Wed Jun 09, 2021 12:04 pm Feeling a bit silly. My code literally tells me what it's doing, and I just glazed over it.

Commented the two dialogs and now they don't show. Maybe I should take a break from debugging...

Thanks again for the suggestion, Ben. Sometimes I have to ask stupid questions to get smart answers.

Marked your suggestion correct as it was the easiest, but I think Ulf's was an excellent suggestion as well. I just am too lazy to implement a different method.
Those are my lines! Happens more than I want to admit. That's why I have been told about rubber duck debugging buddy.

https://en.wikipedia.org/wiki/Rubber_duck_debugging
Austin Schukar
Posts: 98
Joined: Thu Mar 18, 2021 11:19 am
Answers: 1
Location: St. Louis, MO
x 288
x 56

Re: [SW PDM Add-in] Prevent Check-in / Create Reference dialogs

Unread post by Austin Schukar »

LOL. I have not heard of that, but am glad that I now know about it.
Austin
Post Reply