Instantiating a PowerCopy From a Macro

This topic provides you with information about the instantiation of Power Copies using macros.
Until now it was possible to instantiate Power Copies only interactively. It is now possible to instantiate Power Copies from VB macros. (Note that this method is also a new way to instantiate a User Feature by macro. For more information, see Instantiating a User Feature Using a VB Macro.)

To instantiate a Power Copy from a VB macro:

  1. Develop your macro in an editor and save it with the CATScript extension. (Read carefully the instructions below to know how to structure your script.)

  2. From the Tools>Macro>Macros... command, access the Macros dialog box in CATIA. Click Macro libraries....

  3. In the Macro libraries dialog box, select the Directories option from the Library type scrolling list.

  4. In the Open a directory of macros dialog box, select the directory that contains the VB script you have created. Click OK when done. Click Close in the Macro libraries dialog box:  The macro contained in this directory is displayed in the Macros dialog box.

  5. Click Run. Your macro is run and your Power Copy is instantiated.

Note that:

  • The instantiation has to be done entirely from the beginning to the end, following the steps indicated below. The final step of the instantiation cannot be performed unless all the required inputs are correctly valuated. Trying to do so will lead to an error message and the script execution will stop. Moreover, as the duplication of the Power Copy components has already been performed, the duplicated components will have to be erased manually.
  • As the instantiation is performed programmatically, there is no possibility to intervene using the interface during the instantiation. Thus, manual reroute and orientation-handling are impossible.
    It is also impossible to modify a Design Table associated with the Power Copy.
    The Repeat mode is unavailable. Nevertheless this can be simulated by inserting a loop inside the script.
  • Inputs and published parameters are referenced by name in the methods and not by position.
  • The instantiation is always performed after the position of the current feature (the In-work object).
From the Instance Factory (A), the instantiation process can be broken down into 3 major steps, the second step itself being broken down into 5 different steps.
  • Initialization: It is the step where you define which Power Copy is to be instantiated. To perform several instantiations in a loop, the reference document is locked in the CATIA session. It will be unlocked in the final step.
  • Instantiation: It is the major step in which data are duplicated. This step can be repeated several times in a loop for example without doing the steps 1 and 3 again.
    • Inputs valuation: Each input of the Power Copy has to be valuated with a feature of the destination document.
    • Instantiation: All the components of the Power Copy are duplicated.
    • End of instantiation: After this call, the instantiation is ended, and all the links to the reference are broken.
  • Conclusion: This is the last step: The reference document is unlocked and released from the session.
     
' Instantiation of a Power Copy Reference called "TwoSurfacicHole"
' TwoSurfacicHole is stored in the CATPart PowerCopyReference.CATPart"
' It has 3 inputs: FirstHole, Support,and SecondHole
' and 2 published parameters: Radius1 and Radius2
'--------------------------------------------------------------

'---------------------------------------------------------------
CATIA.SystemService.Print "Retrieve the current part"

Dim PartDocumentDest As PartDocument
Set PartDocumentDest = CATIA.ActiveDocument

Dim PartDest As Part
Set PartDest = PartDocumentDest.Part
'---------------------------------------------------------------
CATIA.SystemService.Print "Retrieve the factory of the current part"

Dim factory As InstanceFactory (A)
Set factory = PartDest.GetCustomerFactory("InstanceFactory")
'---------------------------------------------------------------
CATIA.SystemService.Print "BeginInstanceFactory" (1)

factory.BeginInstanceFactory "TwoSurfacicHole", "e:\tmp\PowerCopyReference.CATPart"
'---------------------------------------------------------------
CATIA.SystemService.Print "Begin Instantiation"

factory.BeginInstantiate
(2)
'---------------------------------------------------------------
CATIA.SystemService.Print "Set Inputs"

Dim FirstHole As Object
Set FirstHole = PartDest.FindObjectByName("Point.1")

Dim Support As Object
Set Support = PartDest.FindObjectByName("Extrude.1")

Dim SecondHole As Object
Set SecondHole = PartDest.FindObjectByName("Point.2")

factory.PutInputData "FirstHole", FirstHole
(3)
factory.PutInputData "Support", Support
factory.PutInputData "SecondHole", SecondHole
'---------------------------------------------------------------
CATIA.SystemService.Print "Modify Parameters"

Dim param1 As Parameter
Set param1 = factory.GetParameter("Radius1")
(4)
param1.ValuateFromString("25mm")

Dim param2 As Parameter
Set param2 = factory.GetParameter("Radius2")
param2.ValuateFromString("15mm")
'---------------------------------------------------------------
CATIA.SystemService.Print "Instantiate"
(5)

Dim Instance As ShapeInstance
Set Instance = factory.Instantiate
'---------------------------------------------------------------
CATIA.SystemService.Print "End of Instantiation"
factory.EndInstantiate
(6)
'---------------------------------------------------------------
CATIA.SystemService.Print "Release the reference document"

factory.EndInstanceFactory
(7)
'---------------------------------------------------------------
CATIA.SystemService.Print "Update"
PartDest.Update
  • Initialization (1): Use the BeginInstanceFactory method of the CATIAInstanceFactory interface. The first argument must be the name of the Power Copy. The second argument is the name of the document where this reference is stored.
    For example: InstanceFactory.BeginInstanceFactory ("name_of_reference","name_of_document")
  • Instantiation: It is the most important part. It is broken down into 5 other steps that must be executed in the following order:
    • Begin of instantiation: Use the BeginInstantiate method (2) of the CATIAInstanceFactory interface.
      For example: InstanceFactory.BeginInstantiate
    • Valuation of inputs: Use the PutInputData method (3) of the CATIAInstanceFactory interface.
      For example: InstanceFactory.PutInputData "input1", selected_feature1
    • Parameter modification: Retrieve the published parameter using the GetParameter method (4) of the CATIAInstanceFactory interface.
      Then, modify its value using the ValuateFromString method of the CATIAParameter interface.
      For example: Set param = InstanceFactory.GetParameter ("published_parameter1")
      param.ValuateFromString ("length1")
    •  Instantiation: Use the Instantiate method (5) of the CATIAInstanceFactory interface. Nothing is returned by this method when instantiating a Power Copy.
      For example: Set Instance = InstanceFactory.Instantiate
    • End of instantiation: Use the EndInstantiate method (6) of the CATIAInstanceFactory interface.
      For example: InstanceFactory.EndInstantiate
  • Conclusion: Use the EndInstanceFactory method (7) of the CATIAInstanceFactory interface.
    For example: InstanceFactory.EndInstanceFactory

To get an example, see Instantiating a Power Copy From a VB Macro.