ModifyDefinition not making changes

I am try to modify the thickness of a lofted bend.

For my example macro, I first select the lofted bend, and then run it.

I get the definition of the feature, change the thickness value, and then call ModifyDefinition.

Nothing changes in the part, and when I call getDefinition again I can see that nothing has changed in code either.

Option Explicit

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swModelDocExt As SldWorks.ModelDocExtension

Dim swSelMgr As SldWorks.SelectionMgr

Dim swFeat As SldWorks.Feature

Dim featName As String, featType As String

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swSelMgr = swModel.SelectionManager

Set swModelDocExt = swModel.Extension

' Get the selected feature

Set swFeat = swSelMgr.GetSelectedObject6(1, -1)

Dim lbfd As SldWorks.LoftedBendsFeatureData

Set lbfd = swFeat.GetDefinition

Debug.Print "Thickness: " & lbfd.Thickness

lbfd.Thickness = 0.01

Dim bRet As Boolean

bRet = swFeat.ModifyDefinition(lbfd, swModel, Nothing): Debug.Assert bRet

' Debug messages follow:

' This is my changed thickness:

Debug.Print "Thickness: " & lbfd.Thickness

'  See what the feature sees as the thickness:

Set lbfd = swFeat.GetDefinition

' It shows the original thickness therefore modifydefinition did not work.

Debug.Print "Thickness: " & lbfd.Thickness

End Sub

SolidworksApi macros
Answers 6
IK
IK 2016-09-28 Best Answer
SF
SF 2016-09-28

Thanks for your response

unfortunately adding the line:

     Set lbfd = swFeat.GetDefinition

      ' this line is new:
     lbfd.AccessSelections swModel, Nothing

to my VBA macro resulted in no change

KR
KR 2016-09-28

Technically, AccessSelections is only necessary when modifying the selections used to create a feature, since it is necessary to put the feature in a rollback state. On a few occasions, however, I found it necessary to use this method even when changing non-selection options. Therefore, I agree with Ivana. You should try use ILoftedBendsFeatureData::AccessSelections before modifying the thickness.

Keith

SolidWorks API Training and Services​

SF
SF 2016-09-28

Hi Keith,

Thanks for your help

unfortunately adding the line:

     Set lbfd = swFeat.GetDefinition

      ' this line is new:
     lbfd.AccessSelections swModel, Nothing

to my VBA macro resulted in no change.

(My apparent slow response times are due to waiting for moderation - assume it's because I have a new account)

IK
IK 2016-09-29

your macro is working here. SW 2013 and 2016

Can you modify thickness to this value in SW without macro?

SF
SF 2016-09-30

Interesting that it works for you... I am able to change the value in SW without macro.

Thanks for your help.

I am currently using a workaround where I link the thickness via equation to a dummy dimension on a sketch. I can modify that dimension with a macro.