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 Selection

Status
Not open for further replies.

elmundo777

Automotive
Jun 23, 2020
93
BY
Interested in the question: in turn, I selected the necessary elements in the tree. Next, I want to change their names in the same order.

But the problem is that Сatia does not understand the order and changes names in a random order. Where is the mistake?
I did not find information in the V5Automation.chm file.

red numbers - the order of selection of elements
blue numbers - how Сatia sees their order
tree_order_selection_icihrk.png


And here part of the code where I save the selected item with the name of the table:

Code:
for z as Integer = 1 to selection1.Count
   docPath = DataGridView1.Rows(bList_indexes.ElementAt(z-1)).Cells(6).Value
   selection1.Item(z).Value.ReferenceProduct.Parent.SaveAs(docPath & "\\" & selection1.item(z).LeafProduct.PartNumber)         
 Next
 
Replies continue below

Recommended for you

Selection preserves order in which elements were selected.
In fact it never behaves randomly.
 
how can I refer to the selected items in the order of selection?
 
When i want to run this code:
Code:
 Dim i as Single
        dim selection2 as Selection = Catia.ActiveDocument.Selection
        for i = 1 To selection2.count2
            selection2.Item(i).Value.Name = selection2.item(i).LeafProduct.PartNumber & "_" & i 
        Next
it works like this:
5 item, 1 item, 2, 3, 4.
that is, it processes the last element of the collection first.

This code adds to selection:
Code:
Dim uSel As Selection
             uSel = CATIA.ActiveDocument.Selection
            uSel.Search( "('Assembly Design'..'Part Number'=" & nameWithoutExt & "),all")
            aList.Add(usel.item(1).value)
     
        for item as Integer = 0 To aList.Count - 1 
            selection1.Add((aList.Item(item))) 
        Next

Where is an error?
 
this is how I'd get the found, and selected items into the array
Code:
Sub CATMain()

Dim mySel As Selection
Set mySel = CATIA.ActiveDocument.Selection

Dim selString As String
selString = "'Assembly Design'.Product.Name=*ASSY*"
mySel.Clear
mySel.Search selString

Dim i As Integer
If mySel.Count > 0 Then
    ReDim aList(mySel.Count)
    For i = 1 To mySel.Count
        Set aList(i - 1) = mySel.item(i).Value
    Next
End If

End Sub

regards,
LWolf
 

I want to find an item that matches the search criteria. after create a selection from all found elements.
 
tesak said:
Your requirements now differs completely? It is really not clear what you are after. Anyway, share the complete code, if you expect to identify error.

I'm want to find documents by name in a loop and add them to the selection.

For example, I have products and parts. I want to select product2 and product4 in the tree. I find them by name, select them. Then I carry out the operations of renaming and saving.

Problem with adding to selection and accessing the selected item of the collection.

In a selection, the first index is the last one. And I don’t understand why.
For example 5 documents are selected. Their order: 5,1,2,3,4.

The code for searching by name and adding to the selection was dropped above.
 
I am not really sure why do you need to add to selection. If you find products you need, you can get them from selection and store them in a collection or dictionary. Later, you can use them as you wish.

I do not see a logic in a code from above. You search selection to get desired items, then you loop selection to store them in a list and later on you loop the list in order to add items to selection, the same items which are already presented in selection ... What???

Tesak
- Play Tetris in CATIA V5 drawing
 
Thank you all for your help. I found a bug.
Before adding to the selection - I forgot to write the selection clear. Therefore, the selection always starts from the last found element.
 
I have a table in the application of the vb.net form. In the table also have a column with checkboxes. When you click in the checkboxes, the tree elements are selected in the Catia. After that I perform renaming and/or saving operations with the selected elements.
 
It is not very efficient solution. You should read the whole structure in advance, store it, make your table and just then add/remove items from selection on checkbox click. On fly searching will be really slow for big assemblies and if you perform it on every checkbox click, user experience is going to be horrible.

Tesak
- Play Tetris in CATIA V5 drawing
 
Tesak, you're making a good points as always.

Off-topic.
I've emailed you at scripts4all, please reply if you're interested.
 
The program has been tested on large assemblies. works pretty fast.
When loading the form - the tree structure is already loaded in the table. and the original names of the documents are saved in the list.
The user selects by checkboxes the documents he wants to work with. After in rows of the table user changes documents names. Then he clicks on the "rename" button and the documents are renamed. then the second button, which allows you to save documents (on the right in the table is the column where the user specifies the path for files)

As a result, we have an analogue of save management, but with additional functions that I have not indicated here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top