So I have a sizeable paclet built. In my PacletInfo.m, I have created a Resource that points to a file in the Resources directory of my paclet. The resource extension looks like this:
I've seen various places on-line that I should be able to use a function called PacletResource["PacletName","FilePaths"] to access and open that file. However, that function seems to be missing. Mathematica doesn't recognize it and I can't find anything like it in the help system.
I have Mathematica 12.1 and the Paclet is installed in my user specific Paclets\Repository. I can use the Paclet and it works fine. I've tried loading "PacletManager'" and that function doesn't seem to be in there.
What am I missing?
You can use
or the newer form
where pObj is the appropriate PacletObject representing the paclet.
@Ilian Gachevski Thanks for that.
However, although the first form gives me no errors (that's better than I've been able to do on my own!), but it also gives no output.
In:= PacletManager`PacletResource["PackletName", "FilePaths"]
(* No output here*)
In:= FileExistsQ[PacletManager`PacletResource["PacletName", "FilePaths"]]
The second option doesn't do any better. I can correctly create the PacletObject, and get its information, but getting "AssetLocation" just repeats the command, like it is an unknown command.
In:= PObj["AssetLocation", "FilePaths"]
Out= PObj["AssetLocation", "FilePaths"]
Is this documented somewhere, or have I stepped into the outer limits? I can't find any documentation on PacletManager or it's functions.
I did manage to get this to work:
In:= hString = Quiet@Import["PacletName\\Resources\\Filepaths.txt"]
Out= "Contents of Filespatths.txt"
As long as
hString != $Failed
I think this will work. Would be nice to know why that paclet resource isn't working, though.
To clarify, by pObj, I meant the result of pObj = PacletObject["PacletName"] or, equivalently pObj = First[PacletFind["PacletName"]].
pObj = PacletObject["PacletName"]
pObj = First[PacletFind["PacletName"]]
Getting Null for the PacletResource / AssetLocation means the asset does not exist in the paclet.
A possible reason for that is that the default asset Root is ., but in your case the file is placed in a subdirectory called Resources.
Got it. I was trying everything you said and it still wasn't working. Mathematica simply couldn't find my resource.
Turns out that Workbench (the latest version available to us mere mortals) is not keeping up with the current Mathematica paclet technology and wasn't properly installing the paclet (or registering the resources?).
I created a paclet archive and then did an "official" PacletInstall. Now both methods you gave me work perfectly.