You seem to be trying to find the object in the P&ID database,
Project pj = projeto.ProjectParts["PnId"];
which is causing the exception "ObjectDoesNotHaveLink" which means "I cant find what you are looking for".
To access the 3D data, you must use:
Project pj = projeto.ProjectParts["Piping"];