Hello everyone!
To explain the context, I'm currently trying to extract and archive files via a PDM script as seen in the image:
Here are the details of the code:
Option Explicit
Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
swApp.Visible = True
sAddinName = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS PDM\PDMSW.dll"
status = swApp.LoadAddIn(sAddinName)
modelPath = "<Filepath>"
Set swDocSpecification = swApp.GetOpenDocSpec(modelPath)
swDocSpecification.DocumentType = swDocPART
swDocSpecification.ReadOnly = False
swDocSpecification.Silent = True
swDocSpecification.ConfigurationName = ""
swDocSpecification.DisplayState = ""
swDocSpecification.IgnoreHiddenComponents = True
Set swModel = swApp.OpenDoc7(swDocSpecification)
errors = swDocSpecification.Error
Set swModel = swApp.ActiveDoc
Dim swPdmVault As IEdmVault5
Const VAULT_NAME As String = "XXXXXXXXXXXX"
Dim swPdmFile As IEdmFile5
Set swPdmVault = New EdmVault5
swPdmVault.LoginAuto VAULT_NAME, 0
Set swPdmFile = swPdmVault.GetFileFromPath(modelPath)
Dim swPdmFolder As IEdmFolder5
Set swPdmFolder = swPdmVault.GetFolderFromPath(Left(modelPath, InStrRev(modelPath, "\")))
swModel.ForceReleaseLocks
swPdmFile.LockFile swPdmFolder.ID, 0
End Sub
I would like to point out that to execute this script I use a PDM task that works via the "SOLIDWORKS Task-Add-in" add-in in which I have also added the .dll to use the PDM functions extract, archive, etc.
My problem is that this macro works very well when I run it from SolidWorks (by replacing the path of the file in question of course ...) directly but gives me the following error when I run it via the PDM script...
Since there is no indication of why the script is not working properly, I appeal to your knowledge!!
Has anyone ever encountered this problem or an idea? Because honestly I have gone through all my ideas ....
Thank you very much in advance for those who will help me and have a good day :)
Hello
That way, I'd tend to say that it crashes in PDM (I guess it's in Windows Explorer) since the script basically calls SW functions (hence the fact that it works well in SW).
Therefore, it would be necessary to add functions to open SW and the targeted file to perform the processing in SW. As far as I know, the tasks, whether there are scripts or not, necessarily open SW to do conversions or prints.
1 Like
Thank you for your feedback Cyril :)
The PDM script does open SolidWorks at the beginning of the execution... and if I keep only the part of the script that allows you to open a file in SW :
modelPath = "<Filepath>"
Set swDocSpecification = swApp.GetOpenDocSpec(modelPath)
swDocSpecification.DocumentType = swDocPART
swDocSpecification.ReadOnly = False
swDocSpecification.Silent = True
swDocSpecification.ConfigurationName = ""
swDocSpecification.DisplayState = ""
swDocSpecification.IgnoreHiddenComponents = True
Set swModel = swApp.OpenDoc7(swDocSpecification)
errors = swDocSpecification.Error
The script works very well... So I have the impression that it is a problem in the extract/archive part of the script!
Oops sorry misread the code. So I tested quickly, same behavior doesn't work from the explorer.
I think there is a conflict between what the script sends to SW and how SW works (for example, you can see that the file doesn't open).
1 Like
Yes I think too but it's a shame to have no precise indication of the execution problem... because suddenly it is complicated to find the solution :/
This is the "Unable to run the Solidworks macro". I have the impression that it waits on the current versions of the VB.NET and not the VBA but it is true that before the other conversion tasks were in script so easily analyzed.
1 Like
I'll continue to try some code modifications but if I really can't get anything and no one else has any ideas, I'll open a ticket with support!
Finally I omitted it's in the tab "output file detail" or "File" (it depends on the task) and by clicking on advanced script options (you get the SW code).
1 Like
Maybe I should try to insert my code via this type of task ?
To test, I never used the tasks (just a conversion one copied from the basic one and otherwise I use dispatch for other functions)
1 Like
It doesn't work either using the "conversion" / "print" tasks!