@Simeon The new asset.all is kind of useless. This is just one of the items that’s in the table for temp=asset.documents.Craft.all. If I want the name I have to do a lot of messing around to pull the name out of that.
Asset Library: 3D Asset Viewer.codea (path: “/private/var/mobile/Containers/Data/Application/09E04C63-C50D-43F7-A91D-C9AA296E1E01/Documents/Craft/3D Asset Viewer.codea”)
PS. I think you pulled out the path name instead of the key name.
@Simeon I changed my projects to use the new asset.all function but I ran into problems with one project. Here’s a stripped down version of the code.
1.) I had to replace any space in the name with an underscore.
2.) I had to strip off the extension names.
Is there a way to not replace spaces or remove extension names. If not I can always create a function to do it.
function setup()
-- read obj files
tab1=asset.builtin.all -- list of assets
for a,b in pairs(tab1) do
bn=b.name
tab2=asset.builtin[bn].all -- list of asset files
for c,d in pairs(tab2) do
if d.ext=="obj" then
print(bn) -- asset name
bn=string.gsub(bn," ","_") -- replace any space with underscore
print(bn)
bn=string.sub(bn,1,#bn-7) -- remove .extension
print(bn)
n=d.name -- file name
print(n)
n=string.sub(n,1,#n-4) -- remove .extension
print(n)
str=readText(asset.builtin[bn][n])
print(str)
stop() -- cause error to stop after printing first file
end
end
end
end
That’s really strange, you shouldn’t have had to do that!
This code works for me (in that it prints the first object before stopping)
function setup()
-- read obj files
tab1=asset.builtin.all -- list of assets
for a,b in pairs(tab1) do
bn=b.name
tab2=asset.builtin[bn].all -- list of asset files
for c,d in pairs(tab2) do
if d.ext=="obj" then
print(bn) -- asset name
n=d.name -- file name
str=readText(asset.builtin[bn][n])
print(str)
stop() -- cause error to stop after printing first file
end
end
end
end
Note that you could also rewrite this:
function setup()
– read obj files
tab1=asset.builtin.all – list of assets
for a,b in pairs(tab1) do
bn=b.name
tab2=asset.builtin[bn].all – list of asset files
for c,d in pairs(tab2) do
if d.ext==“obj” then
str=readText(d)
print(str)
stop() -- cause error to stop after printing first file
end
end
end
@Simeon Heres an updated version for my above code. I was able to eliminate a lot of code.
function setup()
-- read obj files
tab1=asset.builtin.all -- list of assets
for a,b in pairs(tab1) do
tab2=asset.builtin[b.name].all -- list of asset files
for c,d in pairs(tab2) do
if d.ext=="obj" then
str=readText(d)
print(str)
stop() -- cause error to stop after printing first file
end
end
end
end
@Simeon That’s correct, I don’t need to do any stripping. I was able to remove a lot of code from my original code using the new asset.all code. I wasn’t expecting you to respond because I thought you would be sleeping. I can’t seem to figure out your wake/sleep schedule compared to mine.
@Simeon Version 205. This is a nothing problem, but in the code below, if I put the cursor on one of the middle color lines, the color icon doesn’t show on the line just above or just below which is probably what you want. If the line has one value in the (), the color icon doesn’t show one line above or below. If there are 2 or more values, then the color icon does show on the line just above and below. Like I said it a nothing problem.
PS. The cursor has to be to the right of the color icon. It’s different if it’s left of it.
function setup()
color()
color()
color()
color()
color()
color()
color()
color()
end
@dave1707 the way this works is Codea checks whether the cursor would overlap the colour annotation (with some extra padding) and if so it hides those annotations so you can read the code there
Wooah - loaded 205 checked it out, went to sleep (unlike @Simeon) woke up and 208 !!!
The pace at the moment is frantic. Get a rest Simeon - give us chance to catch up.
@Simeon If I run the below code, it shows Name, Ext, Type, Path of the files in documents. What I don’t like is that Name also shows the extension. Can you change it so name returns only the name without the extension. There’s no hurry, but it would be nice and I don’t think it should affect anything.
displayMode(FULLSCREEN)
function setup()
dy=-30
dx=0
textMode(CORNER)
tab=asset.documents.all
end
function draw()
background(0)
fill(255)
for a,b in pairs(tab) do
text(b.name,20+dx,HEIGHT-a*25+dy)
text(b.ext,250+dx,HEIGHT-a*25+dy)
text(b.type,350+dx,HEIGHT-a*25+dy)
text(b.path,450+dx,HEIGHT-a*25+dy)
end
rect(0,HEIGHT-30,WIDTH,HEIGHT-30)
fill(0)
text("Name",20+dx,HEIGHT-25)
text("Ext",250+dx,HEIGHT-25)
text("Type",350+dx,HEIGHT-25)
text("Path",450+dx,HEIGHT-25)
end
function touched(t)
if t.state==MOVING then
dy=dy+t.deltaY
if dy<-30 then
dy=-30
end
dx=dx+t.deltaX
if dx>0 then
dx=0
end
end
end