Catia Macro for power Copy
Catia Macro for power Copy
(OP)
I everyone
I am trying to realize a Macro to insert a powercopy to a part, and trying to select the inputs during macro execution.
I have found this macro in internet:
' Instantiation of a PowerCopy Reference "SurfacicHoles"
' SurfacicHoles is stored in the CATPart "e:\tmp\PowerCopyReference.CATPart"
' It has
' 3 inputs: FirstHole, Support,and SecondHole
' 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
Set factory = PartDest.GetCustomerFactory("InstanceFactory")
'------------------------------------------------------------------
Catia.SystemService.Print "BeginInstanceFactory"
factory.BeginInstanceFactory "SurfacicHoles", "e:\tmp\PowerCopyReference.CATPart"
'------------------------------------------------------------------
Catia.SystemService.Print "Begin Instantiation"
factory.BeginInstantiate
'------------------------------------------------------------------
Catia.SystemService.Print "Set Inputs"
Dim FirstHole As Object
Set FirstHole = PartDest.FindObjectByName("Point.1")
Dim Support As Object
Set Support = PartDest.FindObjectByName("Surface.1")
Dim SecondHole As Object
Set SecondHole = PartDest.FindObjectByName("Point.2")
factory.PutInputData "FirstHole", FirstHole
factory.PutInputData "Support", Support
factory.PutInputData "SecondHole", SecondHole
'------------------------------------------------------------------
Catia.SystemService.Print "Modify Parameters"
Dim param1 As Parameter
Set param1 = factory.GetParameter("Radius1")
param1.ValuateFromString("25mm")
Dim param2 As Parameter
Set param2 = factory.GetParameter("Radius2")
param2.ValuateFromString("15mm")
'------------------------------------------------------------------
Catia.SystemService.Print "Instantiate"
Dim Instance As ShapeInstance
Set Instance = factory.Instantiate
'------------------------------------------------------------------
Catia.SystemService.Print "End of Instantiation"
factory.EndInstantiate
'------------------------------------------------------------------
Catia.SystemService.Print "Release the reference document"
factory.EndInstanceFactory
'------------------------------------------------------------------
Catia.SystemService.Print "Update"
PartDest.Update
in the section:
Dim Support As Object
Set Support = PartDest.FindObjectByName("Surface.1")
I have tried to replace "FindObjectByName", by "UserSel.SelectElement2(What, "Select a Plane", False)", but there is always an error.
Anyone knows how can I use this function?
I really want to creat a macro for institiate the power copy by pressing a button (using a macro), and after institiate a powercopy, i want to make a few other things, that i need to add in a macro, but for this i need to put my macro working with select inputs during execution
I am trying to realize a Macro to insert a powercopy to a part, and trying to select the inputs during macro execution.
I have found this macro in internet:
' Instantiation of a PowerCopy Reference "SurfacicHoles"
' SurfacicHoles is stored in the CATPart "e:\tmp\PowerCopyReference.CATPart"
' It has
' 3 inputs: FirstHole, Support,and SecondHole
' 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
Set factory = PartDest.GetCustomerFactory("InstanceFactory")
'------------------------------------------------------------------
Catia.SystemService.Print "BeginInstanceFactory"
factory.BeginInstanceFactory "SurfacicHoles", "e:\tmp\PowerCopyReference.CATPart"
'------------------------------------------------------------------
Catia.SystemService.Print "Begin Instantiation"
factory.BeginInstantiate
'------------------------------------------------------------------
Catia.SystemService.Print "Set Inputs"
Dim FirstHole As Object
Set FirstHole = PartDest.FindObjectByName("Point.1")
Dim Support As Object
Set Support = PartDest.FindObjectByName("Surface.1")
Dim SecondHole As Object
Set SecondHole = PartDest.FindObjectByName("Point.2")
factory.PutInputData "FirstHole", FirstHole
factory.PutInputData "Support", Support
factory.PutInputData "SecondHole", SecondHole
'------------------------------------------------------------------
Catia.SystemService.Print "Modify Parameters"
Dim param1 As Parameter
Set param1 = factory.GetParameter("Radius1")
param1.ValuateFromString("25mm")
Dim param2 As Parameter
Set param2 = factory.GetParameter("Radius2")
param2.ValuateFromString("15mm")
'------------------------------------------------------------------
Catia.SystemService.Print "Instantiate"
Dim Instance As ShapeInstance
Set Instance = factory.Instantiate
'------------------------------------------------------------------
Catia.SystemService.Print "End of Instantiation"
factory.EndInstantiate
'------------------------------------------------------------------
Catia.SystemService.Print "Release the reference document"
factory.EndInstanceFactory
'------------------------------------------------------------------
Catia.SystemService.Print "Update"
PartDest.Update
in the section:
Dim Support As Object
Set Support = PartDest.FindObjectByName("Surface.1")
I have tried to replace "FindObjectByName", by "UserSel.SelectElement2(What, "Select a Plane", False)", but there is always an error.
Anyone knows how can I use this function?
I really want to creat a macro for institiate the power copy by pressing a button (using a macro), and after institiate a powercopy, i want to make a few other things, that i need to add in a macro, but for this i need to put my macro working with select inputs during execution





