Solved! Go to solution

clicks "Save" button to run others

Hi All,

I'm trying (or better - I'm looking for a solution now ) to handle "Save" button in SolidEdge ST7.

Every time, when user clicks a "Save" button I want to run a small macro, but i don't know how tohandle a save action.

I will be very grateful for any hint!

 maybe a solution that is to write a custom addin,but I don't know how to write it.can you give me some advice.

It will be best that if you have any similar examples.

thank you!

Smiley Happy



Re: clicks "Save" button to run others

Take a look at the resources provide here:


and specfically you will find an Add-in demo  and Add-in Wizard...


Hope that points you in the right direction

Matt Johnson
Solid Edge Certified Professional (ST7 & ST8)
Solid Edge ST9 (SEEC) - Production
NX10 (Tc Integration) Pre-Production Testing
Teamcenter 10.1.6

Re: clicks "Save" button to run others

I couldn't get the Developer Community resources to work with Visual Studio 2017, but I was able to get a functional code to trigger on a Before Save event in ST7 and ST9 using the information in the .Net Programmers Guide.


I found that I had to combine the sections on Addins and Handling Events, but it works.


What are you trying to do with the macro?



Re: clicks "Save" button to run others

@mpowers We are working on similar usage. Did you use the Application even or Document event? We are looking to save the flat to dxf whenever a psm is saved.

Accepted by topic author yagely
‎07-20-2017 05:14 AM

Re: clicks "Save" button to run others

I used an document event for saving .dft to .pdf automatically.


Here's the framework that I used for mine.  I did this in VB.Net.  Somethings that gave me trouble are getting the ProgIdAttribute right, and then registering the addin so that you can debug.  You'll also need to make sure you provide the right CATIDs for the Sheet Metal Environments.


Imports Microsoft.Win32
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports SolidEdgeFramework
Imports System.IO

<GuidAttribute("F57998BF-A665-48A2-B45F-5BD59352BCEF"), ProgIdAttribute("DrawingRelease4.AddIn"), ComVisible(True)> Public Class Addin
    Implements ISolidEdgeAddIn
    Implements ISEDocumentEvents

    Private _addin As SolidEdgeFramework.AddIn
    Private seApp As Application
    Private WithEvents SeDocEvents As ISEDocumentEvents_Event

#Region "Connection Events"
    Public Sub OnConnection(ByVal Application As Object, ByVal ConnectMode As SolidEdgeFramework.SeConnectMode, ByVal AddInInstance As SolidEdgeFramework.AddIn) Implements SolidEdgeFramework.ISolidEdgeAddIn.OnConnection
        Debug.Print("Connected to Application")
        ' Store local variables for later use
        _addin = AddInInstance
        seApp = Application
        ' Set Addin's GUI Version
        AddInInstance.GuiVersion = 1

       'This line is important to let the program see the document events!
        SeDocEvents = seApp.ActiveDocument.DocumentEvents
    End Sub

    Public Sub OnConnectToEnvironment(ByVal EnvCatID As String, ByVal pEnvironmentDispatch As Object, ByVal bFirstTime As Boolean) Implements SolidEdgeFramework.ISolidEdgeAddIn.OnConnectToEnvironment
        Debug.Print("Connected to Environment")
    End Sub

    Public Sub OnDisconnection(
    ByVal DisconnectMode As SolidEdgeFramework.SeDisconnectMode) Implements SolidEdgeFramework.ISolidEdgeAddIn.OnDisconnection
        If Not (_addin Is Nothing) Then
            _addin = Nothing
        End If
        If Not (seApp Is Nothing) Then
            seApp = Nothing
        End If
    End Sub
#End Region

