DanPatterson_Retired
MVP Emeritus

not sure I follow, but

r"C:\Users\melis\Documents\GISPortfolioProjects\CustomTools\Sel2DefQuery.aprx" is fine when pro isn't open, but

"CURRENT"

Tutorial: Getting started with arcpy.mp—ArcPy | ArcGIS Desktop 

as in

aprx = arcpy.mp.ArcGISProject("CURRENT")

if you are using the python window in Pro