rhyton.document¶
Module for modifying the rhino document. This is the only module in this package that actually modifies a Rhino file.
- class AffectedElements[source]¶
Bases:
objectClass for handling information on the objects affected by rhyton.
- static remove(flag, guids)[source]¶
Removes given guids from the document config storage saved under given flag.
- Parameters
guids (str) – A single or a list of Rhino object ids.
- static save(flag, data)[source]¶
Saves the guids of given elements to the document user text. This allows rhyton to keep track of the elements it’s modifying.
The input ‘data’ should contain information on the previous or new state of the affected objects alongside their guid:
Example:
{<guid>: {'key1': 'value1'}}
- Parameters
flag (str) – The identifier for the data.
data (dict) – A dictionary of guids with a dictionary as values.
- class DocumentConfigStorage[source]¶
Bases:
objectClass for handling the reading and writing of document user text.
- get(flag, default=None)[source]¶
Gets the data stored under given flag.
Example:
config = rhyton.DocumentConfigStorage() item = config.get('name')
- Parameters
flag (str) – The identifier for the data.
default (mixed, optional) – An optional default value. Defaults to None.
- Returns
The data stored under given flag.
- Return type
mixed
- class ElementOverrides[source]¶
Bases:
objectClass for handling color overrides on Rhino objects.
- OVERRIDE_PROGRESS = 'Color Overrides...'¶
- classmethod apply(overrides)[source]¶
Sets the colors for given elements. The original colors and color sources will be stored alongside the objects id in the document user text. When an objects is overridden by rhyton for a second time, the original color and color source will remain as they are.
Examples:
ElementOverrides.apply( [ { "guid": [<guid1>, <guid2>], "color": <hexvalue1> }, { "guid": <guid3>, "color": <hexvalue2> } ]) # or ElementOverrides.apply( { "guid": <guid>, "color": <hexvalue> })
- Parameters
overrides (list(dict)) – A dictionary or a list of dictionaries.
- classmethod clear(guids, clearSource=False)[source]¶
Clear the color overrides for given objects. The original colors will be restored from the
Document Text.- Parameters
guids (str) – The ids of the objects.
clearSource (bool, optional) – If
True, the color source will be set to0. Defaults toFalse.
- class ElementUserText[source]¶
Bases:
objectClass for handling user text on Rhino objects.
- static aggregate(guids, keys=[])[source]¶
Aggregates user text values from given objects. Non-numeric values will cause an error.
- Parameters
guids (str) – A list of Rhino objects ids.
keys (list, optional) – A list of keys. Defaults to [].
- Returns
The sum of all values.
- Return type
float
- static apply(data)[source]¶
Applies given user text to provided elements. The expected input format for ‘data’ is a dictionary containing the guid as well as at least one user text key:
Examples:
ElementUserText.apply( [ { "guid": [<guid1>, <guid2>], "string_key": "Value", "number_key": 0 }, { "guid": <guid3>, "string_key": "Value", "number_key": 0 } ]) # or ElementUserText.apply( { "guid": <guid>, "string_key": "Value", "number_key": 0 })
Due to Rhino’s limitations, all values will be stored as strings.
- Parameters
data (list(dict)) – A list of dictionaries describing the
keyPrefix (str, optional) – The prefix for all keys. Defaults to “”.
- static get(guids, keys=None)[source]¶
Gets user text from given elements.
Return format:
[ { "guid": <guid1>, "example_key1": "example_value1" "example_key2": "example_value2" } ]
- Parameters
guids (list(str)) – A list of Rhino objects ids.
keys (list(str), optional) – A list of keys. By default, all keys are returned.
- Returns
A list of dictionaries.
- Return type
list
- static getKeys(guids)[source]¶
Gets a complete set of unique user text keys from given objects.
- Parameters
guids (str) – A list of Rhino objects ids.
- static getValue(guid, key)[source]¶
Wrapper function to get user text from an objects
- Parameters
guid (str) – A rhino objects id.
key (str) – The key to get the value from.
- Returns
None if key does not exist, ” ” if key has no value, else: str of value
- Return type
mixed
- GetBreps(filterByTypes=[8, 16, 1073741824])[source]¶
Gets the currently selected Rhino objects or asks the user to go get some.
Allowed objects are by default:
8 = Surface 16 = Polysurface 8192 = Text Dot 1073741824 = Extrusion
- Returns
A list of Rhino objects ids.
- Return type
list[str]
- GetFilePath(ExtensionFilter)[source]¶
Gets a file path from the user.
- Parameters
ExtensionFilter (str) – The file extension filter.
- Returns
The file path.
- Return type
str
- GetUnitSystem(abbreviate=False)[source]¶
Gets the current Rhino units.
- Returns
The current Rhino units.
- Return type
str
- class Group[source]¶
Bases:
objectClass for handling Rhino groups.
- class Layer[source]¶
Bases:
objectClass for handling layer information.
- static addLayerHierarchy(guids, depth)[source]¶
Add the layer name for each depth level of sublayers to given entries.
- Parameters
data (dict) – A dictionary or list of dictionaries.
depth (int) – The maximum depth of sublayer names to add.
- classmethod hierarchyInformation(guids)[source]¶
Context manager function to temporarlily add layer information to the user text of given Rhino objects.
- Parameters
guids (list(str)) – A list of Rhino object ids.
- class TextDot[source]¶
Bases:
objectClass for handling Rhino text dot objects.
- static add(data, valueKey, aggregate=True, prefixKey=None)[source]¶
Adds a new text dot to the document. The textdot location is the center of the bounding box of given guid(s). Provide a list of guids, if you want to place the text dot in the middle of multiple objects.
Note
The input dictionary can contain unrelated keys - they will be ignored.
This allows you to use the same input for ‘’TextDot.add’’ and ‘’ElementOverrides.apply’’
Examples:
TextDot.add( [ { "guid": [<guid1>, <guid2>], "color": <color1> }, { "guid": <guid3>, "color": <color2> } ]) # or TextDot.add( { "guid": <guid>, "color": <display color> })
- Parameters
dict (list(dict)) – A dictionary or list of dictionaires.
valueKey (str) – The key to aggregate or count values.
prefix (str, optional) – The text to display before the value.
- Returns
The input list of dicts with the guids of the text dots added.
- Return type
list