Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

CATIA Macro: algorithm 1

Status
Not open for further replies.

elmundo777

Automotive
Jun 23, 2020
93
Hello. I need help with creating algorithm.
I'm trying to assign names to CATIA tree elements from table rows. See pictures:

Tree:
tree_kyn9nk.png


Table:
table_gpfpsd.png



I have an idea how it should look roughly in pseudocode, but I don't have enough knowledge to implement it. (vb.net language or catscript\c#\vba. does not matter).
Cycles in pseudocode:
For i = 1 to catia.docs.count
For Z = 0 To DataGridview.Rows.Count - 2
Dim nameRename As String = DataGridview.Rows(Z).Cells(0).Value
item(i).name = nameRename


How to implement it correctly?
Thanks!
 
Replies continue below

Recommended for you

File names, instance names and partnumbers are all independent in CATIA.
Moreover, the idea of renaming specification TREE based on excel TABLE data seems like a bad one. It will lead to errors and ambigious results in models with more than one level of indentation.

Why would you want to do what you're describing in the first place? What is your final goal?
 
I want to create a small but useful utility for quick renaming.
And then saving to the selected directory
 
Why would you need a tool like that? There's a "Save management" command.

What about instance namea and partnumbers? Are you going to provide them as an input as well?
 
For the instance name, the name is also changed in the cycle. instance name = part number + .1
there are no problems with these.
the problem is to assign names to the documents one by one as they are given in the table.

Second problem - if the root product does not exist on disk and I try to save it with a new name - I get an error 0x8004005

So I want to change all the names that I require
and then save it as the whole product.

save management doesn't suit me.
I have name templates written to the table. which greatly simplifies the process.
 
This is good video. But it didn't make it any easier. it won't solve my problem
 
Code:
Selection.Search "CATAsmSearch.Product+CATAsmSearch.Part,all"
for i=1 to Selection.Count
  Selection.Item(i).ReferenceProduct.Parent.SaveAs   ExcelRange(i)
Next
 
Good decision. But I can't beat the problem of renaming a not yet saved main product.
I always get an error.
 
Little Cthulhu said:
Selection.Search "CATAsmSearch.Product+CATAsmSearch.Part,all"
for i=1 to Selection.Count
Selection.Item(i).ReferenceProduct.Parent.SaveAs ExcelRange(i)
Next
Also i have this:
ex_vepmgb.png
 
Item(i).Value.ReferenceProduct

As for saving not yet saved product try calling Save before SaveAs
 
Little Cthulhu said:
Item(i).Value.ReferenceProduct

As for saving not yet saved product try calling Save before SaveAs
I don't know what i do wrong....
err2_kywfnm.png
 
I found one of the errors: the saved files have a link/reference to the old files and display their data, not the new ones.
how to make an analogue using code? (see picture below)
info_forum_hyyl5e.png
 
Little Cthulhu said:
Try inverting for loop order
I had an idea to run in reverse order
but nothing is saved
i'm get an error
Code:
 oSelection.Search("CATAsmSearch.Product+CATAsmSearch.Part,all")
        for i =  oSelection.Count to 0 step -1
            ' oSelection.Item(i).Value.ReferenceProduct.Parent.Save()
            oSelection.Item(i).Value.ReferenceProduct.Parent.SaveAs(pathQ & "\\" & documents1.Item(i).Name) 'HERE AN ERROR System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
            oSelection.Item(i).Value.ReferenceProduct.Parent.Save()
        Next
 
Inspect what value you actually use as save path and try saving using exactly that value manually. We're talking about last (first in a loop) document.
By the way loop should end with 1, not 0
 
Little chtulhu said:
Inspect what value you actually use as save path and try saving using exactly that value manually. We're talking about last (first in a loop) document.
By the way loop should end with 1, not 0
in any case, links to previous versions remain.

eg: I created a product document. added 3 products and one part to it. gave names.
product 1e
--product 2e
--product 3e
--product 4e
--part1e

saved them to next folder: c: / temp / 1 /

then I rename this document as follows:
product 1__a
--product 2__a
--product 3__a
--product 4__a
--part1__a

save to folder
c: / temp / 2 /
as a result, the names from folder 1 are saved, but the names are new in the tree structure itself.
I assume this is due to links and needs to be saved as a new document. but how to do that?
 
Little Cthulhu said:
Selection.Search "CATAsmSearch.Product+CATAsmSearch.Part,all"
for i=1 to Selection.Count
Selection.Item(i).ReferenceProduct.Parent.SaveAs ExcelRange(i)
Next

Could you also suggest how to save only the selected components?
analog save management
tree_selection_biacnf.png
 
Try using SendTo for saving. If it won't work you have to use NewFrom and make document "copies" by yourself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor