AnsweredAssumed Answered

SW Macro Insert Bends

Question asked by Patrick Krug on Aug 31, 2018

Can someone help me with my macro? I tried to insert Bends with a Macro in a solid part. (With the insert bend feature)

And add some properties (that worked).


Sub main()


Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swFeat As SldWorks.Feature

Dim swCustPropMgr As SldWorks.CustomPropertyManager


Dim bret As Boolean

Dim strName As String

Dim strLänge As String

Dim strLängeTrim As String

Const strBenennung As String = "Kassette"


Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

Set swModel = swApp.ActiveDoc

Set swFeat = swModel.FirstFeature

Set swCustPropMgr = swModel.Extension.CustomPropertyManager(Empty)


strName = Left(swModel.GetTitle, Len(swModel.GetTitle) - 7)

strLänge = Right(strName, 8)

strLängeTrim = Replace(strLänge, "-", "")


swCustPropMgr.Add3 "Länge", swCustomInfoText, strLängeTrim, swCustomPropertyReplaceValue

swCustPropMgr.Add3 "Benennung", swCustomInfoText, strBenennung, swCustomPropertyReplaceValue


Do While Not swFeat Is Nothing

    If swFeat.GetTypeName2 = "Blech" Then         'Search for sheet-metal feature?

        bret = swModel.ForceRebuild3(True)

        Debug.Print "Positive"

        Exit Sub


        boolstatus = Part.Extension.SelectByRay(0.29..., 0.29..., 1.49..., -0.577381545199981, -0.57..., -0.57..., 3.80..., 2, False, 0, 0)

        boolstatus = Part.InsertBends2(0.0015, "", 0.5, -1, True, 0.5, True)

        bret = swModel.ForceRebuild3(True)

        Debug.Print "Negative"

    End If

        Set swFeat = swFeat.GetNextFeature



Debug.Print "+#+#+#+"           'just for the command window


End Sub