Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recording a Macro with Renaming

Status
Not open for further replies.

akhtar07

Mechanical
Mar 8, 2015
59
AE
Hi all,

I am trying to generate a macro with renaming feature in CATIA but it seems like macro skips the part of renaming and moves on.

Is there any way to do it?

example what i am doing :

I generate different Geometrical Sets, I rename them to A, B and C and record the macro. When i run the macro it works fine but it creates Geo Sets with Geometrical Set 1, 2 and so on.

Can any body tell me how to overcome this problem ?

Your help is of great importance to me.
 
Replies continue below

Recommended for you

Option Explicit
'
Sub CATMain()
'
Dim CatPart As Part, CatHybridBodies As HybridBodies, CatHybridBody As HybridBody, i As Integer
'
Set CatPart = CATIA.ActiveDocument.Part
Set CatHybridBodies = CatPart.HybridBodies
'
For i = 1 To 10
Set CatHybridBody = CatHybridBodies.Add()
CatHybridBody.Name = Chr(64 + i)
Next i
'
CatPart.Update
'
End Sub
 
Hello AKCalixto,

Thank you so much for you kind reply.

I am stiff confused because what if I want to rename the geometrical sets to something like From Boss, Part Geometry and Cutting Direction ?
 
That means you have standard GeoSets in a CATPart and you want to create them with specific names....please try to be a bit more explicit when asking something. I would suggest you to try to modify the AKCalixto code (which is very good, by the way) according to your needs, looking also to the code bellow (is longer but is giving you a clear idea).


Code:
Language="VBSCRIPT"
Sub CATMain()

'Works in an active CATPart, create new specific named geometrical sets 

Dim oPartDoc As Part
On Error Resume Next
Set oPartDoc = CATIA.ActiveDocument.Part    
If Err.Number <> 0 Then                   
Message = MsgBox("Sorry, This script works with a CATPart as Active document, so please open CATPart in a new window", vbCritical, "Error")
Exit Sub
End If

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim HB0,HB1,HB2 As HybridBodies
Set HB0 = CATIA.ActiveDocument.part.HybridBodies
Set HB1 = CATIA.ActiveDocument.part.HybridBodies
Set HB2 = CATIA.ActiveDocument.part.HybridBodies

Set HB0 = HB0.Add()
Set HB1 = HB1.Add()
Set HB2 = HB2.Add()

HB0.Name = "From Boss"
HB1.Name = "Part Geometry"
HB2.Name = "Cutting Direction"

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Dim body1 As Body
Set body1 = bodies1.Item("PartBody")
part1.InWorkObject = body1
part1.Update 

End Sub

Regards
Fernando

- Romania
- EU
 
Hello Ferdo,

Thank you very much.

It works perfect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top