Macro for Symmetry
Macro for Symmetry
(OP)
is it possible to create a macro or a script to do the following. I have no scripting experience
In a single catpart consisting of multiple part bodies, i would like to create a symmetry of each individual part body about a specified plane the user can pick. There could be anywhere from 10 to 50 or so part bodies in any particular instance, there would be no specific names to the part bodies, and the first main part body would always be empty. See picture. Any help would be appreciated
In a single catpart consisting of multiple part bodies, i would like to create a symmetry of each individual part body about a specified plane the user can pick. There could be anywhere from 10 to 50 or so part bodies in any particular instance, there would be no specific names to the part bodies, and the first main part body would always be empty. See picture. Any help would be appreciated





RE: Macro for Symmetry
In the same file or in different file (from what you wrote I can understand something else comparing with what is in screen capture) ? A sample file ?
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Macro for Symmetry
RE: Macro for Symmetry
I think if user have to pick the plane each time, significance of a macro will reduce.
Think about it.
Regards,
Vikt
RE: Macro for Symmetry
RE: Macro for Symmetry
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Macro for Symmetry
RE: Macro for Symmetry
I started to record a macro by repeating all those operations just for few bodies. Then I looked into code and deleted all repetitive parts (let just first part of code, if you will be curios to record a macro I'm sure you will understand which part to keep).
Then you need to think a little bit how to do same part of code in a repetitive way...the simple way is to go by search all bodies, put them in a selection, then do same thing for each one of them starting with number 1 and ending with Count2.
Sometimes is very easy to combine recorded codes with something which you can find in v5automation file...of course it will be something else if you want to pick an arbitrary plane and not this specific YZ plane.
CODE --> CATScript
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Macro for Symmetry
RE: Macro for Symmetry
Jopal, search criteria is selection1.Search "Name=PartBody' 'from*,all" , which means all Bodies names has to start with "PartBody from"....so you have a naming problem in this template part...
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Macro for Symmetry
I'm trying to do the exact same code, except instead of symmetry, i want a rotate instead about the default z axis of the file. I cant seem to get it to work
RE: Macro for Symmetry
Language="VBSCRIPT"
Sub CATMain()
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
''''''''search by name to create selection - this part can be also recorded
Dim selection1 As Selection
Set selection1 = partDocument1.Selection
selection1.Search "Name=PartBody' 'from*,all"
X = selection1.Count2 ''count all bodies according with search criteria
For i = 1 To X ''''''''start cycle
NumePB = selection1.Item(i).Value.Name ''we need to get the name of each item to use it later
''''MsgBox NumePB '' comment, MsgBox was just for additional checks
''''''''this part of code was initially recorded
Dim part1 As Part
Set part1 = partDocument1.Part
Dim bodies1 As Bodies
Set bodies1 = part1.Bodies
Dim body1 As Body
Set body1 = bodies1.Item(NumePB) ''Item(NumePB) is the only part of code modified instead of what was recorded, need to have something general not only for a specific name
part1.InWorkObject = body1
Dim shapeFactory1 As Factory
Set shapeFactory1 = part1.ShapeFactory
Dim hybridShapeLineExplicit1 as AnyObject
Set hybridShapeLineExplicit1 =hybridShapes1.Item("Z Axis")
Set reference1 = part1.CreateReferenceFromObject(hybridShapeLineExplicit1)
Set rotate1 = shapeFactory1.AddNewRotate2(reference1, 180.000000)
Set hybridShapeRotate1 = rotate1.HybridShape
hybridShapeRotate1.RotationType = 0
hybridShapeRotate1.Axis = reference1
part1.InWorkObject = hybridShapeRotate1
part1.Update
''''end of first "block" of the recorded code
Next ''''to repeat operation for each item
End Sub
RE: Macro for Symmetry
comment this lines:
CODE -->
'Dim hybridShapeLineExplicit1 As AnyObject 'Set hybridShapeLineExplicit1 = hybridShapes1.Item("Z Axis") 'Set reference1 = part1.CreateReferenceFromObject(hybridShapeLineExplicit1)and add this just after ...
CODE -->