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

[pre-commit.ci] pre-commit autoupdate #79

Merged
merged 3 commits into from
Jun 5, 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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# .pre-commit-config.yaml
repos:
- repo: https://github.com/mattlqx/pre-commit-search-and-replace
rev: v1.0.5
rev: v1.1.2
hooks:
- id: search-and-replace
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -11,6 +11,6 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.3.0
rev: 24.4.2
hooks:
- id: black
16 changes: 12 additions & 4 deletions BoM_Commands_Mixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def Activated(self):
DebugMode=False,
)
if BoM is not None:
General_BOM_Functions.General_BOM.createBoMSpreadsheet(mainList=BoM, Headers=None, Summary=False)
General_BOM_Functions.General_BOM.createBoMSpreadsheet(
mainList=BoM, Headers=None, Summary=False
)

return

Expand Down Expand Up @@ -115,7 +117,9 @@ def Activated(self):
DebugMode=False,
)
if BoM is not None:
General_BOM_Functions.General_BOM.createBoMSpreadsheet(mainList=BoM, Headers=None, Summary=False)
General_BOM_Functions.General_BOM.createBoMSpreadsheet(
mainList=BoM, Headers=None, Summary=False
)

return

Expand Down Expand Up @@ -170,7 +174,9 @@ def Activated(self):
DebugMode=False,
)
if BoM is not None:
General_BOM_Functions.General_BOM.createBoMSpreadsheet(mainList=BoM, Headers=None, Summary=False)
General_BOM_Functions.General_BOM.createBoMSpreadsheet(
mainList=BoM, Headers=None, Summary=False
)

return

Expand Down Expand Up @@ -224,7 +230,9 @@ def Activated(self):
DebugMode=False,
)
if BoM is not None:
General_BOM_Functions.General_BOM.createBoMSpreadsheet(mainList=BoM, Headers=None, Summary=False)
General_BOM_Functions.General_BOM.createBoMSpreadsheet(
mainList=BoM, Headers=None, Summary=False
)

return

Expand Down
8 changes: 6 additions & 2 deletions BoM_CreateUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ def CreateWorkBenchToolbar(WorkBench: str, ButtonList: list) -> object:
# Define the name for the toolbar
ToolBarName = "BoM_Toolbar"
# define the parameter path for the toolbar
WorkbenchToolBarsParamPath = "User parameter:BaseApp/Workbench/" + WorkBench + "/Toolbar/"
WorkbenchToolBarsParamPath = (
"User parameter:BaseApp/Workbench/" + WorkBench + "/Toolbar/"
)

# endregion

Expand Down Expand Up @@ -162,7 +164,9 @@ def RemoveWorkBenchToolbars(WorkBench: str) -> None:
custom_toolbars.RemGroup(ToolbarGroupName)


def ReplaceButtons(ToolbarGroupName: str, WorkbenchToolBarsParamPath: str, ButtonList: list) -> None:
def ReplaceButtons(
ToolbarGroupName: str, WorkbenchToolBarsParamPath: str, ButtonList: list
) -> None:
# Get the toolbar
TechDrawToolbar = App.ParamGet(WorkbenchToolBarsParamPath + ToolbarGroupName)

Expand Down
52 changes: 41 additions & 11 deletions GetBOM_A3.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def CheckIfAssembly(self, docObject):

