Worksession

References
public sealed class Worksession
Manages a list of models that are being used as reference geometry.

Properties

Document

#Since v6.0
public RhinoDoc Document { get; }
Gets the document that owns this worksession.

FileName

#Since v6.0
public string FileName { get; }
Returns the path to the open worksession, or .rws, file. If there is no worksession file open, or the active worksession has not yet been saved, then null is returned.

ModelCount

#Since v6.0
public int ModelCount { get; }
Returns the number of models in the worksession. The active model will included in this count whether or not it has been saved.

ModelPaths

#Since v6.0
public string[] ModelPaths { get; }
Returns the paths to the models used by the worksession. If the active model has not been saved, then it will not be included in the output array.

Models

#Since v9.0
public WorksessionModel[] Models { get; }
The models in this worksession, including the active model.

WorksessionModel.UpdateAvailable is filled in, so this reports the same state the Worksessions panel shows. Use GetModels(bool) with false to skip that check.

Name

#Since v9.0
public string Name { get; }
Gets the name of the worksession - the worksession (.rws) file name without its path or extension. Returns an empty string if there is no worksession file open, or the active worksession has not yet been saved; it is up to the caller to decide what to display in that case.

RuntimeSerialNumber

#Since v6.3
[CLSCompliant(false)] public uint RuntimeSerialNumber { get; }
Unique serial number for the worksession while the application is running. This is not a persistent value.

Since Rhino 9 worksessions are per-document and no longer have serial numbers of their own, so this returns Document's RhinoDoc.RuntimeSerialNumber. Prefer that property in new code.

Methods

Attach

#Since v9.0
public bool Attach(string path)
Attaches a model to this worksession as a reference model.
Remarks: The model is attached to this worksession's document, which need not be the active document. No user interface is displayed.
path (string)The full path to the .3dm file to attach.
True if the model was attached, false otherwise.

Attach

#Since v9.0
public int Attach(IEnumerable<string> paths)
Attaches several models to this worksession as reference models.
paths (IEnumerable<string>)The full paths to the .3dm files to attach.
The number of models that were attached.

Detach

#Since v9.0
[CLSCompliant(false)] public bool Detach(IEnumerable<uint> modelSerialNumbers)
Detaches several reference models from this worksession.
modelSerialNumbers (IEnumerable<uint>)The reference models' serial numbers, from WorksessionModel.SerialNumber.
True if at least one model was detached, false otherwise.

Detach

#Since v9.0
[CLSCompliant(false)] public bool Detach(uint modelSerialNumber)
Detaches a reference model from this worksession.
Remarks: The active model - serial number 0 - cannot be detached.
modelSerialNumber (uint)The reference model's serial number, from WorksessionModel.SerialNumber.
True if the model was detached, false otherwise.

FileNameFromRuntimeSerialNumber

#Since v6.3
[CLSCompliant(false)] public static string FileNameFromRuntimeSerialNumber(uint runtimeSerialNumber)
Returns the path to the open worksession, or .rws, file. If there is no worksession file open, or the active worksession has not yet been saved, then null is returned.
runtimeSerialNumber (uint)Since Rhino 9 worksessions are per-document and no longer have serial numbers of their own, so this is a document's RhinoDoc.RuntimeSerialNumber. In new code, prefer getting the document and using its RhinoDoc.Worksession FileName.
The path to the .rws file, or null.

GetLockInformation

#Since v9.0
public static string GetLockInformation(string modelPath)
Describes whether a worksession model's file is locked, and by whom.
Remarks: This reads the file's lock file and does not depend on any document, which is why it is static.
modelPath (string)The full path to the model's file.
A localized description of the file's lock state, or an empty string if it could not be determined.

GetModels

#Since v9.0
public WorksessionModel[] GetModels(bool checkForUpdates)
The models in this worksession, including the active model.
checkForUpdates (bool)True to fill in WorksessionModel.UpdateAvailable for each model. This compares each referenced file's size and last modified time against the values stored when the file was attached, which opens and stats each file once - no file contents are read, so the cost does not grow with the size of the models, but it is still one round trip per model. Pass false to skip it, for example when reading this repeatedly or when the models live on a slow network share.
The models in the worksession, or an empty array if there are none.

ModelPathFromSerialNumber

#Since v6.12
[CLSCompliant(false)] public string ModelPathFromSerialNumber(uint modelSerialNumber)
Returns the path to a model, used by the worksession, given a reference model serial number
modelSerialNumber (uint)The reference model serial number.
The path to the model if successful, null otherwise.

Open

#Since v9.0
public static RhinoDoc Open(string path)
Opens a worksession (.rws) file.
Remarks:

Opening a worksession is a document-level operation rather than a change to an existing worksession, which is why this is static. Always use the returned document: it may be the current document, reused, or a newly created one, depending on the platform and on whether the current document can be reused. On Windows, other than headless, the current document is closed and replaced.

As with SetActiveModel(uint), do not call this from a script running in a document that this might close.

path (string)The full path to the .rws file to open.
The document the worksession was read into, or null on failure.

Save

#Since v9.0
public bool Save()
Saves this worksession to its existing .rws file.
True if successful. False if the worksession has never been saved, in which case use SaveAs(string) to supply a path.

SaveAs

#Since v9.0
public bool SaveAs(string path)
Saves this worksession to a .rws file.
path (string)The full path to write to.
True if successful, false otherwise.

SetActiveModel

#Since v9.0
[CLSCompliant(false)] public RhinoDoc SetActiveModel(uint modelSerialNumber)
Makes one of this worksession's reference models the active model.
Remarks:

Changing the active model loads the requested model into a different document, so carry on with the returned document: treat Document and this Worksession instance as unusable once this returns.

The document this was called on is closed as part of the switch, but on Mac that close is asynchronous and may not have finished when this returns. Do not rely on the old document either still being open or already being gone.

This is not fully silent: if the outgoing document has unsaved changes the user is prompted to save it, and cancelling that prompt makes this return null. Save the document first if you need it to run unattended.

Do not call this from a script that is itself running in the document being replaced. Scripts run in a document context, and closing that document from underneath the running script leaves Rhino's command machinery working with a document that no longer exists. Drive this from a command, a panel, or an idle handler instead.

modelSerialNumber (uint)The reference model's serial number, from WorksessionModel.SerialNumber.
The document the worksession is now using, or null on failure.

Update

#Since v9.0
[CLSCompliant(false)] public bool Update(uint modelSerialNumber)
Re-reads a reference model whose file has changed on disk.
modelSerialNumber (uint)The reference model's serial number, from WorksessionModel.SerialNumber. Pass 0 to update every out-of-date reference model in this worksession.
True if successful, false otherwise.

UpdateAll

#Since v9.0
public bool UpdateAll()
Re-reads every reference model in this worksession whose file has changed on disk.
True if successful, false otherwise.