| document - resource authoring handle |
|
Returns the filename a resource document has adopted. The result is empty for an untitled document. Save As adopts its destination after a successful save. For the full story, see the reusable resources guide, which covers resource formats, ownership, editing and the save workflow. See also: SaveResourceDocument, ResourceDocumentDirty, ResourceDocumentDiskRevision. |
; CreateResourceDocument Example
; ------------------------------
; Create an untitled material document in memory; nothing touches the disk
document=CreateResourceDocument("material")
If document=0 Then RuntimeError ResourceDocumentError()
Print "New material document"
Print " path: '"+ResourceDocumentPath(document)+"' (untitled)"
Print " dirty: "+ResourceDocumentDirty(document)
Print " revision: "+ResourceDocumentRevision(document)
; Recolour it with an edit transaction made at the revision we observed
revision=ResourceDocumentRevision(document)
text$="{'protocol':'blitz3d.resource-document-edit','version':1,'revision':"+revision+","
text=text+"'operations':[{'op':'set-material-property','property':'color','value':[0.9,0.4,0.1,1]}]}"
edit=ParseJson(Replace(text,"'",Chr(34)))
If ApplyResourceDocumentEdit(document,edit)=0 Then RuntimeError ResourceDocumentError()
Print ""
Print "ApplyResourceDocumentEdit succeeded; revision is now "+ResourceDocumentRevision(document)
; The same edit is now stale, so it is rejected and nothing changes
Print "Applying it again returns "+ApplyResourceDocumentEdit(document,edit)
Print " ResourceDocumentError: "+ResourceDocumentError()
FreeJson edit
; Broken replacement text is rejected too, with diagnostics
If ReplaceResourceDocumentSource(document,"{",ResourceDocumentRevision(document))=0
diagnostics=ResourceDocumentDiagnostics(document)
Print ""
Print "ReplaceResourceDocumentSource rejected '{' with "+JsonCount(diagnostics)+" diagnostic(s)"
FreeJson diagnostics
EndIf
; Validation reports on the document without changing it
report=ValidateResourceDocument(document)
valid=JsonObjectGet(report,"valid")
Print ""
Print "ValidateResourceDocument valid: "+JsonBoolean(valid)
FreeJson valid
FreeJson report
; Read the colour back from a JSON snapshot of the document
snapshot=ResourceDocumentJson(document)
definition=JsonObjectGet(snapshot,"definition")
Print "Authored definition: "+JsonStringify(definition)
FreeJson definition
FreeJson snapshot
Print "Source text length: "+Len(ResourceDocumentSource(document))+" characters"
; Diagnostics of the latest operation in this program, handle or not
latest=ResourceDocumentLastDiagnostics()
Print "Latest operation diagnostics: "+JsonCount(latest)
FreeJson latest
FreeResourceDocument document
Print ""
Print "Press any key to close the example"
WaitKey
End