0

I cant figure out how to instantiate Power-copy using VBA macro. I have a CATPart1, that have Power-copy name "MyPC". And I want to instantiate this power-copy in current Part. Just for example, this Power-copy inputs are: "Plane", "Start_point" and "End_point". I found in "CAA V5 VB help" that there are InstanceFactory object, that have methods to instantiate power-copy and UDFs. But my code doesn't work.

Sub CATMain() 
Dim partDocument1 As partDocument
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As part
Set part1 = partDocument1.part

Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies

Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item("gt")

Dim mplane As Plane
Dim StartPnt As point
Dim EndPnt As point

Set mplane = hybridBody1.HybridShapes.Item(1)
Set StartPnt = hybridBody1.HybridShapes.Item(2)
Set EndPnt = hybridBody1.HybridShapes.Item(3)

Dim InstFactory As InstanceFactory
Set InstFactory = part1.HybridShapeFactory

Dim instance

InstFactory.BeginInstanceFactory "MyPC", "D:\myFolder\Part1.CATPart"
InstFactory.BeginInstantiate

InstFactory.PutInputData "Plane", mplane
InstFactory.PutInputData "Start_point", StartPnt
InstFactory.PutInputData "End_point", EndPnt

Set instance = InstFactory.Instantiate
hybridBody1.AppendHybridShape instance
InstFactory.EndInstantiate

End Sub   

An automation error occurs in line

InstFactory.BeginInstanceFactory "MyPC", "D:\myFolder\Part1.CATPart"

Does anybody help me to understand why it isn't work? Thank you in advance)

  • What OS do you have? Do you have more CATIA releases installed ? Is a network installation ? What is saying exactly the error ? Are you sure your Power Copy is done correctly? – ferdo Oct 17 '16 at 15:53
  • @ferdo Hello. OS is windows 64bit. Version of CATIA V5R19. Other releases do not installed. Installation was done by system administrator. PowerCopy is done correctly, because if i instantiate it manually it works fine. Error saying "Run-time error '-2147467259(80004005)': Automation error. Unspecified error" . Do you have any ideas how to find out why this error appears? – A. Morozko Oct 19 '16 at 14:15

1 Answers1

1

There are two things that may be the cause of the error you are having:

1 - Use

Dim InstFactory As InstanceFactory
Set InstFactory = part1.GetCustomerFactory("InstanceFactory")

instead of

Dim InstFactory As InstanceFactory
Set InstFactory = part1.HybridShapeFactory

2 - You need to activate the floating license KT1 in order to use the PowerCopy operation via API. To activate it, go to Catia menu -> Tools -> Options and then select the tab Shearable Products and active the license.

Quima
  • 894
  • 11
  • 21