Powercopy and macro connection
Introduction
A powercopy can be any set of CATIA features. It can be very simple, like one body and pad, but it can be very advanced too. You can make very advanced powercopies with a lot of elements, even rules, and tables. We will not define a macro, because we wrote about it on this post.
First of all, if you don’t have a lot of knowledge about powercopy and macro this can be very useful for you. Powercopy is very powerful to use and even easier to make. For powercopy, you don’t need to have programming knowledge. On the other hand, if you have basic programming knowledge you can make very powerful stuff with a combination of powercopy and macro. So in this post, we will show you how to make powercopy and macro and how to make a connection.
Making powercopy
We can say almost every model in CATIA certainly has some sort of holes. There are two ways to make them. So you can do it manually for each part or you can use powercopy. With the power of powercopy, you can easily be organized and fast. Also, you can share it with a team. Using the same powercopy by the team you will get a lot of advantage. Every part of every model will have the same structure. Let’s make one very simple powercopy.
You need to open a new part and enter a name for it. In this example, we will use holes_powercopy. You must define inputs for powercopy. We will need an axis system and one plane as inputs. Now you need to make holes for a screw head and thread section but everything must be connected with inputs. It’s easier to make a video for this.
In the previous video, we created simple powercopy. Besides that, you can see other possibilities. You can also add parameters and relations, insert table for screw dimensions and so on. Powercopy can have very complex geometry with a lot of inputs. When you insert powercopy as I did in the video, you need to do something. For example, remove that SREW_HEAD body from PartBody and make publication for SCREW_THREAD. You can do this manually but also you can record a simple macro to do that for you. This is very practical because the names of bodies are identical every time.
Connect powercopy and macro
Let’s insert powercopy again. Add the body and make a publication with macro instead of manual recording. If you want to read more about recording macro you can do it on this link.
Add-on for VB code is making an error it converts “&” to “&”
Language="VBSCRIPT"
Sub CATMain()
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim bodies1 As Bodies
Set bodies1 = part1.Bodies
Dim body1 As Body
Set body1 = bodies1.Item("PartBody")
part1.InWorkObject = body1
Dim shapeFactory1 As Factory
Set shapeFactory1 = part1.ShapeFactory
Dim body2 As Body
Set body2 = bodies1.Item("SCREW_HEAD")
'THIS PART OF CODE IS EDITED
Dim Remm
Set Remm=shapeFactory1.AddNewRemove( body2)
Remm.name=body2.name
part1.Update
'Part of code for publication
Dim Part_Name
Part_Name = CATIA.ActiveDocument.part.name
Dim product1 As CATBaseDispatch
Set product1 = partDocument1.GetItem(Part_Name)
Dim reference1 As Reference
Set reference1 = product1.CreateReferenceFromName(Part_Name & "/!SCREW_THREAD")
Dim publications1 As Publications
Set publications1 = product1.Publications
Dim publication1 As Publication
Set publication1 = publications1.Add("SCREW_THREAD")
publications1.SetDirect "SCREW_THREAD", reference1
Dim settingControllers1 As SettingControllers
Set settingControllers1 = CATIA.SettingControllers
Dim visualizationSettingAtt1 As SettingController
Set visualizationSettingAtt1 = settingControllers1.Item("CATVizVisualizationSettingCtrl")
visualizationSettingAtt1.SaveRepository
End Sub
This is a recorded code with a small edition. You don’t need to understand all of the code to use it. In this way you can make a lot of small macros and combine them with powercopies.
I think this is a very useful thing to know because it can help you to be faster and more organized. Make your powercopies and macros for time-saving.
Also you can check my YouTube channel CATIA Tutorials
