Instantiating a Power Copy From a VB Macro

You can decide to instantiate your power copy using a VB macro.

Note: When instantiating a power copy through a VB macro, sub-elements are not rerouted contrary to what happens when using other instantiation modes.


Before you begin:
  • The 3D Templates Capture license is required to instantiate a power copy from a VB macro.
  • 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.
  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 Power Copy named "PCBoundingSphere"
    ' 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 Power Copy. 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 "PCBoundingSphere", "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 power copy is instantiated.

Note: The table below shows the objects destination after instantiation by macro. * means that no error message appears, however nothing is instantiated.
IWO (In Work Object)Solid UDF Surfacic UDFPC Surfacic Feature (From GS)PC Surfacic Feature (from OGS)PC Solid Feature (from Body)PC Surfacic Set (GS)
Surfacic Set (GS)Inside Solid SetInside Surfacic SetInside Surfacic Set **Inside Set
Solid Set (Body)Inside Solid SetInside Solid Set-Inside Solid SetInside Solid SetEnd of tree
Solid FeatureAfter IWO featureAfter IWO feature-After IWO featureInside Solid Set, after the last featureEnd of tree
Surfacic Feature in Solid SetAfter IWO featureAfter IWO feature-After IWO featureInside Solid Set, after the last featureEnd of tree
Surfacic Feature in Surfacic Set (OGS)Inside Solid SetInside Surfacic Set-After IWO feature*End of tree