Skip to content

Commit

Permalink
Merge pull request #180 from tlorantfy/CreateProperties
Browse files Browse the repository at this point in the history
New commands: CreatePropertyDefinitions, DeletePropertyDefinitions, DeletePropertyGroups
  • Loading branch information
tlorantfy authored Oct 6, 2024
2 parents fead55c + 7176047 commit ee53237
Show file tree
Hide file tree
Showing 17 changed files with 101,459 additions and 1,479 deletions.
78 changes: 78 additions & 0 deletions archicad-addon/Examples/delete_and_create_properties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import aclib

# Get all details of all properties and groups

propertyIds = aclib.RunCommand ('API.GetAllPropertyIds', {'propertyType': 'UserDefined'})['propertyIds']
propertyDefinitions = aclib.RunCommand ('API.GetDetailsOfProperties', {'properties': propertyIds})['propertyDefinitions']
propertyDefinitionAvailabilityList = aclib.RunCommand ('API.GetPropertyDefinitionAvailability', {'propertyIds': propertyIds})['propertyDefinitionAvailabilityList']
propertyGroupIds = aclib.RunCommand ('API.GetAllPropertyGroupIds', {'propertyType': 'UserDefined'})['propertyGroupIds']
propertyGroups = aclib.RunCommand ('API.GetPropertyGroups', {'propertyGroupIds': propertyGroupIds})['propertyGroups']

# Delete all properties and groups

aclib.RunTapirCommand ('DeletePropertyDefinitions', {'propertyIds': propertyIds})
aclib.RunTapirCommand ('DeletePropertyGroups', {'propertyGroupIds': propertyGroupIds})

propertyIds = aclib.RunCommand ('API.GetAllPropertyIds', {'propertyType': 'UserDefined'})['propertyIds']
if propertyIds:
print ('FAILED to delete all custom properties')
exit (1)
propertyGroupIds = aclib.RunCommand ('API.GetAllPropertyGroupIds', {'propertyType': 'UserDefined'})['propertyGroupIds']
if propertyGroupIds:
print ('FAILED to delete all custom property groups')
exit (1)

# ReCreate all properties and groups

for i in range(len(propertyDefinitions)):
del propertyDefinitions[i]['propertyDefinition']['propertyId']
del propertyDefinitions[i]['propertyDefinition']['group']['propertyGroupId']
propertyDefinitions[i]['propertyDefinition']['availability'] = propertyDefinitionAvailabilityList[i]['propertyDefinitionAvailability']['availableClassifications']
for propertyGroup in propertyGroups:
del propertyGroup['propertyGroup']['propertyGroupId']

aclib.RunTapirCommand ('CreatePropertyGroups', {'propertyGroups': propertyGroups})
aclib.RunTapirCommand ('CreatePropertyDefinitions', {'propertyDefinitions': propertyDefinitions})

# Get all details of all properties and groups

propertyIds = aclib.RunCommand ('API.GetAllPropertyIds', {'propertyType': 'UserDefined'})['propertyIds']
propertyDefinitionsAfterRecreate = aclib.RunCommand ('API.GetDetailsOfProperties', {'properties': propertyIds})['propertyDefinitions']
propertyDefinitionAvailabilityListAfterRecreate = aclib.RunCommand ('API.GetPropertyDefinitionAvailability', {'propertyIds': propertyIds})['propertyDefinitionAvailabilityList']
propertyGroupIds = aclib.RunCommand ('API.GetAllPropertyGroupIds', {'propertyType': 'UserDefined'})['propertyGroupIds']
propertyGroupsAfterRecreate = aclib.RunCommand ('API.GetPropertyGroups', {'propertyGroupIds': propertyGroupIds})['propertyGroups']

# Compare current state to the state before deleted all

for i in range(len(propertyGroupsAfterRecreate)):
del propertyGroupsAfterRecreate[i]['propertyGroup']['propertyGroupId']

beforeDeleteStr = aclib.JsonDumpDictionary (propertyGroups[i])
afterRecreateStr = aclib.JsonDumpDictionary (propertyGroupsAfterRecreate[i])
if beforeDeleteStr != afterRecreateStr:
print ('FAILED')
print (beforeDeleteStr)
print (afterRecreateStr)
exit (1)

for i in range(len(propertyDefinitionsAfterRecreate)):
del propertyDefinitionsAfterRecreate[i]['propertyDefinition']['propertyId']
del propertyDefinitionsAfterRecreate[i]['propertyDefinition']['group']['propertyGroupId']
propertyDefinitionsAfterRecreate[i]['propertyDefinition']['availability'] = propertyDefinitionAvailabilityListAfterRecreate[i]['propertyDefinitionAvailability']['availableClassifications']

beforeDeleteStr = aclib.JsonDumpDictionary (propertyDefinitions[i])
afterRecreateStr = aclib.JsonDumpDictionary (propertyDefinitionsAfterRecreate[i])
if beforeDeleteStr != afterRecreateStr:
print ('FAILED')
print (beforeDeleteStr)
print (afterRecreateStr)
exit (1)

if len(propertyGroups) != len(propertyGroupsAfterRecreate):
print ('FAILED to create some property groups')
exit (1)
if len(propertyDefinitions) != len(propertyDefinitionsAfterRecreate):
print ('FAILED to create some properties')
exit (1)

print ('SUCCEEDED')
4 changes: 1 addition & 3 deletions archicad-addon/Examples/get_all_properties.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import json
import aclib

response = aclib.RunTapirCommand ('GetAllProperties', {})
print (response)
response = aclib.RunTapirCommand ('GetAllProperties', {})
12 changes: 12 additions & 0 deletions archicad-addon/Sources/AddOnMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ GSErrCode Initialize (void)
propertyCommands, "1.0.7",
"Creates Property Groups based on the given parameters."
);
err |= RegisterCommand<DeletePropertyGroupsCommand> (
propertyCommands, "1.0.9",
"Deletes the given Custom Property Groups."
);
err |= RegisterCommand<CreatePropertyDefinitionsCommand> (
propertyCommands, "1.0.9",
"Creates Custom Property Definitions based on the given parameters."
);
err |= RegisterCommand<DeletePropertyDefinitionsCommand> (
propertyCommands, "1.0.9",
"Deletes the given Custom Property Definitions."
);
AddCommandGroup (propertyCommands);
}

Expand Down
Loading

0 comments on commit ee53237

Please sign in to comment.