# function to go through the objects and their child objects
@classmethod
def GoThrough_Objects(self, docObjects, sheet, ItemNumber, ParentNumber: str = "") -> True:
def GoThrough_Objects(
self, docObjects, sheet, ItemNumber, ParentNumber: str = ""
) -> True:
"""
Args:
docObjects (_type_): list[DocumentObjects]\n
Expand Down Expand Up @@ -186,9 +188,16 @@ def GoThrough_Objects(self, docObjects, sheet, ItemNumber, ParentNumber: str = "
childObjects.clear()
# Go through the subObjects of the document object, If the item(i) is not None, add it to the list.
for k in range(len(docObject.getSubObjects())):
if docObject.getSubObject(subname=docObject.getSubObjects()[k], retType=1) is not None:
if (
docObject.getSubObject(
subname=docObject.getSubObjects()[k], retType=1
)
is not None
):
childObjects.append(
docObject.getSubObject(subname=docObject.getSubObjects()[k], retType=1),
docObject.getSubObject(
subname=docObject.getSubObjects()[k], retType=1
),
)
if len(childObjects) > 0:
self.mainList[len(self.mainList) - 1]["Type"] = "Assembly"
Expand Down Expand Up @@ -261,7 +270,12 @@ def GoThrough_ChildObjects(
subChildObjects.clear()
# Go through the subObjects of the child document object, if item(i) is not None, add it to the list
for k in range(len(childObject.getSubObjects())):
if childObject.getSubObject(subname=childObject.getSubObjects()[k], retType=1) is not None:
if (
childObject.getSubObject(
subname=childObject.getSubObjects()[k], retType=1
)
is not None
):
subChildObjects.append(
childObject.getSubObject(childObject.getSubObjects()[k], 1),
)
Expand Down Expand Up @@ -299,7 +313,10 @@ def FilterBodies(self, BOMList: list, AllowAllBodies: bool = True) -> list:
flag = True

# If the next object is an body or feature, set the flag to False.
if ItemObjectTypeNext == "Part::Feature" or ItemObjectTypeNext == "PartDesign::Body":
if (
ItemObjectTypeNext == "Part::Feature"
or ItemObjectTypeNext == "PartDesign::Body"
):
# Filter out all type of bodies
if AllowAllBodies is False:
ItemObject["Type"] = "Part"
Expand Down Expand Up @@ -366,7 +383,10 @@ def ObjectCounter_ItemNumber(
# The parent number is the itemnumber without the last digit. if both ItemNumber and item in numberlist are the same, continue.
# If the itemnumber is more than one level deep:
if len(ItemNumber.split(".")) > 1:
if BomList[i]["ItemNumber"].rsplit(".", 1)[0] == ItemNumber.rsplit(".", 1)[0]:
if (
BomList[i]["ItemNumber"].rsplit(".", 1)[0]
== ItemNumber.rsplit(".", 1)[0]
):
# If the document object in the list is equal to DocObject, increase the counter by one.
if ObjectNameValue == "Object":
if BomList[i]["DocumentObject"] == ListItem["DocumentObject"]:
Expand Down Expand Up @@ -547,11 +567,15 @@ def CreateTotalBoM(
# If App:Links only contain the same bodies and IncludeBodies = False,
# replace the App::Links with the bodies they contain. Including their quantity.
if Level > 1:
TemporaryList = self.FilterBodies(BOMList=TemporaryList, AllowAllBodies=IncludeBodies)
TemporaryList = self.FilterBodies(
BOMList=TemporaryList, AllowAllBodies=IncludeBodies
)

# Correct the itemnumbers if indentation is wanted.
if IndentNumbering is True:
TemporaryList = General_BOM.CorrectItemNumbers(BoMList=TemporaryList, DebugMode=False)
TemporaryList = General_BOM.CorrectItemNumbers(
BoMList=TemporaryList, DebugMode=False
)

# If no indented numbering is needed, number the parts 1,2,3, etc.
if IndentNumbering is False:
Expand Down Expand Up @@ -659,7 +683,9 @@ def SummarizedBoM(

# If App:Links only contain the same bodies and IncludeBodies = False,
# replace the App::Links with the bodies they contain. Including their quantity.
TemporaryList = self.FilterBodies(BOMList=TemporaryList, AllowAllBodies=IncludeBodies)
TemporaryList = self.FilterBodies(
BOMList=TemporaryList, AllowAllBodies=IncludeBodies
)

# number the parts 1,2,3, etc.
for k in range(len(TemporaryList)):
Expand All @@ -668,7 +694,9 @@ def SummarizedBoM(

# Create the spreadsheet
if CreateSpreadSheet is True:
General_BOM.createBoMSpreadsheet(mainList=TemporaryList, Headers=None, Summary=True)
General_BOM.createBoMSpreadsheet(
mainList=TemporaryList, Headers=None, Summary=True
)
return

# Function to create a BoM list for a parts only BoM.
Expand Down Expand Up @@ -763,7 +791,9 @@ def PartsOnly(

# If App:Links only contain the same bodies and IncludeBodies = False,
# replace the App::Links with the bodies they contain. Including their quantity.
TemporaryList = self.FilterBodies(BOMList=TemporaryList, AllowAllBodies=IncludeBodies)
TemporaryList = self.FilterBodies(
BOMList=TemporaryList, AllowAllBodies=IncludeBodies
)

# number the parts 1,2,3, etc.
for k in range(len(TemporaryList)):
Expand Down
73 changes: 59 additions & 14 deletions GetBOM_A4.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,20 @@ def GetTreeObjects(self, checkAssemblyType=True) -> True:

# Check if there are groups with items. create a list from it and add it to the docObjects.
for RootObject in RootObjects:
if RootObject.TypeId == "App::DocumentObjectGroup" and RootObject.Name != "Parts":
if (
RootObject.TypeId == "App::DocumentObjectGroup"
and RootObject.Name != "Parts"
):
RootObjects.extend(General_BOM.GetObjectsFromGroups(RootObject))

# Get the folder with the parts and create a list from it.
PartsGroup = []
PartList = []
for RootObject in RootObjects:
if RootObject.Name == "Parts" and RootObject.TypeId == "App::DocumentObjectGroup":
if (
RootObject.Name == "Parts"
and RootObject.TypeId == "App::DocumentObjectGroup"
):
PartsGroup.append(RootObject)
for Part in PartsGroup:
PartList.append(Part)
Expand Down Expand Up @@ -95,7 +101,10 @@ def GetTreeObjects(self, checkAssemblyType=True) -> True:
def FindAssemblyInGroups(self, Group, docObjects: list):
for GroupObject in Group.Group:
try:
if GroupObject.AssemblyType == "Part::Link" and GroupObject.Type == "Assembly":
if (
GroupObject.AssemblyType == "Part::Link"
and GroupObject.Type == "Assembly"
):
docObjects.append(GroupObject)
break
except Exception:
Expand Down Expand Up @@ -154,7 +163,9 @@ def FilterLinkedParts(self, ObjectDocument, objectComparison) -> App.DocumentObj

# function to go through the objects and their child objects
@classmethod
def GoThrough_Objects(self, docObjects, sheet, Parts: list, ItemNumber, ParentNumber: str = "") -> True:
def GoThrough_Objects(
self, docObjects, sheet, Parts: list, ItemNumber, ParentNumber: str = ""
) -> True:
"""
Args:
docObjects (_type_): list[DocumentObjects]\n
Expand Down Expand Up @@ -199,14 +210,23 @@ def GoThrough_Objects(self, docObjects, sheet, Parts: list, ItemNumber, ParentNu
self.mainList.append(rowList)

# If the object is an container, go through the sub items, (a.k.a child objects)
if object.TypeId == "App::LinkGroup" or object.TypeId == "App::Link" or object.TypeId == "App::Part":
if (
object.TypeId == "App::LinkGroup"
or object.TypeId == "App::Link"
or object.TypeId == "App::Part"
):
# Create a list with child objects as DocumentObjects
childObjects = []
# Make sure that the list is empty. (probally overkill)
childObjects.clear()
# Go through the subObjects of the document object, If the item(i) is not None, add it to the list.
for j in range(len(object.getSubObjects())):
if object.getSubObject(subname=object.getSubObjects()[j], retType=1) is not None:
if (
object.getSubObject(
subname=object.getSubObjects()[j], retType=1
)
is not None
):
# Go through the parts folder and compare the parts with the subobjects.
for k in range(len(Parts)):
# If filtering with the parts in the part folder results in an document object,
Expand All @@ -221,7 +241,9 @@ def GoThrough_Objects(self, docObjects, sheet, Parts: list, ItemNumber, ParentNu
is not None
):
if self.AllowedObjectType(
object.getSubObject(subname=object.getSubObjects()[j], retType=1).TypeId
object.getSubObject(
subname=object.getSubObjects()[j], retType=1
).TypeId
):
childObjects.append(
object.getSubObject(
Expand Down Expand Up @@ -299,7 +321,12 @@ def GoThrough_ChildObjects(
subChildObjects.clear()
# Go through the subObjects of the child document object, if item(i) is not None, add it to the list
for j in range(len(childObject.getSubObjects())):
if childObject.getSubObject(subname=childObject.getSubObjects()[j], retType=1) is not None:
if (
childObject.getSubObject(
subname=childObject.getSubObjects()[j], retType=1
)
is not None
):
# Go through the parts folder and compare the parts with the subobjects.
for k in range(len(Parts)):
# If filtering with the parts in the part folder results in an document object,
Expand Down Expand Up @@ -382,7 +409,12 @@ def FilterBodies(self, BOMList: list, AllowAllBodies: bool = True) -> list:
# Test the object. If the parent is an assembly, the object is allowed.
testResult = False
try:
if ItemObject["DocumentObject"].getParent().getPropertyByName("Type", 2)[1] == "Assembly":
if (
ItemObject["DocumentObject"]
.getParent()
.getPropertyByName("Type", 2)[1]
== "Assembly"
):
testResult = True
if len(ItemObject["ItemNumber"].split(".")) == 1:
testResult = True
Expand Down Expand Up @@ -414,7 +446,12 @@ def FilterBodies(self, BOMList: list, AllowAllBodies: bool = True) -> list:
# Test the next object. If the parent is an assembly, the object is allowed.
testResult = False
try:
if ItemObjectNext["DocumentObject"].getParent().getPropertyByName("Type", 2)[1] == "Assembly":
if (
ItemObjectNext["DocumentObject"]
.getParent()
.getPropertyByName("Type", 2)[1]
== "Assembly"
):
testResult = True
if len(ItemObjectNext["ItemNumber"].split(".")) == 1:
testResult = True
Expand Down Expand Up @@ -651,7 +688,9 @@ def CreateTotalBoM(
# If App:Links only contain the same bodies and IncludeBodies = False,
# replace the App::Links with the bodies they contain. Including their quantity.
if Level > 1:
TemporaryList = self.FilterBodies(BOMList=TemporaryList, AllowAllBodies=IncludeBodies)
TemporaryList = self.FilterBodies(
BOMList=TemporaryList, AllowAllBodies=IncludeBodies
)

# Correct the itemnumbers if indentation is wanted.
if IndentNumbering is True:
Expand Down Expand Up @@ -763,7 +802,9 @@ def SummarizedBoM(

# If App:Links only contain the same bodies and IncludeBodies = False,
# replace the App::Links with the bodies they contain. Including their quantity.
TemporaryList = self.FilterBodies(BOMList=TemporaryList, AllowAllBodies=IncludeBodies)
TemporaryList = self.FilterBodies(
BOMList=TemporaryList, AllowAllBodies=IncludeBodies
)

# number the parts 1,2,3, etc.
for k in range(len(TemporaryList)):
Expand All @@ -772,7 +813,9 @@ def SummarizedBoM(

# Create the spreadsheet
if CreateSpreadSheet is True:
General_BOM.createBoMSpreadsheet(mainList=TemporaryList, Headers=None, Summary=True)
General_BOM.createBoMSpreadsheet(
mainList=TemporaryList, Headers=None, Summary=True
)
return

# Function to create a BoM list for a parts only BoM.
Expand Down Expand Up @@ -867,7 +910,9 @@ def PartsOnly(

# If App:Links only contain the same bodies and IncludeBodies = False,
# replace the App::Links with the bodies they contain. Including their quantity.
TemporaryList = self.FilterBodies(BOMList=TemporaryList, AllowAllBodies=IncludeBodies)
TemporaryList = self.FilterBodies(
BOMList=TemporaryList, AllowAllBodies=IncludeBodies
)

# number the parts 1,2,3, etc.
for k in range(len(TemporaryList)):
Expand Down
Loading