Click or drag to resize

UserResource Class

Class representing a file which can be embedded in a model or catalog and can be referenced by visuals and scripts.
Inheritance Hierarchy
SystemObject
  Demo3D.VisualsUserResource

Namespace:  Demo3D.Visuals
Assembly:  Demo3D.Core (in Demo3D.Core.dll) Version: 15.0.2.11458
Syntax
C#
[SerializableAttribute]
public class UserResource

The UserResource type exposes the following members.

Constructors
  NameDescription
Public methodUserResource
Initializes a new instance of the UserResource class.
Top
Properties
  NameDescription
Public propertyCreated
Gets the time at which this resource was created (not when the original file was created).
Public propertyCode exampleLocalPath
Gets or sets the name and path of this user resource, relative to the UserResources directory. Never set this property directly, always go through UserResourceLibrary.RenameFile.
Public propertyPersistence
Gets or sets a value indicating whether this UserResource will remain in a UserResourceLibrary even when it's not referenced.
Public propertySourcePath
Gets the original path of the file.
Top
Methods
  NameDescription
Public methodCode exampleGetInputStream
Gets a Stream object which can be used to read the contents of the file.
Public methodHasSameContent
Checks whether the content of this UserResource matches the content of another UserResource instance.
Top
Examples
C#
[Auto] CustomPropertyValue<UserResourceReference> Data;

[Auto] void OnReset(BoxVisual sender) {
    if (!sender.HasProperty("Data")) return;

    var ur = document.FindUserResource(this.Data);
    var localFile = WriteUserResourceToTemporaryFile( ur );

    if (localFile == "") return;

    var dataTable =
        Demo3D.Utilities.DataSourceImporter.ReadDataTableFromTextFile( localFile );

    File.Delete( localFile );

    foreach (var colName in dataTable.Columns) {
        print(colName);
    }
}

string WriteUserResourceToTemporaryFile(UserResource ur) {
    if (ur == null) return "";

    var ins   = ur.GetInputStream(null);
    var len   = ins.Length;
    var bytes = new byte[len];

    ins.Read( bytes, 0, (int)len );

    var tmpFile = 
        Path.Combine( Path.GetTempPath(), Path.GetFileName(ur.LocalPath) );

    File.WriteAllBytes( tmpFile, bytes );

    return tmpFile;
}
See Also