Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New commands: SetDetailsOfElements, GetAllElements, GetElementsByType #173

Merged
merged 7 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions archicad-addon/Examples/filter_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import itertools

print ('-' * 30)
allElements = aclib.RunCommand ('API.GetAllElements', {})['elements']
allElements = aclib.RunTapirCommand ('GetAllElements', {}, debug=False)['elements']
print ('All elements = {}'.format (len (allElements)))
print ('-' * 30)

typesOfElements = aclib.RunCommand ('API.GetTypesOfElements', {'elements':allElements})['typesOfElements']
detailsOfElements = aclib.RunTapirCommand ('GetDetailsOfElements', {'elements': allElements}, debug=False)['detailsOfElements']
typeCounterDict = dict()
for typeOfElement in typesOfElements:
if 'typeOfElement' in typeOfElement and 'elementType' in typeOfElement['typeOfElement']:
elementType = typeOfElement['typeOfElement']['elementType']
for detailsOfElement in detailsOfElements:
if 'type' in detailsOfElement:
elementType = detailsOfElement['type']
if elementType not in typeCounterDict:
typeCounterDict[elementType] = 1
else:
Expand Down
1 change: 0 additions & 1 deletion archicad-addon/Examples/generate_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@
}

response = aclib.RunTapirCommand (commandName, commandParameters)
print (response)
20 changes: 20 additions & 0 deletions archicad-addon/Examples/get_and_set_details_of_elements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import aclib

walls = aclib.RunTapirCommand ('GetElementsByType', {'elementType': 'Wall', 'filters': ['IsVisibleIn3D']})['elements']
columns = aclib.RunTapirCommand ('GetElementsByType', {'elementType': 'Column', 'filters': ['IsVisibleIn3D']})['elements']

detailsOfElements = aclib.RunTapirCommand ('GetDetailsOfElements', {'elements': walls + columns})['detailsOfElements']

wallsWithChangedDetails = []
for i in range(len(walls)):
wallsWithChangedDetails.append ({
'elementId': walls[i]['elementId'],
'details': {
'layerIndex': detailsOfElements[i]['layerIndex'] + 1,
'floorIndex': detailsOfElements[i]['floorIndex'] + 1
}
})

response = aclib.RunTapirCommand ('SetDetailsOfElements', {'elementsWithDetails': wallsWithChangedDetails})

detailsOfElements = aclib.RunTapirCommand ('GetDetailsOfElements', {'elements': walls})['detailsOfElements']
6 changes: 0 additions & 6 deletions archicad-addon/Examples/get_details_of_elements.py

This file was deleted.

26 changes: 14 additions & 12 deletions archicad-addon/Sources/AddOnMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@
#include "ClassificationCommands.hpp"
#include "MigrationHelper.hpp"

#ifdef DEBUG
static const bool IsDebugBuild = true;
#else
static const bool IsDebugBuild = false;
#endif

