#####################
Creating PRC Entities
#####################

This section explains how to create the PRC entities that represent the structure of the PRC file, such as the model file, product occurrences, and part definitions.
The names of structure module entities have the form `A3DAsm***Entity_name** *`.

* If the model file references multiple product occurrences, create an array to accommodate a pointer that references each product occurrence.
* For each product occurrence in the model file, create a pointer that references a populated product occurrence entity. (See :doc:`building_prc_2`).
  In the following example, `createOccurrence` is a private function that returns a pointer to a populated product occurrence.

.. code-block:: c

   A3DAsmProductOccurrence* p = createOccurrence();

Declare and initialize a model file data structure and set the values of its members, as follows:

* `m_uiPOccurrencesSize` represents the number of child product occurrences.
* `m_dUnit` is a multiple of millimeters that specifies the units used by the 3D data in the structure element.
* `m_ppPOccurrences` references the array of product occurrence pointers.

.. code-block:: c

   A3DAsmModelFileData sData = A3D_MAKE_DATA(A3DAsmModelFileData);
   sData.m_uiPOccurrencesSize = 1;
   sData.m_dUnit = 1.0;
   sData.m_ppPOccurrences = &p;


* Encapsulate the model file data by invoking the `A3DAsmModelFileCreate` function. The first argument is a pointer to the model file data, and the second argument is a pointer to the model file entity.

  .. code-block:: c

   A3DInt32 iRet = A3DAsmModelFileCreate(&sData, &pModelFile);



* Optionally, associate the model file entity with root-level attributes (:doc:`building_prc_6`).

* Declare a null pointer to a product occurrence.

  .. code-block:: c

   A3DAsmProductOccurrence* pProductOccurrrence = NULL;

* Create a pointer to a populated part definition. (See :doc:`building_prc_2`.) In the following example, `createPart` is a private function that returns a pointer to a populated part definition entity.

  .. code-block:: c

   A3DAsmPartDefinition* p = createPart();

* Set the `m_pPart` member to reference the part created in Step 2.

  .. code-block:: c

   A3DAsmProductOccurrenceData sData = A3D_MAKE_DATA(A3DAsmProductOccurrenceData);
   sData.m_pPart = p;

* Package the product occurrence data as a PRC entity by invoking the `A3DAsmProductOccurrenceCreate` function.
  The first argument is a pointer to the product occurrence data, and the second argument is an indirect pointer to the product occurrence.

.. code-block:: c

   A3DInt32 iRet = A3DAsmProductOccurrenceCreate(&sData, &pProductOccurrence);

* Define the cascaded attributes for the product occurrence. (See :doc:`building_prc_2`)

* Declare a null pointer to a part definition.

  .. code-block:: c

   A3DAsmPartDefinition* pPartDefinition = NULL;

* Declare and initialize a part definition data structure, as shown in the following example.

  .. code-block:: c

   A3DAsmPartDefinitionData sData = A3D_MAKE_DATA(A3DAsmPartDefinitionData);

* For each representation item referenced by this part definition, create a pointer to that representation item and populate it.
  (See :doc:`building_prc_3`) In the following example, `createRIBrep` is a private function that returns a pointer to a populated B-rep representation item.

  .. code-block:: c

   A3DRiRepresentationItem* p = createRIBrep();

* Set the `m_uiRepItemsSize` member of the part definition to the number of representation items.

* Set the m_ppRepItems member of the part definition to the array of pointers for the representation items. The following example describes a part definition that references a single representation item:

  .. code-block:: c

   sData.m_uiRepItemsSize = 1;
   sData.m_ppRepItems = &p;

* Package the part definition data as a PRC entity by invoking the `A3DAsmPartDefinitionCreate` function. The first argument is a pointer to the product occurrence data, and the second is the pointer to the part definition created in Step 1.

  .. code-block:: c

   A3DInt32 iRet = A3DAsmPartDefinitionCreate(&sData, &pPartDefinition);

