1515 SherlockExportPartsListError ,
1616 SherlockGetPartLocationError ,
1717 SherlockImportPartsListError ,
18+ SherlockUpdatePartsFromAVLError ,
1819 SherlockUpdatePartsListError ,
1920 SherlockUpdatePartsLocationsByFileError ,
2021 SherlockUpdatePartsLocationsError ,
2122)
2223from ansys .sherlock .core .grpc_stub import GrpcStub
23- from ansys .sherlock .core .types .parts_types import PartLocation
24+ from ansys .sherlock .core .types .parts_types import (
25+ AVLDescription ,
26+ AVLPartNum ,
27+ PartLocation ,
28+ PartsListSearchDuplicationMode ,
29+ PartsListSearchMatchingMode ,
30+ )
2431
2532
2633class Parts (GrpcStub ):
@@ -34,6 +41,12 @@ def __init__(self, channel):
3441 self .BOARD_SIDES = None
3542 self .MATCHING_ARGS = ["Both" , "Part" ]
3643 self .DUPLICATION_ARGS = ["First" , "Error" , "Ignore" ]
44+ self .AVL_PART_NUM_ARGS = [
45+ "AssignInternalPartNum" ,
46+ "AssignVendorAndPartNum" ,
47+ "DoNotChangeVendorOrPartNum" ,
48+ ]
49+ self .AVL_DESCRIPTION_ARGS = ["AssignApprovedDescription" , "DoNotChangeDescription" ]
3750
3851 @staticmethod
3952 def _add_matching_duplication (request , matching , duplication ):
@@ -155,8 +168,8 @@ def update_parts_list(
155168 project ,
156169 cca_name ,
157170 part_library ,
158- matching ,
159- duplication ,
171+ matching_mode ,
172+ duplication_mode ,
160173 ):
161174 """Update a parts list based on matching and duplication preferences.
162175
@@ -168,9 +181,9 @@ def update_parts_list(
168181 Name of the CCA.
169182 part_library : str
170183 Name of the parts library.
171- matching : UpdatesPartsListRequestMatchingMode
184+ matching_mode : PartsListSearchMatchingMode
172185 Matching mode for updates.
173- duplication : UpdatesPartsListRequestDuplicationMode
186+ duplication_mode : PartsListSearchDuplicationMode
174187 How to handle duplication during the update.
175188
176189 Returns
@@ -219,7 +232,7 @@ def update_parts_list(
219232 project = project , ccaName = cca_name , partLibrary = part_library
220233 )
221234
222- self ._add_matching_duplication (request , matching , duplication )
235+ self ._add_matching_duplication (request , matching_mode , duplication_mode )
223236
224237 response = self .stub .updatePartsList (request )
225238
@@ -690,3 +703,104 @@ def get_part_location(self, project, cca_name, ref_des, location_units):
690703 except SherlockGetPartLocationError as e :
691704 LOG .error (str (e ))
692705 raise e
706+
707+ def update_parts_from_AVL (
708+ self ,
709+ project : str ,
710+ cca_name : str ,
711+ matching_mode : PartsListSearchMatchingMode ,
712+ duplication_mode : PartsListSearchDuplicationMode ,
713+ avl_part_num : AVLPartNum ,
714+ avl_description : AVLDescription ,
715+ ) -> SherlockPartsService_pb2 .UpdatePartsListFromAVLResponse :
716+ r"""Update the parts list from the Approved Vendor List (AVL).
717+
718+ Parameters
719+ ----------
720+ project : str
721+ Name of the Sherlock project.
722+ cca_name : str
723+ Name of the CCA.
724+ matching_mode: PartsListSearchMatchingMode
725+ Determines how parts are matched against the AVL
726+ duplication_mode: PartsListSearchDuplicationMode
727+ Determines how duplicate part matches are handled when found
728+ avl_part_num: AVLPartNum
729+ Determines what part number info in the parts list is updated from the AVL
730+ avl_description: AVLDescription
731+ Determines if the part description is updated or not
732+
733+ Returns
734+ -------
735+ UpdatePartsListFromAVLResponse
736+ - returnCode : ReturnCode
737+ - value : int
738+ Status code of the response. 0 for success.
739+ - message : str
740+ indicates general errors that occurred while attempting to update parts
741+ - numPartsUpdated : int
742+ Number of parts updated
743+ - updateErrors : list<str>
744+ Errors found when updating part
745+
746+ Examples
747+ --------
748+ >>> from ansys.sherlock.core.launcher import launch_sherlock
749+ >>> from ansys.sherlock.core.types.parts_types import (
750+ AVLDescription,
751+ AVLPartNum,
752+ UpdatesPartsListRequestDuplicationMode,
753+ UpdatesPartsListRequestMatchingMode
754+ )
755+ >>> sherlock = launch_sherlock()
756+ >>> sherlock.project.import_odb_archive(
757+ "C:\\Program Files\\ANSYS Inc\\v241\\sherlock\\tutorial\\ODB++ Tutorial.tgz",
758+ True,
759+ True,
760+ True,
761+ True,
762+ project="Test",
763+ cca_name="Card",
764+ )
765+ >>> sherlock.parts.update_parts_from_AVL(
766+ project="Test",
767+ cca_name="Card",
768+ matching_mode=UpdatesPartsListRequestMatchingMode.BOTH,
769+ duplication=UpdatesPartsListRequestDuplicationMode.FIRST,
770+ avl_part_num=AVLPartNum.ASSIGN_INTERNAL_PART_NUM,
771+ avl_description=AVLDescription.ASSIGN_APPROVED_DESCRIPTION
772+ )
773+ """
774+ try :
775+ if project == "" :
776+ raise SherlockUpdatePartsFromAVLError (message = "Project name is invalid." )
777+ if cca_name == "" :
778+ raise SherlockUpdatePartsFromAVLError (message = "CCA name is invalid." )
779+
780+ request = SherlockPartsService_pb2 .UpdatePartsListFromAVLRequest (
781+ project = project ,
782+ ccaName = cca_name ,
783+ matching = matching_mode ,
784+ duplication = duplication_mode ,
785+ avlPartNum = avl_part_num ,
786+ avlDesc = avl_description ,
787+ )
788+
789+ if not self ._is_connection_up ():
790+ LOG .error ("Not connected to a gRPC service." )
791+ return
792+
793+ # Call method on server
794+ response = self .stub .updatePartsListFromAVL (request )
795+
796+ return_code = response .returnCode
797+
798+ if return_code .value == - 1 :
799+ if return_code .message == "" :
800+ raise SherlockUpdatePartsFromAVLError (error_array = response .updateErrors )
801+ raise SherlockUpdatePartsFromAVLError (message = return_code .message )
802+
803+ return response
804+ except SherlockUpdatePartsFromAVLError as e :
805+ LOG .error (str (e ))
806+ raise e
0 commit comments