ComponentOccurrence.Replace method in VBA

ComponentOccurrence.Replace method in VBA

Anonymous
Not applicable
2,025 Views
3 Replies
Message 1 of 4

ComponentOccurrence.Replace method in VBA

Anonymous
Not applicable
has anyone got an example of ComponentOccurrence.Replace method in VBA they could give me? Would be most appreciated.
0 Likes
2,026 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Hay,

What is the problem in calling that function. In my las company I did a project in which I used that method, but currently I don't have the code. But What I remember is it is straight forward. The only thing you should consider that you should provide the full path of the file by which you want to replace the occurence. Also if your occurence contains mate then the new component too should contain the same mate name. If you are not able to do it then let me know, I will try a small sample for you.

Thanks
Manoj
0 Likes
Message 3 of 4

Anonymous
Not applicable
Hello,

Sorry, but i´m new using this. I´m trying to use the componentoccurrence.replace too, and i´m would like to know how to get the occurrence i want to change.

Thanks.
Frederico Ottoni.
0 Likes
Message 4 of 4

Anonymous
Not applicable
Hi Take the look at the following sample.

Public Sub ReplaceOccurance()
Dim oAssDoc As Inventor.AssemblyDocument
Set oAssDoc = ThisApplication.ActiveDocument

Dim oAssCompDef As Inventor.AssemblyComponentDefinition
Set oAssCompDef = oAssDoc.ComponentDefinition

Dim oAssOccurences As Inventor.ComponentOccurrences
Set oAssOccurences = oAssCompDef.Occurrences

Dim oCompOccur As Inventor.ComponentOccurrence
For Each oCompOccur In oAssOccurences
MsgBox oCompOccur.Name
'Either you can use the name of the occurence or the index of the occurence
'to replace a particular occurence by a different part or sub assembly

'Please note that if the second parameter is true and the same occurence has multiple instances
'i.e. a car has four wheels, and if the replace is called on any of the wheel occurence with
'second parameter true, all the wheels will be replaced otherwise only that instance
'will be replaced on which will be called.
If oCompOccur.Name = "MYOCCURANCE" Then
Call oCompOccur.Replace("C:\Myoccorence.ipt", False)
End If

'If the occurence is attached by imate and the replacing part or assembly does not have the
'correct imate then the imates will fail
Next
End Sub

In this sample I have used the name of the occurence to replace one. You can use the index too. The indexing is same as the position in the browser pan. For useing the index you need to change the for loop as follows

Dim i As Long
For i = 1 To oAssOccurences.Count
Set oCompOccur = oAssOccurences(i)
Select Case i
Case 1:
'replace at index 1
Case 2:
'replace at index 2
Case Else:
'replace default
End Select
Next

Hope this will help you problem

Manoj
0 Likes