Instantiate PowerCopy in CATIA V5R19 using VBA macros

£可爱£侵袭症+ 提交于 2019-12-02 15:56:09

问题


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)


回答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.



来源:https://stackoverflow.com/questions/40081560/instantiate-powercopy-in-catia-v5r19-using-vba-macros

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!