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!

CATIA VBA renaming one item of a selection

Status
Not open for further replies.

jissididi

Automotive
Mar 17, 2015
46
FR
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:
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
 
Replies continue below

Recommended for you

Try to use this.

I believe it does what you want.

Code:
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
 
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.
 
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"
print_afjh30.png
 
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
 
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
 
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
 
What Tiago is saying is something like this

Code:
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

- Romania
- EU
 
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)
 
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.

Untitled_qu3iuh.png


Tiago Figueiredo
Tooling Engineer
 
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
 
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
 
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....
 
the planar sections are selected
so the selection works fine but the .Name method does not with the planar sections
 
try this for rename

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

Tiago Figueiredo
Tooling Engineer
 
no it does not work either
tells me that NewName does not support the .Name property
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top