iLogicto read Browser

iLogicto read Browser

JorisSteurs1246
Advocate Advocate
652 Views
6 Replies
Message 1 of 7

iLogicto read Browser

JorisSteurs1246
Advocate
Advocate

Is it possible to read with iLogic the first .ipt or .aim from the browser tree in an assembly?

I need to know what that part name is so that I can replace it with another part using iLogic.

I've a function already that reads all the files , but I need very specifically to read the first file , or second for that matter, as long as it reads exactly the file that I point to.

All help really appreciated 🙂

0 Likes
Accepted solutions (1)
653 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

See how you get on with this.

 

 

On Error Resume Next
'Counts for the number of components in an assembly
Dim myDoc As Document
doc = ThisDoc.Document
myDoc = ThisApplication.ActiveDocument
If doc Is mydoc Then

' a counter starting at zero and going up by one for each component in the assembly
Dim counter As Integer = 0

'Grab the Assembly Document
Dim oDoc As AssemblyDocument
oDoc = ThisDoc.Document

'Grab the Active Assembly Component Definition
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Get the model browser
Dim oPane As BrowserPane
oPane = oDoc.BrowserPanes.Item("Model")

Dim AssySubtype As String
AssySubtype = "Assembly"

' Grab the occurrence of the object
Dim oOcc As ComponentOccurrence
For Each oOcc In oDoc.ComponentDefinition.Occurrences

counter = counter + 1

'this is the magic number that will decide whether  your code is fired or on not
If counter = 1 Then

'your code here

End If

Next
End If

 

Message 3 of 7

Jef_E
Collaborator
Collaborator

@JorisSteurs1246 wrote:

Is it possible to read with iLogic the first .ipt or .aim from the browser tree in an assembly?

I need to know what that part name is so that I can replace it with another part using iLogic.

I've a function already that reads all the files , but I need very specifically to read the first file , or second for that matter, as long as it reads exactly the file that I point to.

All help really appreciated 🙂


I don't get what you mean.. You state 3 different cases? the first, the first/second, the file you point to?

 

  • Do you want to read the filename/partnumber of the top item in the browser?
  • Do you want to read the filename/partnumber for selected item(s)?

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 4 of 7

Jef_E
Collaborator
Collaborator
Accepted solution

Why not point to the item number instead of starting a loop that runs through all occurrences if only occurrence 1 is required?

 

' Grab the occurrence of the object
Dim oOcc As ComponentOccurrence
oOcc = oDoc.ComponentDefinition.Occurrences.item(1)

 

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 5 of 7

JorisSteurs1246
Advocate
Advocate

Thank you guys, I got my code working using  the input of  SutherNe   but I  accepted  the code of Jef_E as solution.

Jef_E code also works for me and is much more simple.

To Answer your question Jef_E yes the code had to specify to a specific location in the browser  and with your code I can do so by changing .item(1) into another number. 

0 Likes
Message 6 of 7

Jef_E
Collaborator
Collaborator

Could you please post your finished code? It's nice for other user that have the same question to have a finished result.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 7 of 7

JorisSteurs1246
Advocate
Advocate

No problem,
So far this seems to work nicely

 

'Grab the Assembly Document
Dim oDoc As AssemblyDocument
oDoc = ThisDoc.Document

'Grab the Active Assembly Component Definition
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Define new part
Dim oReplacer As String
' Below replace with your replacing part / assy
oReplacer = "C:\Users\kasutaja\Documents\Inventor\Cadsherpa work\AUTO_Stair_1\REV1\parts\Standard\Fasteners\DIN 933 - M10  x 30 - St.ipt"

' Grab the occurrence of the object
Dim oOcc As ComponentOccurrence
oOcc = oDoc.ComponentDefinition.Occurrences.item(1)
oPartName = (oOcc.Name) ' get name
    If Component.IsActive(oPartName) = True Then
        Try
           Component.Replace(oPartName, oReplacer, True)'replace
        Catch
        MessageBox.Show("Could not replace: " & oPartName , "ERROR")
        End Try
    Else
    MessageBox.Show("The part to replace is not active", "NOT REPLACED")
    End If

 

0 Likes