3D Visualization (3DV)

Creating a list of Product Occurrences

Creating a list of Product Occurrences entails processing the CAD Data Objects created when parsing the query results. Note that although the API requests a list of Product Occurrence objects containing only the root Product Occurrence Objects representing the CAD Items being viewed at the top level – and each Product Occurrence will store the BOM hierarchy as children. The following is a code snippet showing a possible implementation for creating Product Occurrences.

private void build(ProductOccurrenceInstance parent, CAD c)
 {
foreach(String xFormStr in c.Instances)
 {
 ProductOccurrenceInstance poInst = new ProductOccurrenceInstance();
 //poInst.Attributes.Add(new ProductOccurrenceAttr(“QUERY ITEM REF ID”, c.QryRefId));
 //poInst.Attributes.Add(new ProductOccurrenceAttr(“ITEM ID”, c.ID));
 poInst.SetServiceProperty(“QUERY ITEM REF ID”, c.QryRefId);
 poInst.SetServiceProperty(“ITEM ID”, c.ID);
 // bounding box
poInst.ProductOccurrenceSource.BoundingBox.Max.X = c.BBox.MaxX;
 // Testing Rendering Configuration
ProductOccurrenceRenderingConfiguration rConfig = new ProductOcc…();
 rConfig.SetColor(Color.FromArgb(55, 40, 0));
 rConfig.Opacity = 0.4;
 rConfig.Name = “test";
 poInst.RenderingConfigurations.Add(rConfig);
// Add Transformation Matrix
 poInst.TransformationMatrix = cadInstInfo.XForm;
// Add SetServiceProperty Method Calls
 poInst.SetServiceProperty(cadInstInfo.RefID, cadInstInfo.ID);
 poInst.SetServiceProperty(c.CADStrQryRefId, c.CADStructureID);
 poInst.SetServiceProperty(c.QryRefId, c.ID);
 // Add SetServiceProperty Method Calls
poInst.Name = c.Name;
if (c.Children.Count == 0 && c.SCFileID != null) // Assume this is a component
 {
 poInst.ProductOccurrenceSource.Name = c.SCFileID; // use File Item Id for name
 poInst.ProductOccurrenceSource.FileReferenceByTypeMap.Add(
 SourceModelType.Scs, c.SCFileID);
 }
 if (c.Children.Count == 0 && c.SCFileID == null)
 poInst = null; // Invalid Part
 else (parent != null)
 parent.Children.Add(poInst);
 // Recurse through child hierarchy
foreach (CAD child in c.Children)
 build(poInst, child);
 } // foreach(String xFormStr in c.Instances)
 } // build()

This logic is complex, so each key section in the code is enumerated with an explanation that follows:

  1. This example uses a recursive method to construct the hierarchy of Product Occurrence Objects. Note that the specific Product Occurrence classes used will either be ProductOccurrenceInstance or ProductOccurrenceSource. The former refers to actual instances (Assembly or Component) of some 3D geometry, the latter refers to the view geometry file itself.
  2. As mentioned previously in the explanation of the CAD Data Model Object class, the list of transformation strings associated with each CAD object denote the number of instances for that CAD Item. There should be at least one.
  3. For each Product Occurrence Instance, it’s critical that the following two Attributes be included:
    1. Query Item Reference ID. The reference ID is used for all Product Occurrence Instances and is extracted from the Query Results
    2. ID of the Item. This is used to map the instance of the geometry to the node of the CAD Item displayed in the Tree Grid View.
    3. Warning
      In 3DV 14.0.4, logic for associating Product Occurrence objects with Tree Grid Views (TGV) was modified. This change now uses the SetServiceProperty() method for setting the Query Item Reference ID and Item ID values. Previous versions used Product Occurrence Attributes for this purpose. In order to maintain synchronization between the 3D View and TGV for selection, use of SetServiceProperty() is necessary as shown in the example above.
      Note
      For each Product Occurrence Instance at the root level, it is necessary to set the “Root Flag” property set by calling ProductOccurenceBase.SetAsRoot() method. In the case of Digital Mockup (section Digital Mockup), there may be several root Product Occurrence Instances. See the full example in Section Sample Custom Default Query Processor.

  4. Set the bounding box values for each of the min and max values for X, Y, and Z
  5. Add a Rendering Configuration. This is optional, but necessary to add one or more View Modes to the Dynamic or Streaming Viewer (section 7.2.7). Rendering Configurations add alternate rendering parameters for the geometry associated with the Product Occurrence. This includes color and opacity (transparency). Together they can be used to visually isolate/highlight certain 3D geometry to show some information about the model or about related Items. There can be multiple rendering configurations for each Product Occurrence, although each must have a unique Name.
  6. If a Transformation string is included in the CAD Instance Item, then it should be applied to the TransformationMatrix Property of the Product Occurrence. If there is only one instance, and the geometry can be rendered as it was positioned/stored in the CAD software, then a transformation matrix is not required. In this case, an Identity matrix will be assumed. Note that if there are multiple instances of a CAD Item, then there should be a transformation matrix for each of them. Without a transformation matrix for each, the geometry will be rendered at a location based on how the geometry was stored in the CAD system.
  7. Set the Instance properties for instance id, CAD id, and CAD Structure id to support combined rows and the synchronization of instances. This is required to synchronize combined rows in the TGV to extract the path of the combined row and map it to the view.
  8. Note
    For each Product Occurrence Instance, it is necessary to set the service propertiesSetServiceProperty() method. See the full example in Section Sample Custom Default Query Processor.

  9. The name used for the Product Occurrence. It’s helpful to either use the document number or name of the CAD Item.
  10. For the CAD Data Model Object used, if there are no children, then it is assumed that the CAD Item is a component; in which case it should have an associated view file. In this case, create a ProductOccurrenceSource object, setting the properties as shown. Note that the ‘Name’ needs to store the File ID of the view file.
  11. If there are no children (CAD is assumed to be a Component) and there is no associated view file, then there is no sense (and it is invalid) in creating a Product Occurrence since there is no 3D geometry to load.
  12. Note
    Errors returned from the processing of Product Occurrence lists regarding the value ‘null’ for ‘key’ Parameters are typically related to the inclusion of Product Occurrence Instances for assemblies where no child in that assembly contains associated view data. To avoid these errors, ensure that at least one descendant Product Occurrence has a valid view file attached to it.

  13. If a valid parent was passed into the method, then add the newly created Occurrence to it.
  14. Recurse through the CAD hierarchy.