AnsweredAssumed Answered

Temporary Body won't allow operations unless I call a .Copy on it first

Question asked by J. R. on Nov 20, 2018
Latest reply on Nov 20, 2018 by J. R.



I am having a must puzzling problem. I making an application in VB.NET that connects to Solidworks and uses it's API to manipulate Temporary Bodies. I have a code block that looks like this:

        Dim bodyArray as Object = swPart.GetBodies2(swBodyType_e.swSolidBody, False)
        Dim firstBody as Body2 = bodyArray(0)
        firstBody.Display3(swModel, 0, 0)

If I run this, there is nothing being displayed in the model view. Additionally, API calls such as Operations2 fail (no error message, just not producing any output bodies), as for some reason it doesn't consider the firstBody as a valid Body2.


However (!), if I insert an additional line,

          firstBody = firstBody.Copy


then display3, as well as Operations2 (and other API calls as far as I can tell) will work perfectly for firstBody after this line.


I find this extremely bizarre, as the line 2 of the quoted code should give the firstBody a reference to the first object of bodyArray, which is a valid Body2. As could be expected, calling

          bodyArray(0).display3(swModel, 0, 0)


won't work either. No matter what I do, that Body won't be considered valid for most API calls unless I Copy it. Which I don't want to do, because it slows down my application.


Am I misunderstanding some fundamental element about how these object references work?