diff --git a/archicad-addon/Examples/highlight_selected_elements.py b/archicad-addon/Examples/highlight_selected_elements.py index 6bf4a14..3238599 100644 --- a/archicad-addon/Examples/highlight_selected_elements.py +++ b/archicad-addon/Examples/highlight_selected_elements.py @@ -15,7 +15,8 @@ commandName = 'HighlightElements' commandParameters = { 'elements' : response['elements'], - 'highlightedColor' : [255, 0, 0, 255], + 'highlightedColors' : [[(i*10) % 255, 0, 0, 255] for i in len(response['elements'])], + 'wireframe3D' : True, 'nonHighlightedColor' : [0, 0, 255, 128] } diff --git a/archicad-addon/Sources/ElementCommands.cpp b/archicad-addon/Sources/ElementCommands.cpp index 37ba6ae..a2df2aa 100644 --- a/archicad-addon/Sources/ElementCommands.cpp +++ b/archicad-addon/Sources/ElementCommands.cpp @@ -781,18 +781,26 @@ GS::Optional HighlightElementsCommand::GetInputParametersSchema ( "elements": { "$ref": "#/Elements" }, - "highlightedColor": { + "highlightedColors": { "type": "array", - "description": "Color of the highlighted elements as an [r, g, b, a] array. Each component must be in the 0-255 range.", + "description": "A list of colors to highlight elements.", "items": { - "type": "integer" - }, - "minItems": 4, - "maxItems": 4 + "type": "array", + "description": "Color of the highlighted element as an [r, g, b, a] array. Each component must be in the 0-255 range.", + "items": { + "type": "integer" + }, + "minItems": 4, + "maxItems": 4 + } + }, + "wireframe3D": { + "type": "boolean", + "description" : "Optional parameter. Switch non highlighted elements in the 3D window to wireframe." }, "nonHighlightedColor": { "type": "array", - "description": "Color of the non highlighted elements as an [r, g, b, a] array. Each component must be in the 0-255 range.", + "description": "Optional parameter. Color of the non highlighted elements as an [r, g, b, a] array. Each component must be in the 0-255 range.", "items": { "type": "integer" }, @@ -803,8 +811,7 @@ GS::Optional HighlightElementsCommand::GetInputParametersSchema ( "additionalProperties": false, "required": [ "elements", - "highlightedColor", - "nonHighlightedColor" + "highlightedColors" ] })"; } @@ -814,48 +821,62 @@ GS::Optional HighlightElementsCommand::GetResponseSchema () const return {}; } +static GS::Optional GetRGBAColorFromObjectState (const GS::ObjectState& os, const GS::String& name) +{ + GS::Array color; + if (os.Get (name, color)) { + return API_RGBAColor { + color[0] / 255.0, + color[1] / 255.0, + color[2] / 255.0, + color[3] / 255.0 + }; + } else { + return {}; + } +} + GS::ObjectState HighlightElementsCommand::Execute (const GS::ObjectState& parameters, GS::ProcessControl& /*processControl*/) const { - GS::Array elementIdArray; - parameters.Get ("elements", elementIdArray); - - GS::Array highlightedColorArray; - parameters.Get ("highlightedColor", highlightedColorArray); - API_RGBAColor highlightedColor { - highlightedColorArray[0] / 255.0, - highlightedColorArray[1] / 255.0, - highlightedColorArray[2] / 255.0, - highlightedColorArray[3] / 255.0 - }; - - GS::Array nonHighlightedColorArray; - parameters.Get ("nonHighlightedColor", nonHighlightedColorArray); - API_RGBAColor nonHighlightedColor { - nonHighlightedColorArray[0] / 255.0, - nonHighlightedColorArray[1] / 255.0, - nonHighlightedColorArray[2] / 255.0, - nonHighlightedColorArray[3] / 255.0 - }; - - GS::HashTable elements; - for (const GS::ObjectState& elementIdArrayItem : elementIdArray) { - GS::ObjectState elementId; - elementIdArrayItem.Get ("elementId", elementId); + GS::Array elements; + parameters.Get ("elements", elements); + + if (elements.IsEmpty ()) { + ACAPI_UserInput_ClearElementHighlight (); + // need to call redraw for changes to take effect + ACAPI_View_Redraw (); + return {}; + } - GS::UniString guidStr; - elementId.Get ("guid", guidStr); + GS::Array highlightedColors; + parameters.Get ("highlightedColors", highlightedColors); - GS::Guid guid (guidStr); - API_Guid apiGuid = GSGuid2APIGuid (guid); - elements.Add (apiGuid, highlightedColor); + if (highlightedColors.GetSize () != elements.GetSize ()) { + return CreateErrorResponse (APIERR_BADPARS, "The size of 'elements' array and 'highlightedColors' array does not match."); } - if (!elements.IsEmpty ()) { - ACAPI_UserInput_SetElementHighlight (elements, GS::NoValue, nonHighlightedColor); - } else { - ACAPI_UserInput_ClearElementHighlight (); + GS::HashTable elementsWithColors; + for (USize i = 0; i < elements.GetSize (); ++i) { + GS::ObjectState elementId; + if (elements[i].Get ("elementId", elementId)) { + const API_Guid elemGuid = GetGuidFromObjectState (elementId); + const GS::Optional color = GetRGBAColorFromObjectState (highlightedColors[i], "nonHighlightedColor"); + if (color.HasValue ()) { + elementsWithColors.Add (elemGuid, *color); + } + } + } + + GS::Optional wireframe3D; + bool tmp; + if (parameters.Get ("wireframe3D", tmp)) { + wireframe3D = tmp; } + const GS::Optional nonHighlightedColor = GetRGBAColorFromObjectState (parameters, "nonHighlightedColor"); + + ACAPI_UserInput_SetElementHighlight (elementsWithColors, wireframe3D, nonHighlightedColor); + // need to call redraw for changes to take effect ACAPI_View_Redraw (); diff --git a/docs/archicad-addon/command_definitions.js b/docs/archicad-addon/command_definitions.js index 312f5f8..577b0d5 100644 --- a/docs/archicad-addon/command_definitions.js +++ b/docs/archicad-addon/command_definitions.js @@ -366,41 +366,48 @@ }, { name : "HighlightElements", - version : "1.0.1", + version : "1.0.3", description : "Highlights the elements given in the elements array. In case of empty elements array removes all previously set highlights.", inputScheme : { - "type": "object", - "properties": { - "elements": { - "$ref": "#/Elements" - }, - "highlightedColor": { - "type": "array", - "description": "Color of the highlighted elements as an [r, g, b, a] array. Each component must be in the 0-255 range.", - "items": { - "type": "integer" - }, - "minItems": 4, - "maxItems": 4 - }, - "nonHighlightedColor": { - "type": "array", - "description": "Color of the non highlighted elements as an [r, g, b, a] array. Each component must be in the 0-255 range.", - "items": { - "type": "integer" - }, - "minItems": 4, - "maxItems": 4 - } - }, - "additionalProperties": false, - "required": [ - "elements", - "highlightedColor", - "nonHighlightedColor" - ] - }, - outputScheme : null + "type": "object", + "properties": { + "elements": { + "$ref": "#/Elements" + }, + "highlightedColors": { + "type": "array", + "description": "A list of colors to highlight elements.", + "items": { + "type": "array", + "description": "Color of the highlighted element as an [r, g, b, a] array. Each component must be in the 0-255 range.", + "items": { + "type": "integer" + }, + "minItems": 4, + "maxItems": 4 + } + }, + "wireframe3D": { + "type": "boolean", + "description" : "Optional parameter. Switch non highlighted elements in the 3D window to wireframe." + }, + "nonHighlightedColor": { + "type": "array", + "description": "Optional parameter. Color of the non highlighted elements as an [r, g, b, a] array. Each component must be in the 0-255 range.", + "items": { + "type": "integer" + }, + "minItems": 4, + "maxItems": 4 + } + }, + "additionalProperties": false, + "required": [ + "elements", + "highlightedColors" + ] + }, + outputScheme : null }, { name : "MoveElements", diff --git a/python-package/src/tapir_py/core.py b/python-package/src/tapir_py/core.py index 682be52..93d81be 100644 --- a/python-package/src/tapir_py/core.py +++ b/python-package/src/tapir_py/core.py @@ -242,13 +242,14 @@ def GetProductInfo(self): result = response.get_result() return result['version'], result['buildNumber'], result['languageCode'] - def HighlightElements(self, elements, highlightedColor = [0, 150, 0, 100], nonHighlightedColor = [150, 0, 0, 100]): + def HighlightElements(self, elements, highlightedColors, wireframe3D = False, nonHighlightedColor = [150, 0, 0, 100]): """Highlights specified elements in current ArchiCAD document. Args: elements (:obj:`list` of :obj:`Element`): A list of elements. - highlightedColor (:obj:`list` of :int:): RGBA Color for highlighted objects. - nonHighlightedColor (:obj:`list` of :int:): RGBA Color for non-highlighted objects. + highlightedColors (:obj:`list` of :int:): RGBA Colors for highlighted elements. + wireframe3D (:bool:): Optional parameter. Switch non-highlighted elements in the 3D window to wireframe + nonHighlightedColor (:obj:`list` of :int:): Optional parameter. RGBA Color for non-highlighted elements. Returns: None @@ -256,10 +257,11 @@ def HighlightElements(self, elements, highlightedColor = [0, 150, 0, 100], nonHi Raises: Exception: If command was unsuccessful. """ - param_selected_color = Parameter("highlightedColor", highlightedColor) + param_selected_color = Parameter("highlightedColors", highlightedColors) + param_wireframe3D = Parameter("wireframe3D", wireframe3D) param_unselected_color = Parameter("nonHighlightedColor", nonHighlightedColor) param_elements = Parameter("elements", [element.ToDictionary() for element in elements]) - packed_params = Parameter.pack([param_elements, param_selected_color, param_unselected_color]) + packed_params = Parameter.pack([param_elements, param_selected_color, param_wireframe3D, param_unselected_color]) cmd = Command.FormatAddOnCommand("HighlightElements", packed_params)