ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
CKCody Kirsch12/02/2018

I am trying to create a macro feature a using VB.NET addin and am not having much luck. I have tried both the COM callbacks and .NET add-In callbacks methods described here​ as well as using some examples I found poking around the form. I am very familiar with making macro features as a VBA macro so I'm guessing there is something that I am unaware of when using .net so hopefully this is easy question.

The code below is just what i have been using to just try and get a feature inserted so there shouldn't be anything else causing an issue. I have the following module and class in separate .vb files in a project called MyProject, which is also the Start Up Project in a Solution. I have actually tried using InsertMacroFeature3 from an addin but know luck with that either.

In MyModule.vb

Imports SolidWorks.Interop.sldworks

Imports SolidWorks.Interop.swconst

Public Module MyModule

    Public Sub Main()

        Dim _app As SldWorks = GetObject(, "SldWorks.Application")

        Dim _model As ModelDoc2 = _app.ActiveDoc

        Dim FeatMgr As FeatureManager = _model.FeatureManager

        Dim feat As Feature = FeatMgr.InsertMacroFeature3("TestFeature", "MyProject.MacroFeatureClass", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, swMacroFeatureOptions_e.swMacroFeatureByDefault)

        If feat Is Nothing Then MsgBox("Macro Feature Failure")

    End Sub

End Module

In MacroFeatureClass.vb

Imports SolidWorks.Interop.swpublished

Imports SolidWorks.Interop.swconst

<ComClass(MacroFeatureClass.ClassId, MacroFeatureClass.InterfaceId, MacroFeatureClass.EventsId)>

Public Class MacroFeatureClass

    Implements ISwComFeature

    Public Const ClassId As String = "1FEC45A4-8300-4FD2-AFC4-ED4952A6F4F5"

    Public Const InterfaceId As String = "19DEA4FB-46F6-445D-B996-39BACD9B70CA"

    Public Const EventsId As String = "8AF8B870-7455-431C-B5F2-718CCCA1607C"

    Public Sub New()

             MyBase.New()

    End Sub

    Public Function Rebuild(ByVal app As Object, ByVal model As Object, ByVal feat As Object) As Object Implements ISwComFeature.Regenerate

             Return True

    End Function

    Public Function Edit(ByVal app As Object, ByVal model As Object, ByVal feat As Object) As Object Implements ISwComFeature.Edit

             Return True

    End Function

    Public Function Security(ByVal app As Object, ByVal model As Object, ByVal feat As Object) As Object Implements ISwComFeature.Security

             Return swMacroFeatureSecurityOptions_e.swMacroFeatureSecurityByDefault

    End Function

End Class