Inventor iLogic - ReplaceReference()

Inventor iLogic - ReplaceReference()

mrichstein
Enthusiast Enthusiast
1,088 Views
5 Replies
Message 1 of 6

Inventor iLogic - ReplaceReference()

mrichstein
Enthusiast
Enthusiast

Hey at all,

my Name is Matthias and I am from germany.

After I started to automate a lot in the Inventor last year and was pointed out by a friend on his Inventor programming course, I have implemented a lot for the Inventor in VBA.

Since we work in plant engineering in our company and also go up in terms of our systems, we have to construct many kilometers of railings. Through my automation (using iLogic and VBA) in design, we have formed a team dedicated to standardizing and automating designs.Sreenshot_Geländer_002.PNGhere with suppress partshere with suppress partsI built the railing using iLogic and linked it with VBA. Unnecessary components are suppressed.
So that the newly created railing no longer has any reference to the iLogic maternal railing (the goal is to have no link to the mother iLogic), I have created the routine ReplaceReference ().

ReplaceReference corrects the name (the designation is specified manually by the designer 1x) of all 3D models including their 3D references.
Unfortunately, components with multiple identical components are suppressed, as well as the 3D references of ReplaceReference.
But if all components of an assembly are not suppressed, the names of the 3D models and file references are changed accordingly.

 

Then save the created railing.Now my question:

Why are components that are suppressed are overlooked by ReplaceReference even if negative pressures have been previously deleted?

Who can help me or can give any information?

 

here the rule:

Function ReplaceReference()

    'Setzen der Baugruppe a ls aktuelles Dokument
    Dim oDocAssem As AssemblyDocument    'oDocAssem = gesamte Baugruppe)
    'Dim oDocAssemblyNew As String 'nur für's Debugging
    'oFileAssemblyNew = "d:\Arbeitsbereich\Retek\ERP\29\016\29-016-019\29-016-019.iam<DetailgenauigkeitGeländer>" 'nur für's Debugging
    oFileAssemblyNew = oDocAssemblyNew & "<DetailgenauigkeitGeländer>"
    'MsgBox (oFileAssemblyNew)
    Set oDocAssem = ThisApplication.Documents.Open(oFileAssemblyNew, True)
    
    'Löschen von unterdrücken Bauteilen
    'Call RemoveSuppressed
    
    oFileElementNew = Left(oDocAssem.DisplayName, (Len(oDocAssem.DisplayName) - 32))
    MsgBox (oFileElementNew)
    
    oFileAssemblyNew = Left(oFileAssemblyNew, (Len(oFileAssemblyNew) - 42))
    MsgBox (oFileAssemblyNew)
    
    'oRefDocs (Auflistung aller Documents in der Baugruppe) = AllreferencedDocuments von TypDocumentsEnumerator
    Dim oRefDocs As DocumentsEnumerator
    'AllReferencedDocuments = ALLE enthaltenen Dateien
    Set oRefDocs = oDocAssem.AllReferencedDocuments
    
    'Bauteil als aktuelles Dokument setzen
    Dim oRefDoc As Document
        
    'Es sollen nur Zeichnungen berücksichtigt werden die im gleichen Pfad sind
    'also nur Fullfilename abzüglich der letzten 4 Zeichen gesetzt werden
    '(ohne Dateiendung wie .ipt oder .iam) im gleichen Zeichnungpfad.
    'Left = abschneiden des Linken Teil, Len = Ermittlung der Länge eines Strings.
    'Left (Hallo,2) = Ha.
    'oZeichPath = Left(oRefDoc.FullFileName, (Len(oRefDoc.FullFileName) - 4))
    'FileSystemobject zwecks Prüfung, ob die Zeichnung überhaupt als Datei auf der Festplatte existiert.
    'Siehe googel z.B. nach "VBA prüfen ob Datei existiert" oder sowas 🙂
    'Dim objFso As Object
    'Set objFso = CreateObject("Scripting.FileSystemObject")
    
    Dim oDocRef As Document
    Set oDocRef = ThisApplication.ActiveDocument
    Dim oRefFile As FileDescriptor
    Dim oOrigRefName, oOrigFullFileName, selectedfile As String

    For Each oRefFile In oDocAssem.File.ReferencedFileDescriptors
        'setzen des vollständigen Dateipfades
        oOrigFullFileName = oRefFile.FullFileName
        'MsgBox (oOrigFullFileName)
        'oOrigRefName = oRefDoc.DisplayName
        oOrigRefName = Right(oRefFile.FullFileName, (Len(oRefFile.FullFileName) - 44))
        MsgBox (oOrigRefName)
       
        'oFileElementNew = Left(oDocAssem.DisplayName, (Len(oDocAssem.DisplayName) - 32))
        'Setzen von Objekt Variabeln für Dateiauswahldialog
        Dim oFileDlg As Inventor.FileDialog
        Set oFileDlg = Nothing
        Call ThisApplication.CreateFileDialog(oFileDlg)
        oFileDlg.InitialDirectory = oOrigRefName
        oFileDlg.CancelError = True
        On Error Resume Next
        
        'Legende:
        '_001 = Knieleiste
        '_002 = AnschraubplatteMitte
        '_003 = Pfosten
        '_004 = Fussleiste
        '_005 = AnschraubplattePfosten
        '_006 = Handlauf
        If oOrigRefName = "AnschraubplatteMitte.ipt" Then
            selectedfile = oFileAssemblyNew & "\" & oFileElementNew & "_001.ipt"
            Debug.Print selectedfile
        ElseIf oOrigRefName = "Knieleiste.ipt" Then
            selectedfile = oFileAssemblyNew & "\" & oFileElementNew & "_002.ipt"
            Debug.Print selectedfile
        ElseIf oOrigRefName = "Pfosten.ipt" Then
            selectedfile = oFileAssemblyNew & "\" & oFileElementNew & "_003.ipt"
            Debug.Print selectedfile
        ElseIf oOrigRefName = "Fussleiste.ipt" Then
            selectedfile = oFileAssemblyNew & "\" & oFileElementNew & "_004.ipt"
            'Debug.Print selectedfile
        ElseIf oOrigRefName = "AnschraubplattePfosten.ipt" Then
            selectedfile = oFileAssemblyNew & "\" & oFileElementNew & "_005.ipt"
            'Debug.Print selectedfile
        ElseIf oOrigRefName = "Handlauf.ipt" Then
            selectedfile = oFileAssemblyNew & "\" & oFileElementNew & "_006.ipt"
            'Debug.Print selectedfile
        End If
       
        If Err.Number <> 0 Then
            Return
        'ElseIf oFileDlg.Filename <> "" Then
        ElseIf oOrigRefName.Filename <> "" Then
            selectedfile = oFileElementNew.Filename
            selectedfile = oDocElement.Filename
            MsgBox (selectedfile)
        End If
        
        'Modell-Referenz ersetzen
        oRefFile.ReplaceReference (selectedfile)
        oOrigFullFileName = ""
        oDocAssem.Update
        
    Next
    
    'Löschen von unterdrücken Bauteilen
    'Call RemoveSuppressed
    Call oDocAssem.SaveAs(oDocAssem.FullFileName, True)
    Call oDocAssem.Close(True)
    'iLogicVb.UpdateWhenDone = True

