×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

CATIA VBA renaming one item of a selection

CATIA VBA renaming one item of a selection

CATIA VBA renaming one item of a selection

(OP)
Hello all,

I have an issue in a macro i'm making
I have various geometrical set all of them for different uses
in those Geometrical sets, I created some planar sections and then I want to rename them all "Planar Section.1" "Planar Section.2" "Planar Section.3"...
to create the planar sections, I create them all at the same time using the mesh and all the different planes and creating them by plane.

problem is that if there has been a section created previously, my first created section won't have the name "Planar Section.1"

So i created a selection of all the planar sections in the geometrical set corresponding, used the selction.item(i) to make a for loop and rename them all
but it doesn't work...

here is my idea

CODE --> Next

oSelection.Clear 
Set oSelection = CATIA.ActiveDocument.Selection 
oSelection.Add part1.FindObjectByName("AUTO_MODE_GEOMETRICAL_SET") 
oSelection.Search "'Part Design'.'Wireframe & Surface Feature';sel" 
iterationAutoMode = oSelection.Count
 
For i = 1 To iterationAutoMode

    oSelection.Item(i).Value.Name = "AUTO_MODE_GEOMETRICAL_SET_SECTION_" & i

Next 

Anyone has a working idea ?

Thanks
jissididi

RE: CATIA VBA renaming one item of a selection

Try to use this.

I believe it does what you want.

CODE --> CatVBA

Sub CATMain()
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Set oSelection = CATIA.ActiveDocument.Selection
oSelection.Clear
Dim part1 As Part
Set part1 = partDocument1.Part
oSelection.Search "(Name=AUTO_MODE_GEOMETRICAL_SET* & (CATPrtSearch.OpenBodyFeature)) ,all"
iterationAutoMode = oSelection.Count
 For i = 1 To iterationAutoMode
    oSelection.Item(i).Value.Name = "AUTO_MODE_GEOMETRICAL_SET_SECTION_" & i
 Next

End Sub 

Tiago Figueiredo
Tooling Engineer

RE: CATIA VBA renaming one item of a selection

(OP)
Hello again,

Thanks for the post but it was not the name of the geometrical set i wanted to change but the name of the sections which are inside the geometrical set.
as i have for example 10 section in the first geometrical set and 5 in the second geometrical set, i want to change the name of each section accordingly to the geometrical set they are

Thanks again.

RE: CATIA VBA renaming one item of a selection

can you make a print screen?

Tiago Figueiredo
Tooling Engineer

RE: CATIA VBA renaming one item of a selection

(OP)
I want my planar sections to be renamed with the name of the geometrical set followed by their number (1,2,3,4,5)
As you can see, in the geometrical set named "manual angular geometrical set", the planar sections created begin by 16, I want it to be 1, 2,3 as for the geometrical set "auto mode"

RE: CATIA VBA renaming one item of a selection

But in your macro you want to rename the sections of the "AUTO_MODE" and the "MANUAL_ANGULAR" or just the "MANUAL_ANGULAR"?

Tiago Figueiredo
Tooling Engineer

RE: CATIA VBA renaming one item of a selection

(OP)
both of them
in fact in my macro i can create first the manual ones or first the auto mode ones,
so that It can happen that sections from the auto set or from the manual set are created with a bad name

RE: CATIA VBA renaming one item of a selection

I would do the following:

1-Select the "Auto" geometrical set
2-Search all planar sections inside it
3-Rename all planar sections

4- the same for the "Manual"

Tiago Figueiredo
Tooling Engineer

RE: CATIA VBA renaming one item of a selection

What Tiago is saying is something like this

CODE --> CATScript

Language="VBSCRIPT"

Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = partDocument1.Selection

selection1.Search "Name=*GS_1*,all"

Dim oselection1 As Selection
Set oselection1 = partDocument1.Selection

oselection1.Search "CATPrtSearch.Plane,sel"
iterationAutoMode = oselection1.Count
 
For i = 1 To iterationAutoMode
    oSelection1.Item(i).Value.Name = "GS_1_Planar_Section_" & i
Next 

Dim selection11 As Selection
Set selection11 = partDocument1.Selection

selection11.Search "Name=*GS_2*,all"

Dim oselection11 As Selection
Set oselection11 = partDocument1.Selection

oselection11.Search "CATPrtSearch.Plane,sel"
iterationAutoMode11 = oselection11.Count
 
For i = 1 To iterationAutoMode11
    oSelection11.Item(i).Value.Name = "GS_2_Planar_Section_" & i
Next 

End Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208 - Romania
https://picasaweb.google.com/103462806772634246699... - EU

RE: CATIA VBA renaming one item of a selection

(OP)
ok,

does anyone know the search command that would allow me to select the "Planar Sections" instead of the planes ?
something like oselection11.Search "CATPrtSearch.Planar Sections,sel"

Thanks

(I have tried another way of getting the elements i wanted selected by selecting all the elements of the same type and removing the instances i didn't want
But when I finally have the element I want selected, I get an error during the oSelection.Name method and I don't know why)

RE: CATIA VBA renaming one item of a selection

(OP)
btw I am coding in VBA not VBScript

RE: CATIA VBA renaming one item of a selection

I don't have the license to access Planar Sections.
Try to record a macro where you find those, with the find command. On type select "from element" and pick one of those planar sections.

Tiago Figueiredo
Tooling Engineer

RE: CATIA VBA renaming one item of a selection

(OP)
Thank you Tiago
Here is what I found
I tell you if it solved my problem

Sub CATMain()

Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = partDocument1.Selection

selection1.Search "CATPrtSearch.SkinFeature,all"

End Sub

RE: CATIA VBA renaming one item of a selection

(OP)
Hi again,
So I tried it but unfortunately, the method oSelection.Item(i).Value.Name give me an error....
I don't know How to manage this anymore

iterationAutoMode = 0
oSelection.Clear
Set oSelection = CATIA.ActiveDocument.Selection
oSelection.Search ("Name=AUTO_MODE_GEOMETRICAL_SET")
oSelection.Search "CATPrtSearch.SkinFeature,sel"
iterationAutoMode = oSelection.Count
For i = 1 To iterationAutoMode
oSelection.Item(i).Value.Name = "MANUAL_ANGULAR_GEOMETRICAL_SET_SECTION_" & i
Next

RE: CATIA VBA renaming one item of a selection

(OP)
Another thing
I just tried to run my code selecting the planes instead of the planar sections and it works perfect,
I just don't understand why it does not work for the Planar Sections....

RE: CATIA VBA renaming one item of a selection

Remove the last 3 lines, and see what is selected

Tiago Figueiredo
Tooling Engineer

RE: CATIA VBA renaming one item of a selection

(OP)
the planar sections are selected
so the selection works fine but the .Name method does not with the planar sections

RE: CATIA VBA renaming one item of a selection

try this for rename

set NewName=selection1.item(i).value
NewName.Name="MANUAL_ANGULAR_GEOMETRICAL_SET_SECTION_" & i

Tiago Figueiredo
Tooling Engineer

RE: CATIA VBA renaming one item of a selection

(OP)
no it does not work either
tells me that NewName does not support the .Name property

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources