Select to view content in your preferred language

can't GetObjectFromFullName with IGxCatalog

823
4
07-28-2011 03:05 PM
EvanThoms
Frequent Contributor
In an ArcMap addin I have the code:

Dim gxCat As IGxCatalog
Dim pObj As IGxObject
Dim x As Long

gxCat = New GxCatalogClass

pObj = pObj = gxCat.GetObjectFromFullName(sPath, x)


But the last line trips the error - Cannot convert to 'Interface IGxObject', but that's exactly what the function is documented to do.

I know the path is good (tried a few) and I think I am getting a valid catalog object, I mean, I can do things with it like make a folder connection.

Furthermore, on my previous computer, this same addin and this same chunk of code never threw an error.

BTW, what I am trying to do is, from a full path to an object, determine first if the path leads to a valid ArcCatalog object and then what the datase type of that object is, so if there is another way beside getting to IGxDataset.Dataset.Type I would appreciate it.

Thanks
0 Kudos
4 Replies
NeilClemmons
Honored Contributor
This line is incorrect:
pObj = pObj = gxCat.GetObjectFromFullName(sPath, x)

It should be:
pObj = gxCat.GetObjectFromFullName(sPath, x)

Also, GetObjectFromFullName may return an IGxObject reference or an IEnumGxObject reference.  Your code should handle the possibility of both.  See the developer help for more info and for an example.
0 Kudos
amrutabildikar1
Emerging Contributor
Hi,

You can refer following VBA example to implement the functionality.
I think you can try to get full name from GetObjectFullName into a variant type of variable.

Sub GetObjFromFullname()  
Dim pApp As IGxApplication  
Set pApp = Application  
Dim pCat As IGxCatalog
   Set pCat = pApp.Catalog
   Dim pGxObject As IGxObject 
  Dim numFound As Long  
Dim v As Variant  
Set v = pCat.GetObjectFromFullName("C:\data\parcels.shp", numFound)    'Assuming the above pathname is valid
   If numFound = 1 Then    
   Set pGxObject = v 
  Else     
  Dim pEnumGxObject As IEnumGxObject
       Set pEnumGxObject = v    
   Set pGxObject = pEnumGxObject.Next
   End If
End Sub


I hope this helps!

Good luck!
0 Kudos
EvanThoms
Frequent Contributor
Thanks!
Yes, I did find an example of testing for a single or an enumeration reference and it turns out the function is returning an enumeration of three references, all to the exact same object, in this case a tif file (also tried a .asc), which I presume is just one object. And this is probably why my code worked on a different build; it was always only returning a single reference. So, why am I getting three now?
0 Kudos
EvanThoms
Frequent Contributor
And another weird thing is happening I didn't at first think was related. When

pObj = gxCat.GetObjectFromFullName(sPath, numFound)

is called, an unnamed .prj file appears in the folder alongside the mxd that has the addin with the spatial reference of the tif file at the end of sPath.
0 Kudos