I wrote a bit of test code. The line that throws an error in your code works fine for me.
A "NullReferenceException" means that one of the variables in the line is not set correctly. In this specific line of code, there are not that many variables. Therefore I expect that the "sheetMetalCompDef" variable is not set. You can check this by adding a check for a null reference before this line. something like this.
if (sheetMetalCompDef == null)
{
// sheetMetalCompDef is not set.
// You have a problem in your code before this line.
Debugger.Break();
}
PlanarSketch baseSketch = sheetMetalCompDef.Sketches.Add(sheetMetalCompDef.WorkPlanes[3]);
If the "sheetMetalCompDef" variable is not set then the debugger will stop on line 5.
If you have confirmed that this is the issue then you probably want to solve the issue. With that, I can't help without looking at more code.
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog: hjalte.nl - github.com