The NodePaths you're using are wrong - unless part1 and part2 are children of the PinJoint2D you're adding via code. If your tree looks like this:
- Root
- part1
- part2
- PinJoint2D (added at runtime)
then the paths have to be "../part1" and "../part2" respectively. They have to be relative to the PinJoint-path, not the path of the node who adds the PinJoint.