WorksessionFile

ReferencesSince v9.0
public sealed class WorksessionFile : IDisposable
Reads and writes Rhino worksession (.rws) files. A worksession file lists models and a worksession's layer overrides. It does not contain any model content, and nothing here opens or checks the model files it lists.
Remarks: Rhino 4 wrote version 4 files. Rhino 5 and later write version 5. Both versions can be read and written. Models are exchanged by value: GetModel(int) returns a copy, and changes to it are kept only after SetModel(int, WorksessionFileModel).

Constructors

WorksessionFile

#Since v9.0
public WorksessionFile()
Creates an empty worksession with no models.

WorksessionFile

#Since v9.0
public WorksessionFile(WorksessionFile other)
Creates a copy of another worksession.
other (WorksessionFile)The worksession to copy.
ArgumentNullExceptionIf other is null.

Finalizer

~WorksessionFile

#
~WorksessionFile()
Releases the native worksession.

Properties

ActiveModelIndex

#Since v9.0
public int ActiveModelIndex { get; }
Gets the index of the first active model, or -1 if there is no active model.

CurrentVersion

#Since v9.0
public static int CurrentVersion { get; }
The worksession file version Rhino 5 and later write.

ModelCount

#Since v9.0
public int ModelCount { get; }
Gets the number of models.

Version

#Since v9.0
public int Version { get; set; }
Gets or sets the file version. Reading sets it to the version of the file that was read. Writing does not use it.
ArgumentOutOfRangeExceptionIf the value is negative.

Methods

AddModel

#Since v9.0
public void AddModel(WorksessionFileModel model)
Adds a copy of a model to the end of the list.
model (WorksessionFileModel)The model to copy.
ArgumentNullExceptionIf model is null.

ClearModels

#Since v9.0
public void ClearModels()
Removes all of the models.

Dispose

#Since v9.0
public void Dispose()
Releases the native worksession.

Dump

#Since v9.0
public string Dump()
Describes the worksession: its version, and for each model its paths and saved layer settings. For each saved layer it gives its name and the settings Rhino uses.

FromByteArray

#Since v9.0
public static WorksessionFile FromByteArray(byte[] bytes)
Reads a worksession from the contents of a worksession file.
bytes (byte[])The contents of a .rws file.
The worksession, or null if the bytes could not be read, including the contents of a worksession file from a newer version of Rhino.
ArgumentNullExceptionIf bytes is null.

GetModel

#Since v9.0
public WorksessionFileModel GetModel(int index)
Gets a copy of a model.
index (int)Index of the model.
A copy of the model. Changes to it are kept only after SetModel(int, WorksessionFileModel).
ArgumentOutOfRangeExceptionIf index is out of range.

GetModels

#Since v9.0
public WorksessionFileModel[] GetModels()
Gets copies of all of the models.

Read

#Since v9.0
public static WorksessionFile Read(string path)
Reads a worksession file.
path (string)The file to read.
The worksession, or null if the file could not be read. That includes a worksession file from a newer version of Rhino: ReadFileVersion(string) returns a version greater than CurrentVersion for those, and 0 for a file that is not a worksession file.
ArgumentNullExceptionIf path is null.

ReadFileVersion

#Since v9.0
public static int ReadFileVersion(string path)
Reads only the version from the header of a worksession file.
path (string)The file to read.
The file's version, or 0 if the file cannot be read or is not a worksession file. A version greater than CurrentVersion is from a newer version of Rhino.
ArgumentNullExceptionIf path is null.

RemoveModelAt

#Since v9.0
public void RemoveModelAt(int index)
Removes a model.
index (int)Index of the model to remove.
ArgumentOutOfRangeExceptionIf index is out of range.

SetModel

#Since v9.0
public void SetModel(int index, WorksessionFileModel model)
Replaces a model with a copy of another.
index (int)Index of the model to replace.
model (WorksessionFileModel)The model to copy.
ArgumentNullExceptionIf model is null.
ArgumentOutOfRangeExceptionIf index is out of range.

ToByteArray

#Since v9.0
public byte[] ToByteArray()
Writes the worksession as the contents of a version 5 .rws file.
The file contents, or null if the worksession could not be written.

ToByteArray

#Since v9.0
public byte[] ToByteArray(int version)
Writes the worksession as the contents of a .rws file.
version (int)4 or 5.
The file contents, or null if the worksession could not be written.

Write

#Since v9.0
public bool Write(string path, int version)
Writes a worksession file.
path (string)The file to write.
version (int)4 or 5. Version 4 needs exactly one active model and saves only the model file paths.
True if the file was written. If false is returned, an existing file is left as it was.
ArgumentNullExceptionIf path is null.

Write

#Since v9.0
public bool Write(string path)
Writes a version 5 worksession file.
Remarks: The first active model is written first and the other models follow in order. Models with an empty full path are not written. Paths are written as they are, and are not checked or changed.
path (string)The file to write.
True if the file was written. If false is returned, an existing file is left as it was.
ArgumentNullExceptionIf path is null.