Hi,
I try to copy a Body of an instanciate Part into an other Part but if I work with objects, Catia returns always the body of the first instance.
That’s my first script but it doesn’t work (In a first time I tried to copy the complete instanciate Part before trying to copy a Body...)
Sub test()
Set root = CATIA.ActiveDocument.Product.Products
Set subprod = root.Item("Sub-Product_in_root").Products
Set subprod2 = subprod.Item("Product_in_Sub-Product").Products
Set subprod3 = subprod2.Item("Product_containing_the_instanciated_products").Products
Set lastinstance = subprod3.Item("Instance.4").Products
Set Partprod = lastinstance.Item("Part.1").ReferenceProduct.Parent
Set copybody = Partprod.part
Dim oSelElem As SelectedElement
CATIA.ActiveDocument.Selection.Add (copybody)
End Sub
Ok, now I know that it’s not possible to use the objects. So I tried to use the search function.
First sample:
Search the Body in the complete document. 2 possibilities:
1- The Body is at the end of the selection, ok, I use the findObject function to remove the prevorious elements.
2- The Body is not at the end: Problem because I can’t remove a specified item from the selection. In fact I can find out the item position in the selection if the selected item x is contained in my instanciate part:
Sub test49()
Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = productDocument1.Selection
selection1.Clear
selection1.Search "Name='Searched_Body',all"
ReDim test_array(selection1.Count - 1)
'ReDim test_array_2(selection1.Count - 1)
For i = 0 To selection1.Count - 1
'Set test_array_2(i) = selection1.Item(1)
'Findobject remove the foundobject from selection
Set FoundObject = selection1.FindObject("CATIAProduct")
If FoundObject.Parent.Parent.Name = "instance_name" Then
test_array(i) = 1
Else
test_array(i) = 0
End If
Next
selection1.Clear
selection1.Search "Name='Searched_Body',all"
'Remove from selection à seems no to be possible
For i = 0 To selection1.Count - 1
'Set sel = selection1.Item(i + 1)
If test_array(i) = 0 Then
'Doesn’t work:
'Set ert = selection1.Item(i + 1).FindObject("CATIAProduct")
'Selection.Item(i + 1) = Nothing
'Selection.Item(i + 1) = ""
Else
'Item (i+1) contained in the specified instance, OK
End If
Next
End Sub
That method doesn’t work because I can’t remove a specified Item from the selection.
2 bis- Search use the „search in“ function:
Sub test50()
Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = productDocument1.Selection
selection1.Clear
selection1.Search "Name='Searched_Body',in"
selection1.Copy
End Sub
But in that case, I have to activate the instancited Part with a double-clik. This method work but I need to find out how to activate this last instanciated Part...
Can you help me ? because I have no other idea for the moment.
Thanks
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP