Rebuild does not work in a dll.

I am trying to flatten a part with vb.net and I have the code in a dll, it flattens and then the rebuild flag appears by the in the feature tree. I can cannot get it to update so that the part actually flattens.

Anybody ever experianced this ?

This is the code I have tried:

swModel = swApp.ActivateDoc(PartName)

swModel.SetBendState(swSMBendState_e.swSMBendStateFlattened)

swModel.Rebuild(swRebuildOptions_e.swRebuildAll)

swModel.Rebuild(swRebuildOptions_e.swForceRebuildAll)

swModel.EditRebuild3()

Just cannot get it to work.

Note: this works just fine if the code is in an exe or a macro.

Thanks.

SolidworksApi macros