mastoron.colors

class Color[source]

Bases: object

Class for basic color operations.

static HEXtoRGB(hex)[source]

Converts a hex color string to rgb.

Parameters

hex (sting) – The hex color

Returns

The rgb color

Return type

tuple

static HSVtoRGB(hsv)[source]

Convert a color from hsv to rgb.

Parameters

hsv (tuple) – A color in hsv format.

Returns

A color in rgb format

Return type

tuple

static RGBtoHEX(rgb)[source]
__init__()[source]

Inits a new Color instance.

class ColorRange(count, min=0, max=100)[source]

Bases: object

Class for working with color ranges.

__init__(count, min=0, max=100)[source]

Inits a new ColorRange instance.

Accepted values:

0 <= min < 100
1 < max <= 100
count < max - min
getHSV()[source]

Gets a list of colors in hsv format.

Returns

A list of hsv colors

Return type

list

class ColorScheme[source]

Bases: object

Class for handling relationships between labels and colors.

JSON_PATH = 'C:\\temp\\mastoron\\colorscheme.json'
__init__()[source]

Inits a new ColorScheme instance.

static apply(view, elements, schemeName, isInstance, type, patternId)[source]

Applies a mastoron color scheme to given elements in given view. Updates the colors scheme with new keys and colors.

Parameters
  • view (object) – A Revit view

  • elements (object) – A list of Revit elements

  • schemeName (string) – The name of the color scheme

  • isInstance (bool) – True for instance parameters, false for type parameters

  • type (string) – The type of the parameter (Area, Number, Length, etc..)

  • patternId (object) – The Revit element id of the fillpattern to use

Returns

The applied and updated color scheme

Return type

dict

delete(scheme)[source]

Deletes a color scheme from the revitron DocumenConfigStorage.

Parameters

scheme (dict) – A color scheme

static fromJSON(path)[source]

Reads a color scheme from json.

Parameters

path (string) – The json file

Returns

The color scheme

Return type

dict

generate(schemeName, keys, isInstance=None, paramType=None, excludeColors=None, gradient=False)[source]

Generates a new color scheme.

Parameters
  • schemeName (string) – The name of the color scheme

  • keys (string) – A set of keys

  • excludeColors (string, optional) – A list of colors to exclude

  • gradient (int, optional) – A tuple with start and end color

Returns

A color scheme: {name: schemeName, data: {key: color}}

Return type

dict

getColors(count, excludeColors=[])[source]

Gets a given amount of colors.

Parameters
  • count (int) – The number of colors to get

  • excludeColors (string, optional) – List of colors to exclude. Defaults to None.

Returns

A list of colors

Return type

string

static getFromUser(excludeSchemes=None, excludeViews=None)[source]

Asks the user to select a mastoron color scheme.

Parameters
  • excludeSchemes (string, optional) – The name of one or more schemes to exclude. Defaults to None.

  • excludeViews (string, optional) – The id(s) of one ore more views to exclude. Defaults to None.

Returns

The selected mastoron color scheme

Return type

dict

load(schemeName)[source]

Loads a color scheme by name.

Parameters

schemeName (string) – The name of the color scheme

Returns

The color scheme

Return type

dict

save(scheme)[source]

Saves a color scheme to the revitron DocumentConfigStorage.

Parameters

scheme (dict) – A color scheme

static toJSON(data, path='C:\\temp\\mastoron\\colorscheme.json')[source]

Write color scheme to json

Parameters
  • data (dict) – The data to export

  • path (str, optional) – The output file path. Defaults to ‘C: empmastoroncolorscheme.json’.

Returns

The json file

Return type

string

update(colorScheme, keys)[source]

Updates a given color scheme with new keys and default colors.

Parameters
  • colorScheme (dict) – The color scheme to update

  • keys (set) – The keys to add

Returns

The updated color scheme

Return type

dict