Reputation: 39
We are using the RoomPlan API to capture data, which is stored in the 'CapturedRoom' variable in our code (referred to as 'finalResult'). We then attempt to save a USDZ file in the file manager. Sometimes it works, but other times, we encounter issues like the one below
Coding Error: in _IsValidPathForCreatingPrim at line 3338 of usd/stage.cpp -- Path must be an absolute path: <>
cannotCreateNode(path: "/9EE71ED0F8D6415496A7B9F0C3671DB0321")
This is that code we are using for shaving CapturedRoom data
func saveFileLocal() {
if let finalResult {
let fm = FileManager.default
let documentsURL = fm.urls(for: .documentDirectory, in: .userDomainMask).first!
//let documentsURL = URL.documentsDirectory
let fileName = "\(UUID().uuidString).usdz"
let fileURL = documentsURL.appendingPathComponent(fileName)
do {
try finalResult.export(to: fileURL)
} catch {
print(error)
}
}
}
Upvotes: 0
Views: 216
Reputation: 521
File names for CapturedRoom export cannot start with a number - it's a leaky abstraction, implementation details about UDSZ have escaped and affect our choice of filenames.
If you'll change your implementation to:
if let testRoomCapture {
let currentTimeInMilliseconds = CapturedRoomHelper().currentTimeInMiliseconds()
let destinationFolderURL = FileManager.default.temporaryDirectory.appending(path: "Export")
let destinationURL = destinationFolderURL.appending(path: "room_" + String(currentTimeInMilliseconds) + ".usdz")
do {
try testRoomCapture.export(to: destinationURL, exportOptions: .model)
let fileManager = FileManager.default
let fileExist = fileManager.fileExists(atPath: destinationURL.path())
XCTAssertTrue(fileExist)
} catch {
print(error)
XCTAssertNil(testRoomCapture, "Failed to export room data")
}
} else {
XCTAssertNotNil(testRoomCapture, "Should have get a RoomCapture Object")
}
Upvotes: 0
Reputation: 285250
Your code is a bit confusing.
In terms of URL
path
is a file system string path, all your path
variables are actually URL
s.
absoluteURL
does nothing in this context, delete it.
And the absoluteString
detour is pointless, path.appendingPathComponent(c)
is the URL you want, but with contentsOfDirectory(at:includingPropertiesForKeys:)
you get full URLs for free.
func saveFileLocal() {
if let finalResult {
let fm = FileManager.default
let documentsURL = URL.documentsDirectory
let fileName = "\(UUID().uuidString).usdz"
let fileURL = documentsURL.appendingPathComponent(fileName)
do {
try finalResult.export(to: fileURL)
} catch {
print(error)
}
}
}
func removeFiles() {
let fm = FileManager.default
let documentsURL = URL.documentsDirectory
do {
let content = try fm.contentsOfDirectory(at: documentsURL, includingPropertiesForKeys: nil, options: .skipsHiddenFiles)
for anURL in content {
try fm.removeItem(at: anURL)
}
} catch {
print(error)
}
}
Upvotes: 0
Reputation: 39
** Try starting your file name with a non-number** this workaround for this
Upvotes: 0