Instantiating a User Feature from a VB Macro

You can instantiate user features from VB macros. Two different protocols are available to instantiate user features.


Before you begin:
  • To access the models used in this topic, import the Bounding_Box_Reference_000.3dxml and the Bounding_Box_Destination_000.3dxml files located in win_b64\startup\Knowledgeware\3D Templates Samples\Sample1.
See Also
Creating a User Feature
  1. Open the destination product.
  2. From the Tools section, select Macros.
  3. Click Macro libraries... and select the PLM Directories library type from the list.
  4. Click Create new library. Type the name of the library and click OK.
  5. Click Create in the Macros dialog box.
    The Create a new macro dialog box appears.
  6. Enter the macro name and click OK.
  7. Click Edit and enter the following script in the editor:

    ' This sample shows how to instantiate a User Feature named "UDFBoundingSphere"
    ' which is stored in a 3D Shape Representation Reference named 
    ' "Bounding_Box_Reference_000" and with a majorrevision = "---".
    ' There is 1 input: "Surface". To run this sample, open in session the
    ' 3D Shape Representation where you want to instantiate the User Feature. It must  contain at least a
    ' Surface.1 surface.
    ' Go to Tools \ Macro \ Macros ... and run this script.
    							
    Sub CATMain()
    '---------------------------------------------------------------------------
    CATIA.SystemService.Print "Retrieve the Representation Reference where the instantiation is performed"
    Set PartDocumentDest = CATIA.ActiveEditor.ActiveObject
    CATIA.SystemService.Print "PartDocumentDest.TypeName = " & TypeName(PartDocumentDest)
    If TypeName(PartDocumentDest)<> "Part" Then
    MsgBox "Error: TypeName activeObject is not a part"
    End If
    '---------------------------------------------------------------------------
    CATIA.SystemService.Print "Retrieve the Instance factory on this part container"
    Set factory = PartDocumentDest.GetCustomerFactory("InstanceFactory")
    '---------------------------------------------------------------------------
    CATIA.SystemService.Print "Initialize the process with the name of the Power Copy, the name of the 3D Shape Representation Reference, and the majorrevision"
    factory.BeginInstanceFactory "UDFBoundingSphere", "Bounding_Box_Reference_000", "---"
    '----------------------------------------------------------------------------
    CATIA.SystemService.Print "Begin the instantiation"
    factory.BeginInstantiate
    '----------------------------------------------------------------------------
    CATIA.SystemService.Print "Valuate the input named Surface"
    Set input1 = PartDocumentDest.FindObjectByName("Surface.2")
    factory.PutInputData "Surface", input1
    '---------------------------------------------------------------------------
    CATIA.SystemService.Print "Instantiate the Power Copy"
    Set Instance = factory.Instantiate
    '----------------------------------------------------------------------------
    CATIA.SystemService.Print "End the instantiation process"
    factory.EndInstantiate
    '-----------------------------------------------------------------------------
    CATIA.SystemService.Print "Release the 3D Shape Representation containing the Rep Template reference"
    factory.EndInstanceFactory
    '-----------------------------------------------------------------------------
    CATIA.SystemService.Print "Launch a global Update"
    PartDocumentDest.Update
    '----------------------------------------------------------------------------
    End Sub

  8. Close the script editor, select your macro and click Run in the Macros dialog box.
    The user feature is instantiated.