## 3.11. How to Determine the Part Number from the Part Name

Sometimes it may be desirable to know the Part number for a particular Part. Part numbers are assigned in their order of definition, starting with one. Structured and Unstructured Parts are contained and stored in different constructs;

Structured Parts:

  If you want the Part number associated with a specific Part name, the following coding will obtain that number (NSB) :

      USE SUBDEF

      INTEGER (INT4) :: NS, NSB
      NSB = 0
      DO NS = 1, NUMSUB
           IF (NAMSUB(NS) /= ‘Part name’) CYCLE
           NSB = NS
           EXIT
      END DO
                     !           ERROR, PART NOT FOUND
      IF (NSB= = 0) CALL USR_ERROR (‘ERROR !’, ‘PART NOT FOUND’)

  If you are writing a user subroutine called within the computational cycle (types 3 and 5), the current Part number (NSUB) will already be set (module subdef). You can then simply test the Part names, for example NAMSUB(NSUB), to determine if the Part is the one you wish to perform some action on.

Unstructured Parts:

      USE mdpart
      INTEGER(INT4) :: NPART, NPART_WANTED

      NPART_WANTED = 0
      DO NPART = 1, NUM_PARTS
         IF (PARTS(NPART)%P%NAME/=‘Part name’) CYCLE
         NPART_WANTED  = NPART
      END DO

      !           ERROR, PART NOT FOUND
      IF (NPART_WANTED= = 0) CALL USR_ERROR (‘ERROR !’, ‘PART NOT FOUND’)

Release 18.2 - © ANSYS, Inc. All rights reserved.