#Region "Registration Events"
    ' Called by Regasm.exe
    <ComRegisterFunctionAttribute()> Public Shared Sub RegisterFunction(ByVal t As Type)
        Dim baseKey As RegistryKey = Nothing
        Dim summaryKey As RegistryKey = Nothing
        Dim title As AssemblyTitleAttribute
        Dim description As AssemblyDescriptionAttribute
            baseKey = Registry.ClassesRoot.CreateSubKey("CLSID\{" & t.GUID.ToString & "}")
            ' Tell Solid Edge to automatically load your addin
            baseKey.SetValue("AutoConnect", 1)
            ' Write title
            If t.Assembly.IsDefined(GetType(AssemblyTitleAttribute), True) Then
                title = AssemblyTitleAttribute.GetCustomAttribute(t.Assembly, GetType(AssemblyTitleAttribute))
                baseKey.SetValue("409", title.Title)
            End If
            ' Write description
            If t.Assembly.IsDefined(GetType(AssemblyDescriptionAttribute), True) Then
                description = AssemblyDescriptionAttribute.GetCustomAttribute(t.Assembly, GetType(AssemblyDescriptionAttribute))
                summaryKey = baseKey.CreateSubKey("Summary")
                summaryKey.SetValue("409", description.Description)
            End If
            ' Write required registry entries for a Solid Edge Addin.
            ' See secatids.h in C:\Program Files\Solid Edge VXX\SDK\include
            baseKey.CreateSubKey("Implemented Categories\{26B1D2D1-2B03-11d2-B589-080036E8B802}")
            ' Specify the Environment Categories that you want you addin to work in

            baseKey.CreateSubKey("Environment Categories\{08244193-B78D-11D2-9216-00C04F79BE98}")
            'baseKey.CreateSubKey("Environment Categories\{26618394-09D6-11D1-BA07-080036230602}")
            'baseKey.CreateSubKey("Environment Categories\{26618395-09D6-11D1-BA07-080036230602}")
            'baseKey.CreateSubKey("Environment Categories\{26618396-09D6-11D1-BA07-080036230602}")
            'baseKey.CreateSubKey("Environment Categories\{26618398-09D6-11D1-BA07-080036230602}")
            'baseKey.CreateSubKey("Environment Categories\{7313526A-276F-11D4-B64E-00C04F79B2BF}")
        Catch ex As Exception
            If Not (summaryKey Is Nothing) Then
            End If
            If Not (baseKey Is Nothing) Then
            End If
        End Try
    End Sub
    ' Called by Regasm.exe /u
    <ComUnregisterFunctionAttribute()> Public Shared Sub UnregisterFunction(ByVal t As Type)
            ' Remove any previously written registry entries
            Registry.ClassesRoot.DeleteSubKeyTree("CLSID\{" + t.GUID.ToString() + "}")
        Catch ex As Exception
        End Try
    End Sub
#End Region

#Region "Event Triggers"
#Region "Unused Events"
    Public Sub BeforeClose() Implements ISEDocumentEvents.BeforeClose
        Throw New NotImplementedException()
    End Sub

    Public Sub BeforeSave() Implements ISEDocumentEvents.BeforeSave
        Throw New NotImplementedException()
    End Sub

    Public Sub AfterSave() Implements ISEDocumentEvents.AfterSave
        Throw New NotImplementedException()
    End Sub

    Public Sub SelectSetChanged(SelectSet As Object) Implements ISEDocumentEvents.SelectSetChanged
    End Sub

    Private Sub SeDocEvents_BeforeClose() Handles SeDocEvents.BeforeClose

    End Sub

    Private Sub SeDocEvents_SelectSetChanged(SelectSet As Object) Handles SeDocEvents.SelectSetChanged

    End Sub
#End Region

    Private Sub SeDocEvents_BeforeSave() Handles SeDocEvents.BeforeSave
            'Triggered before Save is executed
    End Sub

    Private Sub SeDocEvents_AfterSave() Handles SeDocEvents.AfterSave
       'Triggered After Save is completed.
    End Sub
#End Region

End Class


I think that in Visual Studio 2017, if you set the CPU configuration to x64, then it registers correctly.  If you don't do that, then you'll probably need to run a windows command line like this:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe /codebase "C:\Users\mpowers\Documents\Addin Project Folder\bin\debug\

with your specific path.


I've also been thinking about how to do the flat->dxf automation.  

Re: clicks "Save" button to run others


 Thank you much, been busy working through the SE .NET Programmer's Guide.  Did you find that c/p from the guide was troublesome with many extra line breaks?  I see what you mean about the GUID attributes stuff, those are new to me and taking a bit to wrap my head around.  And the CATIDs, took me a bit to find that they are in the secatids.h file. 

Re: clicks "Save" button to run others

No problem.  

I did think the extra line breaks were annoying, but one I was looking for them, they weren't too bad to edit.



Re: clicks "Save" button to run others

Thanks mpowers,I hand work out this addin .I did not use macro now.But I don't know how to register addin on other conputers you know.

Re: clicks "Save" button to run others

thank you very much.I have work out this addin .But I don't know how to register addin on other conputers you know.

Re: clicks "Save" button to run others

You should be able to use the same Windows Console command line to register on other computers.  You'll definitely need administrator privledges to install an addin that makes changes to the root registry  like the code above.


C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe /codebase "C:\Users\mpowers\Documents\Addin Project Folder\bin\debug\