Inventor iLogic - ReplaceReference()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.here 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