RE: Catia Macro for power Copy
I have see this macro with the function "UserSel.SelectElement2(What, "Select a Plane", False)"
CATIA.StatusBar = "CATScript, Version 1.1"
Sub CATMain()
' Set a Selection
'-----------------------------------------------
Dim What(0)
What(0) = "Plane"
' Define Selection and clear
'---------------------------------
Dim UserSel As Selection
Set UserSel= CATIA.ActiveDocument.Selection
UserSel.Clear
' Make a Selection
'--------------------------------------
Dim E As CATBSTR
E = UserSel.SelectElement2(What, "Select a Plane", False)
If E = "Normal" Then
MsgBox(UserSel.Item(1).Value.Name)
Else
MsgBox ("Selection Aborted")
End If
' Clear Selection
'--------------------------------------------
UserSel.Clear
End Sub
But I really don't know how can i integrate this.
RE: Catia Macro for power Copy
Sub CATMain ()
' Auswahl festlegen ---------------------------------------- Dim Was(1)
Was(0) = "Line"
Was(1) = "AnyObject"
' Selection definition---------------------------------
Dim UserSel As Selection
Set UserSel= CATIA.ActiveDocument.Selection
UserSel.Clear
' Selektion vornehmen lassen --------------------------------- Dim E As CATBSTR
E = UserSel.SelectElement2(Was, "Line or AnyObject", False)
If E = "Normal" Then
MsgBox(UserSel.Item(1).Value.Name)
Else
MsgBox ("Abort")
End If
UserSel.Clear
End Sub
Win 7
23SP5/24SP3, 3DVIA Composer 2015
RE: Catia Macro for power Copy
Regarding the licensing, i believe that is not needed Kt1. I think i don't have that module, and first macro works.
Do you know how to integrate your macro, with the first one?
The first one is finding object by name, i had tried to replace that by UserSel.SelectElement2, and it didn't work. Latter on I will try to make some trials, and then i will give you a feedback.
Thanks
RE: Catia Macro for power Copy
I have tried to made some arrangements, here is the result, unfortunately still doesn't works...
'------------------------------------------------------------------
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
Set factory = PartDest.GetCustomerFactory("InstanceFactory")
'------------------------------------------------------------------
Catia.SystemService.Print "BeginInstanceFactory"
factory.BeginInstanceFactory "PowerCopy.1", "C:\Users\tiago\Desktop\Power copy MCG\Socket head screw\Part1.CATPart"
'------------------------------------------------------------------
Catia.SystemService.Print "Begin Instantiation"
Factory.BeginInstantiate
'------------------------------------------------------------------
Catia.SystemService.Print "Set Inputs"
Dim Plano As Object
CATIA.StatusBar = "CATScript, Version 1.1"
Sub CATMain()
' Set a Selection
'-----------------------------------------------
Dim What(0)
What(0) = "Plane"
' Define Selection and clear
'---------------------------------
Dim UserSel As Selection
Set UserSel= CATIA.ActiveDocument.Selection
UserSel.Clear
Dim Plano As CATBSTR
Plano = UserSel.SelectElement2(What, "Escolha um plano", False)
If Plano = "Normal" Then
Set Plano = UserSel.Item(1)
Else
MsgBox ("Função interrompida")
End If
Factory.PutInputData "Plano", Plano
' Clear Selection
'------------------------------------------------------------------
UserSel.Clear
'------------------------------------------------------------------
Catia.SystemService.Print "Instantiate"
Dim Instance As ShapeInstance
Set Instance = factory.Instantiate
'------------------------------------------------------------------
Catia.SystemService.Print "End of Instantiation"
factory.EndInstantiate
'------------------------------------------------------------------
Catia.SystemService.Print "Release the reference document"
factory.EndInstanceFactory
'------------------------------------------------------------------
Catia.SystemService.Print "Update"
PartDest.Update
End Sub
Anybody can try to help me?
RE: Catia Macro for power Copy
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Catia Macro for power Copy
I have made some new developments, but it stil doesn't work (but this time like I want). I have found a macro on internet, and i have made some adjustments.
It only work when i have a product like the attached one, and it only works with part2 of product3 activated. I want a macro that works in the active document, but i haven't found a way to put it work. Can you help me?
The code that i have at the moment (sorry it's a litle bit messy with some german mixed)
CATIA.StatusBar = "CATScript, Version 1.1"
Sub CATMain()
Dim IntPointObj1, IntPointObj2 As Object
'Private Sub SelectButton1_Click()
'Auswahl festlegen -----------------------------------------------
Dim Filter(1)
Filter(0) = "Plane"
Filter(1) = "Face"
'Selektion definieren und leeren ----------------------------------
Dim UserSel As Object
Set UserSel = CATIA.ActiveDocument.Selection
UserSel.Clear
'Selection vornehmen lassen ---------------------------------------
'INPUT-Geometrie 1: Bezugspunkt oben ------------------------------
Dim intSelAbfrageStr As String
' Abfrage ob Selektion stattgefunden hat
intSelAbfrageStr = UserSel.SelectElement2(Filter, "Escolha um plano ou uma face", False)
If intSelAbfrageStr = "Normal" Then ' Wenn ja, dann zuweisen des selektierten ..
Set IntplaneObj1 = UserSel.Item(1).Value ' .. Objektes an Variable intPointObj1
End If
Dim Prod As Product
Set Prod = CATIA.ActiveDocument.Product
Dim Prods As Products
Set Prods = Prod.Products
Dim myProd As Product
Set myProd = Prods.Item("Product3.1")
Dim myProds As Products
Set myProds = myProd.Products
Dim myPartInstance As Product
Set myPartInstance = myProds.Item("Part2.1")
Dim myPart As Part
Set myPart = myPartInstance.ReferenceProduct.Parent.Part
'Abrufen der factory des aktuellen Parts -----------------------
Dim myFactory As InstanceFactory
Set myFactory = myPart.GetCustomerFactory("InstanceFactory")
'Start der PowerCopy --------------------------------------------
' *** Pfad anpassen
myFactory.BeginInstanceFactory "PowerCopy.1", "C:\Users\tiago\Desktop\Power copy MCG\Socket head screw\Part1.CATPart"
'Start der Instanziierung der Input-Daten ----------------------
myFactory.BeginInstantiate
'Input-Geometrie einlesen ---------------------------------------
myFactory.PutInputData "Plano", IntPlaneObj1 ' Selektiertes Objekt an die PowerCopy senden
'-----------------------------------------------------------------
Dim Instance As ShapeInstance
Set Instance = myFactory.Instantiate
'Ende der Instanziierung ----------------------------------------
myFactory.EndInstantiate
'Lösen vom Referenzdokument --------------------------------------
myFactory.EndInstanceFactory
'Update ----------------------------------------------------------
myPart.Update
End Sub
Thanks
RE: Catia Macro for power Copy
It looks that i found a solution. Until now it looks very reliable, and I will share the code with you.
CATIA.StatusBar = "CATScript, Version 1.1"
Sub CATMain()
'EFECTUAR UMA SELECÇÃO -----------------------------------------------
'PLANO INICIAL -----------------------------------------------
Dim Filter1(1)
Filter1(0) = "Plane"
Filter1(1) = "Face"
Dim UserSel As Object
Set UserSel = CATIA.ActiveDocument.Selection
UserSel.Clear
Dim plano1 As String
plano1 = UserSel.SelectElement2(Filter1, "Escolha um plano ou uma face de assentamento", False)
If plano1 = "Normal" Then
Set face_assentamento = UserSel.Item(1).Value
End If
'PONTO LOCALIZAÇÃO -----------------------------------------------
Dim Filter2(0)
Filter2(0) = "Vertex"
UserSel.Clear
Dim ponto1 As String
ponto1 = UserSel.SelectElement2(Filter2, "Escolha o ponto de localização", False)
If ponto1 = "Normal" Then
Set ponto_localizacao = UserSel.Item(1).Value
End If
'PLANO FINAL -----------------------------------------------
Dim Filter3(1)
Filter3(0) = "Plane"
Filter3(1) = "Face"
UserSel.Clear
Dim plano2 As String
plano2 = UserSel.SelectElement2(Filter3, "Escolha a face ou plano final", False)
If plano2 = "Normal" Then
Set plano_final = UserSel.Item(1).Value
End If
'SELECCIONAR PEÇA PARA ATRIBUIR POWER COPY ----------------------------------
Dim Doc As ProductDocument
Set Doc = CATIA.ActiveDocument
Dim Prod_Root As Product
Set Prod_Root = Doc.Product
Dim Prods_Root As Products
Set Prods_Root = Prod_Root.Products
Dim oSelection 'As Selection
Set oSelection = Doc.Selection
Dim Status As String
Dim InputObjectType(0)
Dim prt As Part
oSelection.Clear
InputObjectType(0) = "Part"
Status = oSelection.SelectElement2(InputObjectType, "Seleccione a peça de destino da PowerCopy", False)
If Status = "Normal" And oSelection.Count = 1 Then
Set myPart = oSelection.Item(1).Value
End If
'INICIAR A APLICAÇÃO DA POWERCOPY -----------------------
Dim myFactory As InstanceFactory
Set myFactory = myPart.GetCustomerFactory("InstanceFactory")
myFactory.BeginInstanceFactory "Socket head screw with threaded holes", "C:\Dassault\Power Copy MCG\Socket head screw\Socket head screw with threaded holes.CATPart"
myFactory.BeginInstantiate
'Associação das às variáveis de entrada da powercopy ---------------------------------------
myFactory.PutInputData "Face assentamento", face_assentamento
myFactory.PutInputData "Ponto localização", ponto_localizacao
myFactory.PutInputData "Plano final", plano_final
'-----------------------------------------------------------------
Dim Instance As ShapeInstance
Set Instance = myFactory.Instantiate
'FIM DA APLICAÇÃO DA POWERCOPY ----------------------------------------
myFactory.EndInstantiate
myFactory.EndInstanceFactory
myPart.Update
End Sub
Sorry for the notes be written in portuguese but you can google it.
After made this macro, i have lots of ideas to improve my work. I will try to turn that ideas in a few macros.
Thanks by your help.
RE: Catia Macro for power Copy