Worksession

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

Properties

Document

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

FileName

#Since v6.0
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.
public string FileName { get; }

ModelCount

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

ModelPaths

#Since v6.0
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.
public string[] ModelPaths { get; }

Models

#Since v9.0
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.

public WorksessionModel[] Models { get; }

Name

#Since v9.0
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.
public string Name { get; }

RuntimeSerialNumber

#Since v6.3
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.

[CLSCompliant(false)] public uint RuntimeSerialNumber { get; }

Methods

Attach

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

Attach

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

Detach

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

Detach

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

FileNameFromRuntimeSerialNumber

#Since v6.3
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.
[CLSCompliant(false)] public static string FileNameFromRuntimeSerialNumber(
runtimeSerialNumber
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
Describes whether a worksession model's file is locked, and by whom.
public static string GetLockInformation(
modelPath
The full path to the model's file.
)
Remarks: This reads the file's lock file and does not depend on any document, which is why it is static.
A localized description of the file's lock state, or an empty string if it could not be determined.

GetModels

#Since v9.0
The models in this worksession, including the active model.
public WorksessionModel[] GetModels(
checkForUpdates
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
Returns the path to a model, used by the worksession, given a reference model serial number
[CLSCompliant(false)] public string ModelPathFromSerialNumber(
modelSerialNumber
The reference model serial number.
)
The path to the model if successful, null otherwise.

Open

#Since v9.0
Opens a worksession (.rws) file.
public static RhinoDoc Open(
path
The full path to the .rws file to open.
)
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.

The document the worksession was read into, or null on failure.

Save

#Since v9.0
Saves this worksession to its existing .rws file.
public bool Save()
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
Saves this worksession to a .rws file.
public bool SaveAs(
path
The full path to write to.
)
True if successful, false otherwise.

SetActiveModel

#Since v9.0
Makes one of this worksession's reference models the active model.
[CLSCompliant(false)] public RhinoDoc SetActiveModel(
modelSerialNumber
The reference model's serial number, from WorksessionModel.SerialNumber.
)
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.

The document the worksession is now using, or null on failure.

Update

#Since v9.0
Re-reads a reference model whose file has changed on disk.
[CLSCompliant(false)] public bool Update(
modelSerialNumber
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
Re-reads every reference model in this worksession whose file has changed on disk.
public bool UpdateAll()
True if successful, false otherwise.