template <typename CommandType>
GSErrCode RegisterCommand (CommandGroup& group, const GS::UniString& version, const GS::UniString& description)
{
Expand Down Expand Up @@ -77,9 +71,7 @@ GSErrCode RegisterInterface (void)
{
GSErrCode err = NoError;

if (IsDebugBuild) {
err |= ACAPI_MenuItem_RegisterMenu (ID_ADDON_MENU, 0, MenuCode_UserDef, MenuFlag_Default);
}
err |= ACAPI_MenuItem_RegisterMenu (ID_ADDON_MENU, 0, MenuCode_UserDef, MenuFlag_Default);

return err;
}
Expand All @@ -88,9 +80,7 @@ GSErrCode Initialize (void)
{
GSErrCode err = NoError;

if (IsDebugBuild) {
err |= ACAPI_MenuItem_InstallMenuHandler (ID_ADDON_MENU, MenuCommandHandler);
}
err |= ACAPI_MenuItem_InstallMenuHandler (ID_ADDON_MENU, MenuCommandHandler);

{ // Application Commands
CommandGroup applicationCommands ("Application Commands");
Expand Down Expand Up @@ -152,6 +142,14 @@ GSErrCode Initialize (void)
elementCommands, "0.1.0",
"Gets the list of the currently selected elements."
);
err |= RegisterCommand<GetElementsByTypeCommand> (
elementCommands, "1.0.7",
"Returns the identifier of every element of the given type on the plan. It works for any type. Use the optional filter parameter for filtering."
);
err |= RegisterCommand<GetAllElementsCommand> (
elementCommands, "1.0.7",
"Returns the identifier of all elements on the plan. Use the optional filter parameter for filtering."
);
err |= RegisterCommand<ChangeSelectionOfElementsCommand> (
elementCommands, "1.0.7",
"Adds/removes a number of elements to/from the current selection."
Expand All @@ -164,6 +162,10 @@ GSErrCode Initialize (void)
elementCommands, "1.0.7",
"Gets the details of the given elements (geometry parameters etc)."
);
err |= RegisterCommand<SetDetailsOfElementsCommand> (
elementCommands, "1.0.7",
"Sets the details of the given elements (floor, layer, order etc)."
);
err |= RegisterCommand<GetSubelementsOfHierarchicalElementsCommand> (
elementCommands, "1.0.6",
"Gets the subelements of the given hierarchical elements."
Expand Down
77 changes: 77 additions & 0 deletions archicad-addon/Sources/CommandBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,81 @@ GS::UniString GetElementTypeNonLocalizedName (API_ElemTypeID typeID)
case API_OpeningID: return "Opening";
default: return "Unknown";
}
}

API_ElemTypeID GetElementTypeFromNonLocalizedName (const GS::UniString& typeStr)
{
if (typeStr == "Wall") return API_WallID;
if (typeStr == "Column") return API_ColumnID;
if (typeStr == "Beam") return API_BeamID;
if (typeStr == "Window") return API_WindowID;
if (typeStr == "Door") return API_DoorID;
if (typeStr == "Object") return API_ObjectID;
if (typeStr == "Lamp") return API_LampID;
if (typeStr == "Slab") return API_SlabID;
if (typeStr == "Roof") return API_RoofID;
if (typeStr == "Mesh") return API_MeshID;
if (typeStr == "Dimension") return API_DimensionID;
if (typeStr == "RadialDimension") return API_RadialDimensionID;
if (typeStr == "LevelDimension") return API_LevelDimensionID;
if (typeStr == "AngleDimension") return API_AngleDimensionID;
if (typeStr == "Text") return API_TextID;
if (typeStr == "Label") return API_LabelID;
if (typeStr == "Zone") return API_ZoneID;
if (typeStr == "Hatch") return API_HatchID;
if (typeStr == "Line") return API_LineID;
if (typeStr == "PolyLine") return API_PolyLineID;
if (typeStr == "Arc") return API_ArcID;
if (typeStr == "Circle") return API_CircleID;
if (typeStr == "Spline") return API_SplineID;
if (typeStr == "Hotspot") return API_HotspotID;
if (typeStr == "CutPlane") return API_CutPlaneID;
if (typeStr == "Camera") return API_CameraID;
if (typeStr == "CamSet") return API_CamSetID;
if (typeStr == "Group") return API_GroupID;
if (typeStr == "SectElem") return API_SectElemID;
if (typeStr == "Drawing") return API_DrawingID;
if (typeStr == "Picture") return API_PictureID;
if (typeStr == "Detail") return API_DetailID;
if (typeStr == "Elevation") return API_ElevationID;
if (typeStr == "InteriorElevation") return API_InteriorElevationID;
if (typeStr == "Worksheet") return API_WorksheetID;
if (typeStr == "Hotlink") return API_HotlinkID;
if (typeStr == "CurtainWall") return API_CurtainWallID;
if (typeStr == "CurtainWallSegment") return API_CurtainWallSegmentID;
if (typeStr == "CurtainWallFrame") return API_CurtainWallFrameID;
if (typeStr == "CurtainWallPanel") return API_CurtainWallPanelID;
if (typeStr == "CurtainWallJunction") return API_CurtainWallJunctionID;
if (typeStr == "CurtainWallAccessory") return API_CurtainWallAccessoryID;
if (typeStr == "Shell") return API_ShellID;
if (typeStr == "Skylight") return API_SkylightID;
if (typeStr == "Morph") return API_MorphID;
if (typeStr == "ChangeMarker") return API_ChangeMarkerID;
if (typeStr == "Stair") return API_StairID;
if (typeStr == "Riser") return API_RiserID;
if (typeStr == "Tread") return API_TreadID;
if (typeStr == "StairStructure") return API_StairStructureID;
if (typeStr == "Railing") return API_RailingID;
if (typeStr == "RailingToprail") return API_RailingToprailID;
if (typeStr == "RailingHandrail") return API_RailingHandrailID;
if (typeStr == "RailingRail") return API_RailingRailID;
if (typeStr == "RailingPost") return API_RailingPostID;
if (typeStr == "RailingInnerPost") return API_RailingInnerPostID;
if (typeStr == "RailingBaluster") return API_RailingBalusterID;
if (typeStr == "RailingPanel") return API_RailingPanelID;
if (typeStr == "RailingSegment") return API_RailingSegmentID;
if (typeStr == "RailingNode") return API_RailingNodeID;
if (typeStr == "RailingBalusterSet") return API_RailingBalusterSetID;
if (typeStr == "RailingPattern") return API_RailingPatternID;
if (typeStr == "RailingToprailEnd") return API_RailingToprailEndID;
if (typeStr == "RailingHandrailEnd") return API_RailingHandrailEndID;
if (typeStr == "RailingRailEnd") return API_RailingRailEndID;
if (typeStr == "RailingToprailConnection") return API_RailingToprailConnectionID;
if (typeStr == "RailingHandrailConnection") return API_RailingHandrailConnectionID;
if (typeStr == "RailingRailConnection") return API_RailingRailConnectionID;
if (typeStr == "RailingEndFinish") return API_RailingEndFinishID;
if (typeStr == "BeamSegment") return API_BeamSegmentID;
if (typeStr == "ColumnSegment") return API_ColumnSegmentID;
if (typeStr == "Opening") return API_OpeningID;
return API_ZombieElemID;
}
3 changes: 2 additions & 1 deletion archicad-addon/Sources/CommandBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ using Stories = GS::Array<Story>;

Stories GetStories ();
GS::Pair<short, double> GetFloorIndexAndOffset (const double zPos, const Stories& stories);
GS::UniString GetElementTypeNonLocalizedName (API_ElemTypeID typeID);
GS::UniString GetElementTypeNonLocalizedName (API_ElemTypeID typeID);
API_ElemTypeID GetElementTypeFromNonLocalizedName (const GS::UniString& typeStr);
Loading