Check if part is already loaded in session

I'm creating my own "library" Form from where I insert often used parts.

I have a problem with inserting a component when it's already loaded into a session.

For the moment I use Try...Catch. There is a collection of theSession.Parts which I assume I could check somehow if there is already a part which I want to load...
Could you help me with that?

Try
Dim basePart As BasePart
Dim partLoadStatus1 As PartLoadStatus
basePart = theSession.Parts.OpenBase(pfile, partLoadStatus1)
partLoadStatus1.Dispose()
Catch ex As Exception
lw.writeline(ex.Message)

End Try

One way to check is to iterate through the .Parts collection and check if an open part matches the one that you want open. Something like below (not tested):

for each openPart as part in theSession.Parts
if openPart.FullPath = pfile then
'part is already open
else
'code to open part
end if
next

Yeah, that should work. I didn't check the part class for properties I can access. So it's possible to compare the parts by the path.