Script for EPDM task

Hello, I have created a new task in EPDM " new project to schedule "

And I'd like When I do right-click on the assembly or on the part concerned and I click on my task:
image

it opens the New Message window of the EPDM mailbox, (as if I were right-clicking → notify → a colleague)

and that it fills: Send To: " Programming " automatically.
in the Fill in Subject: New project to schedule & " automatically put the name of the file where I did right click"

And in the message put a message and the location of the file where I did right click.

image

All that remains is to click on send to the user to the relevant people and add an additional comment if they wish.

Is it possible and if so, does anyone have an idea of the script I should put in my task?

Hello

I couldn't find the arguments to set the Solidworks PDM internal messaging tool to get the desired result.
Another option, go through Outlook: Using dispatch to send outlook messages by data card variable

1 Like

Hello
I just succeeded with this code in the task script:

Dim swApp As Object
Dim oOutlook As Object
Dim oMailItem As Object
Dim Body As Variant
Dim sTmp As String, SigString As String
Dim Signature As String
Dim strbody As String

Sub main()

    Set swApp = Application.SldWorks

    PreparerOutlook oOutlook
    Set oMailItem = oOutlook.CreateItem(0) ' 0 = olMailItem

    strbody = "<font size=3>" _
            & "Bonjour,<br>" _
            & "Voici un nouveau projet à programmer.<br>" _
            & "<br>" _
            & "Cordialement,"

    With oMailItem
        .Display
        .To = "mail@mail.fr"
        .Subject = "Nouveau projet à programmer"
        .HTMLBody = strbody & .HTMLBody
    End With

End Sub

Private Sub PreparerOutlook(ByRef oOutlook As Object)
    On Error Resume Next
    Set oOutlook = GetObject(, "Outlook.Application")
    If (Err.Number <> 0) Then
        Err.Clear
        Set oOutlook = CreateObject("Outlook.Application")
        If (Err.Number <> 0) Then
            MsgBox "Une erreur est survenue lors de l'ouverture de Outlook..."
            Exit Sub
        End If
    End If
End Sub

Would you be how I can retrieve the name of the file or folder now when I right-click on it and run the task?
And also recover the full path of that file or folder
that I can include both in my email?

Hello

You have to stay in the VBA logic of SW and reuse functions such as GetPathname etc.
I think it would have been easier to go through Dispatch which allows you to retrieve the information of the selected files in the vault and map all that (less manipulation of VBA compared to a task)

1 Like

Do you have any examples? I'm lost...

For disptach?
In the link I put in my first answer there is a good part.

1 Like

From what I understood:

I put the two files here: F:\PDM\Admin\Dispatch

the tasks_email.bat file is blank (but it fills in like the .txt file when I run the dispatch)

The email_template.txt file contains:
" C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE " /c ipm.note /m " monmail@mail.fr?subject=New project to program&body=Hello, here's a new project to program: "

I put in Generate the settings file:

Model: F:\PDM\Admin\Dispatch\email_template.txt
Name of: F:\PDM\Admin\Dispatch\tasks_email.bat

I put in Run Shell:

Open C:\Windows\system32\Cmd.exe /c F:\PDM\Admin\Dispatch\tasks_email.bat

but there must be a bug when I put this it adds duplicate stuff when I validate (see image)

but nothing happens... due to the shell bug I think?

It's okay I found, you shouldn't write the open.

How can I do line breaks in my bodysuit?

And how to do it because in the file path I have accents on the e's for example and so it transforms them when it writes the email?

It's HTML so I guess like this for example:

"<html><p><font style=""font-family: Arial; font-size: 10pt;"">" & "Bonjour," & "<br /><br />"

"C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE" /c ipm.note /m "monmail@mail.fr?subject=Nouveau projet a programmer&body=<html><p><font style=""font-family: Arial; font-size: 10pt;"">Bonjour,<br /><br />Voici un nouveau projet à programmer : </font></p></html>"

I put this but it tells me that the command line argument is invalid

I don't think in argument. I'll see if I have some time

Regarde ce lien : windows - Open Outlook.exe from cmd with body text containing newlines - Stack Overflow

2 Likes

I've already tried but it replaces " %0D%0A " in my email with " 0A " without making a line break. after the line break it's a detail, if it's really impossible it's not a big deal... The biggest problem is my file path in " %Repertoire_fichier% " which can have spaces and/or accent on the É for example and which therefore do not come out well in the mail and the path is wrong

