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
Creates an empty worksession with no models.
public WorksessionFile()

WorksessionFile

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

Finalizer

~WorksessionFile

#
Releases the native worksession.
~WorksessionFile()

Properties

ActiveModelIndex

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

CurrentVersion

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

ModelCount

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

Version

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

Methods

AddModel

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

ClearModels

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

Dispose

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

Dump

#Since v9.0
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.
public string Dump()

FromByteArray

#Since v9.0
Reads a worksession from the contents of a worksession file.
public static WorksessionFile FromByteArray(
byte[]
bytes
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
Gets a copy of a model.
public WorksessionFileModel GetModel(
index
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
Gets copies of all of the models.
public WorksessionFileModel[] GetModels()

Read

#Since v9.0
Reads a worksession file.
public static WorksessionFile Read(
path
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
Reads only the version from the header of a worksession file.
public static int ReadFileVersion(
path
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
Removes a model.
public void RemoveModelAt(
index
Index of the model to remove.
)
ArgumentOutOfRangeExceptionIf index is out of range.

SetModel

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

ToByteArray

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

ToByteArray

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

Write

#Since v9.0
Writes a worksession file.
public bool Write(
path,
The file to write.
version
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
Writes a version 5 worksession file.
public bool Write(
path
The file to write.
)
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.
True if the file was written. If false is returned, an existing file is left as it was.
ArgumentNullExceptionIf path is null.