There’s really no other way — even if we had a hypothetical omniscient AI — because you can already construct weapons from a number of harmless existing parts with nonviolent uses, there’s no way of banning ALL possible weapon parts from being printed without also banning everything.
And this isn’t even getting into inevitable circumvention of any such limitations placed on 3D printers.
The only way to entirely prevent the construction of weapons is to build everything around us out of jello or styrofoam, and box everyone inside this soft padded universe permanently. But then I bet you even then someone will figure out how to terrorize others with the tools at hand; even if all they can do is hold you down and smother you in jello, someone, somewhere will do it, and copycats will appear everywhere thereafter.