Replace Sub assembly in main Assembly with ILogic Rules

Replace Sub assembly in main Assembly with ILogic Rules

MKaygisiz
Observer Observer
1,123 Views
5 Replies
Message 1 of 6

Replace Sub assembly in main Assembly with ILogic Rules

MKaygisiz
Observer
Observer

Hello, I'm studying on a project for my PhD education. I need to solve some problem about the ilogic rules.. I should say that i'm begining of the inventor ilogic. 

That's my problem ;

I have MAIN Assembly 

There is two different sub-assembly 
and also two options for each sub-assembly 

I want to change subassembly completely in main assembly with the rule. 

ıf Parameter_A = " Cylinder" And Parameter_B = " Rectangular" Then 

Component.Replace (" Subassembly_Rectangular", "Cylindrical.iam", True)

Component.Replace(" Subassembly_Cylindrical", "Rectangular.iam", True)
ElseIf Parameter_A = " Rectangular" And Parameter_B = " Cylindrical" Then
Component.Replace (" Subassembly_Cylindrical", "Rectangular.iam", True)

Component.Replace(" Subassembly_Rectangular", "Cylindrical.iam", True)

End If

Important Infos:

Main Assemble Name : Project.iam

SubAssembly Name : Mirror.iam

SubAssembly Name : Desk.iam 

Desk and Mirror have two options as "Rectangular" and "Cylindrical" 

How can i replace all sub assembly in main assembly when i choose MutliValue Parameters. 

Thank you all. 🙂

 

0 Likes
1,124 Views
5 Replies
Replies (5)
Message 2 of 6

JamieVJohnson2
Collaborator
Collaborator

here is a file that replaces the file reference using a files path, utilizing the ApprenticeServer:

 

Public Sub ReplaceModelReference(fi As System.IO.FileInfo)
        'GetInventorApplication()
        'Dim invDoc As Inventor.Document = invApp.Documents.Open(fi.FullName)
        Try
            Dim appInv As New ApprenticeServerComponent
            Dim invDoc As ApprenticeServerDocument = appInv.Open(fi.FullName)
            Dim fde As FileDescriptorsEnumerator = invDoc.File.ReferencedFileDescriptors
            For Each fd As FileDescriptor In fde
                Dim fileNew As String = fd.FullFileName.Replace("Orig Keyword ", "New Keyword")
                fd.ReplaceReference(fileNew)
            Next
            appInv.FileSaveAs.AddFileToSave(invDoc, invDoc.FullFileName)
            appInv.FileSaveAs.ExecuteSave()
        Catch ex As Exception
            'Dim eh As New ErrorHandler(ex)
            'eh.HandleIt()
        End Try
    End Sub

I used this when I had to repath an entire project worth of files.

 

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 3 of 6

JamieVJohnson2
Collaborator
Collaborator

Note, you can do the same code without using the ApprenticeServer.  

        Dim invApp as Inventor.Application = ThisApplication

        Dim invDoc2 As Inventor.Document = invApp.Documents.Open(fi.FullName)
        Dim fde As FileDescriptorsEnumerator = invDoc2.File.ReferencedFileDescriptors

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 4 of 6

MKaygisiz
Observer
Observer

To be honest, I don't understand very well. How can i use this functions. 

Can you describe me using of this functions. What should i write at the begining exactly.

0 Likes
Message 5 of 6

JamieVJohnson2
Collaborator
Collaborator

So for each file you place into an assembly it has a file descriptor object.  This object tracks what the file's name is and where its found, and what type it is.  It also gives you control over changing that file path, without removing the component occurrence.

 

AssemblyDocument.Defintion.Occurrences.Occurrence = a single instance of an part in your assembly (think model browser tree).

 

In a different location of the assembly file document, Inventor keeps track of all the file references that these occurrences use.

 

AssemblyDocument.File.ReferencedFileDescriptors.FileDescriptor = a single file that can be referenced one or many times within your assembly (think AutoCAD Ex-Reference list).

 

So while we use Occurrences to manipulate the model, we use FileDescriptors to change the reference paths.

So you do the following:

1.  Open the assembly document.

2.  Cycle through the List of ReferencedFileDescriptors

3.  Look for the file you are interested in changing.

4.  Replace FileDescriptor's Reference (fd.ReplaceReference(FileNew))

5.  Save the Assembly.

 

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 6 of 6

Anonymous
Not applicable

You are almost there with the code you have.

 

The proper way to replace components through iLogic is to stabilize (rename) the parts in your browser. In your example, Desk and Mirror would be appropriate. This way the browser name doesn't change when you replace the component.

2019-01-04_14h12_18.png

One thing that's confusing me is that you have two options for each sub-assembly but it looks like you only have two assemblies (Cylindrical.iam & Rectangular.iam).  I'm assuming you have a rectangular mirror and a rectangular desk option as well as a cylindrical mirror and cylindrical  desk option? If so, I'd recommended giving them more specific file names.

 

On the basis of that assumption, your rule would go like this:

If Parameter_A = " Cylinder" And Parameter_B = " Rectangular" Then 

	Component.Replace ("Desk", "Cylindrical Desk.iam", True)

	Component.Replace("Mirror", "Rectangular Mirror.iam", True)
	
ElseIf Parameter_A = " Rectangular" And Parameter_B = " Cylindrical" Then
	
	Component.Replace ("Desk", "Rectangular Desk.iam", True)

	Component.Replace("Mirror", "Cylindrical Mirror.iam", True)

End If

 

If you want more flexibility to alter your design, then I'd write the rule like this:

If Parameter_A = "Cylinder" Then 
	Component.Replace("Desk", "Cylindrical.iam", True)
Else
	Component.Replace("Desk", "Rectangular.iam", True)
End If

If Parameter_B = "Cylinder" 
	Component.Replace("Mirror", "Cylindrical.iam", True)
Else
	Component.Replace("Mirror", "Rectangular.iam", True)
End If

 

Also note, when using Component.Replace, setting the ReplaceAll boolean to True, will replace all instances of that file, whereas setting is to False will only replace the one instance (the one that has been renamed)

0 Likes