"C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE" /c ipm.note /m "%Email%?subject=Nouveau projet a programmer - %Nom_fichier%&body=Bonjour, voici un nouveau projet a programmer : Repertoire : file\\\%Repertoire_fichier% Nom du fichier : %Nom_fichier%"

In html no accent to replace them, here is the approach to adapt to the language:
https://www.leptidigital.fr/productivite/caracteres-speciaux-html-2-19297/#:~:text=Dans%20le%20langage%20HTML%2C%20les,encodé%20sur%20les%20pages%20web.

If I understand correctly before running the shell here, I have to run another one before that will take the Tasks_email.bat and replace all the special characters in it?
then switch to the other shell?

It's becoming much too complex for me no matter how hard I try, for the past 2 hours I've been completely lost.

wouldn't it be easier in VBA script? Wouldn't there be all these constraints?

I just can't get the name and the path of the file from where I start my task.

Dim swApp As Object
Dim oOutlook As Object
Dim oMailItem As Object
Dim Body As Variant
Dim sTmp As String, SigString As String
Dim Signature As String
Dim strbody As String

Sub main()

    Set swApp = Application.SldWorks

    PreparerOutlook oOutlook
    Set oMailItem = oOutlook.CreateItem(0) ' 0 = olMailItem

    strbody = "<font size=3>" _
            & "Bonjour,<br>" _
            & "Voici un nouveau projet à programmer.<br>" _
            & "<br>" _
            & "Cordialement,"

    With oMailItem
        .Display
        .To = "monmail@mail.fr"
        .Subject = "Nouveau projet à programmer"
        .HTMLBody = strbody & .HTMLBody
    End With

End Sub

Private Sub PreparerOutlook(ByRef oOutlook As Object)
    On Error Resume Next
    Set oOutlook = GetObject(, "Outlook.Application")
    If (Err.Number <> 0) Then
        Err.Clear
        Set oOutlook = CreateObject("Outlook.Application")
        If (Err.Number <> 0) Then
            MsgBox "Une erreur est survenue lors de l'ouverture de Outlook..."
            Exit Sub
        End If
    End If
End Sub```

Hello

I don't have too much time to devote to this subject at the moment.
To work with a task, you have to look at how the path and the file name are retrieved from the other scripts to be able to pass it as a parameter in the constitution of the body of the mail.

1 Like

I found the solution, here is the code if anyone is interested:

Dim swApp As Object
Dim oOutlook As Object
Dim oMailItem As Object
Dim Body As Variant
Dim sTmp As String, SigString As String
Dim Signature As String
Dim strbody As String
Dim fichierChemin As String
Dim NomFichier As String
Dim cheminComplet As String
Dim nomAvecExtension As String

Sub main()

    Set swApp = Application.SldWorks

    fichierChemin = "<Path>"
    cheminComplet = "<Filepath>"
    nomAvecExtension = Mid(cheminComplet, InStrRev(cheminComplet, "\") + 1)
    NomFichier = Left(nomAvecExtension, InStrRev(nomAvecExtension, ".") - 1)



    PreparerOutlook oOutlook
    Set oMailItem = oOutlook.CreateItem(0) ' 0 = olMailItem

strbody = "<font size=3>" _
        & "Bonjour,<br>" _
        & "Voici un nouveau projet à programmer :<br>" _
        & "<br>" _
        & "Chemin du projet : <a href='file://" & Replace(fichierChemin, "\", "/") & "'>" & fichierChemin & "</a><br>" _
        & "Nom de l'assemblage : <b>" & nomAvecExtension & "</b><br>" _
        & "<br>" _
 

    With oMailItem
        .Display
        .To = "mail@mail.fr"
        .Subject = "Nouveau projet à programmer - " & NomFichier 
        .HTMLBody = strbody & .HTMLBody
    End With

End Sub

Private Sub PreparerOutlook(ByRef oOutlook As Object)
    On Error Resume Next
    Set oOutlook = GetObject(, "Outlook.Application")
    If (Err.Number <> 0) Then
        Err.Clear
        Set oOutlook = CreateObject("Outlook.Application")
        If (Err.Number <> 0) Then
            MsgBox "Une erreur est survenue lors de l'ouverture de Outlook..."
            Exit Sub
        End If
    End If
End Sub
2 Likes