Instantiating a Power Copy From a VB Macro

You can decide to instantiate your Power Copy using a VB macro.


Before you begin: KT1 is required to instantiate a Power Copy from a VB macro.

Note: If you are a DS Passport customer, you can read the articles QA00000005128.

Related Topics
Instantiating a User Feature From a VB Macro
  1. Create a 3D Shape Representation called PWC-TST-Macro-RepresentationTemplate containing geometry and identical to the one below:



  2. Click Power Copy . The Power Copy Definition dialog box is displayed.


    • Enter the name of the Power Copy: CircularHolePWC.
    • Select the components in the specification tree: Circle.1 and Split.1.
    • Click the Parameters tab and publish the Circle.1\Radius parameter. Rename it into Radius.
    • Click OK when done to validate your modifications. The Power Copy is created.

  3. Save the created 3D Shape Representation in the database.

  4. Select Tools > Macro > Macros.

  5. Click Macro libraries.... In the Macro libraries window, click Create new library. Enter the name of the Resources zip and click Finish. Click Close.

  6. In the Macros window, click Create.... The Create a new macro dialog box is displayed.

  7. Select the macro language (Script in this scenario), and enter the name of the macro. Click OK.

  8. Click Edit and enter the following script in the editor:

    ' This sample shows how to instantiate a Power Copy named "CircularHolePC"
    							' which is stored in a 3D Shape Representation Reference named 
    							' "PWC-TST-Macro-RepresentationTemplate" and with a V_version = "---".
    							' There are 2 inputs: "Surface" and "Center" and 1 published 
    							' parameter ' "Radius". 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
    							' Fill.1 surface and a input.2 point(this point must 
    							lay on the Fill).
    							' 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 Rep Template and the PLMExternalID of 
    							the Representation Reference where it stands"
    							factory.BeginInstanceFactory "CircularHolePWC", "PWC-TST-Macro-RepresentationTemplate", 
    							"---"
    							'----------------------------------------------------------------------------
    							CATIA.SystemService.Print "Begin the instantiation"
    							factory.BeginInstantiate
    							'----------------------------------------------------------------------------
    							CATIA.SystemService.Print "Valuate the first input named 
    							Surface"
    							Set input1 = PartDocumentDest.FindObjectByName("Fill.1")
    							factory.PutInputData "Surface", input1
    							'---------------------------------------------------------------------------
    							CATIA.SystemService.Print "Valuate the second input 
    							named Center"
    							Set input2 = PartDocumentDest.FindObjectByName("input.2")
    							factory.PutInputData "Center", input2
    							'---------------------------------------------------------------------------
    							CATIA.SystemService.Print "Modify the parameter named 
    							Radius"
    							Set param1 = factory.GetParameter("Radius")
    							param1.ValuateFromString("5mm")
    							'----------------------------------------------------------------------------
    							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

  9. Close the script editor, select your macro and click Run in the Macros dialog box. The Power Copy is instantiated.