End Function

 

As soon as I run the function ReplaceReference clean I would put the complete source code here in the forum. ReplaceReference is only a part, but an important part of the iLogic railing.

 

Greetings and thanks

Matthias

1,089 Views
5 Replies
Replies (5)
Message 2 of 6

MjDeck
Autodesk
Autodesk

Hi Mathias,

I'm testing in Inventor 2019. Please let me know which version you're running.

I found that even if a component is suppressed, it can be replaced by using FileDescriptor.ReplaceReference. When you unsuppress the component, you will see the replacement file.
I don't understand this phrase:

> even if negative pressures have been previously deleted?

Can you express that using different words?


Mike Deck
Software Developer
Autodesk, Inc.

Message 3 of 6

JaneFan
Autodesk
Autodesk

Hi @mrichstein

 

Do you want the suppressed components be replaced or not? It seems a little bit unclear to me. 

If you want the suppressed components be replaced, the code should work. But if not, there is something wrong in the code for the collection of oDocAssem.File.ReferencedFileDescriptors returns all files related in the document no matter whether the component being suppressed or not. 




Jane Fan
Inventor/Fusion QA Engineer
Message 4 of 6

mrichstein
Enthusiast
Enthusiast

Hey Mike,

thanks for your quick answer.

Here my answer in red to you question and info's.

 

I'm testing in Inventor 2019. Please let me know which version you're running.

I'm working with Inventor 2018.

I found that even if a component is suppressed, it can be replaced by using FileDescriptor.ReplaceReference:

First I start the rule to delete all suppressed components. Then I call ReplaceReference(). But was there before only one suppressed components the ReplaceReference read over the component. If there are no supressed component the ReplaceReference it's works.

But where so you use the FileDescriptor.ReplaceReference?

When you unsuppress the component, you will see the replacement file.

If I delete the supressed components, I don't see the replacement file.

I don't understand this phrase:  > even if negative pressures have been previously deleted?

Sorry, wrong typing of me. It's means and correct... "...even if they have been deleted before."

I in the attachment you will see the completly Rule of at all and the 3D-Model of rail.

 

It's will help me if you see the fault or we say here in germany > "I do not see the forrest for the trees."

Thanks and greetings

Matthias

 

 

0 Likes
Message 5 of 6

mrichstein
Enthusiast
Enthusiast

Hey Jane,

thanks for quick answer.

Before I replace, I delete all suppressed components and then I start the rule of ReplaceReference().

Next I do not unserstand:

If you want the suppressed components be replaced, the code should work.

Yes but only not supressed components, because I have deleted all suppressed components before.

If all existing and equal components are not suppressed, it works. But if only one of the existing and equal component is suppressed, it does not work.

And here I think oDocAssem.File.ReferencedFileDescriptors it's could be work and I am with you ReferencedFileDescriptors must return all file related.

I do not see the fault in the completly rule of ReplaceReference.

Thanks and Greetings

Matthias

0 Likes
Message 6 of 6

MjDeck
Autodesk
Autodesk

Hi Matthias,

It sounds like this is the problem you're describing:
- there is only one occurrence of DocumentA in the assembly. That component occurrence is named ComponentA.
- ComponentA is suppressed.
- ComponentA is deleted by the RemoveSuppressed function.

 

Since ComponentA is the only reference to DocumentA, when that occurrence is deleted then DocumentA is no longer referenced by the assembly. The assembly doesn't know about that document any more. It doesn't appear in the ReferencedDocuments or ReferencedFileDescriptors.

I'm not sure why you want to do a SaveAs on a document that is no longer used in the assembly.

 


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes