Adding equations using API in SolidWorks

Hi everyone,

I've been trying to add equations using API in SW. Long story short, if

a="D3@Sketch2@Block.Part"

b="D1@Sketch1@Shaft.Part"

exp as String = """""" & a & """" & """=""" & """" & b & """"""

swEquationMgr.Add -1, """" & exp & """"

boolstatus = Part.EditRebuild3()

?exp in immediate window is = """D3@Sketch2@Block.Part""=""D1@Sketch1@Shaft.Part"""

Whenever I rebuild the model, nothing happens.

However, if I use

swEquationMgr.Add -1, """D3@Sketch2@Block.Part""=""D1@Sketch1@Shaft.Part"""

boolstatus = Part.EditRebuild3()

everything works fine; the relationship is successfully added to the model and it also appears under the equations tool. I'm very confused about this issue. I've spent a lot of time, but no success in the end. Can anyone guide me where I'm going wrong. Any help would be much appreciated.

Many thanks for your time and efforts.

Mo

SolidworksApi macros