enhanced save as revision with ilogic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I use this tool and altered it for saving a revision.
What it does:
It takes the Custom iProperty Current Revision and adds 1.
Than it makes a save as with the new name
opens the corresponding drawing and makes a save as
and finally changes the model reference in the drawing.
Unfortunately there is some strange bug in the code. Sometimes it works sometimes it doesnt.
So for me its hard to find why this error occurs
Can anyone of you professionals take a look at the code and tell me what i need to alter?
Thank you
Sometimes my selfprogrammed codes are broken due to some changes in the ilogic syntax from one version of inventor to another. Could this be the case here? Where can i find the changelogs to fix such problems?
This is the genuine code
https://blogs.rand.com/manufacturing/2016/06/ilogic-inventor-enhanced-save-as.html
Here is my code:
SyntaxEditor Code Snippet
' Start of iLogic code ------------------------------------------------------------------------------------- ' Note this iLogic rule takes a copy of the active assembly and associated drawing file ' ...then associates the drawing with the newly copied assembly. ' This rule is a variation on a previous blog by Luke Davenport located here: ' https://www.cadlinecommunity.co.uk/hc/en-us/articles/203347701-Inventor-2016-iLogic-Copy-Assembly-Model-and-Drawing ' This rule allows any name to be input for the copied drawing and assembly, the code in the blog linked above ' ...allows only a suffix to be entered. ' Set drawing extension you are using here by commenting out as required. 'Dim DWGType As String = ".dwg" Dim DWGType As String = ".idw" Dim oDoc As AssemblyDocument = Nothing Try oDoc = ThisApplication.ActiveEditDocument Catch MsgBox("Dieses Programm wird in einer Assembly-Datei ausgeführt! - Exiting...", 64, "Revision Speichern") Return End Try ' Get current filename without extension Dim CurrentFilename As String = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullDocumentName) ' Get current path Dim Path As String = System.IO.Path.GetDirectoryName(oDoc.FullDocumentName) ' Check that the drawing for this assembly can be found If Not System.IO.File.Exists(System.IO.Path.ChangeExtension(oDoc.FullDocumentName, DWGType)) Then MsgBox("Es konnte keine Zeichnungsdatei gefunden werden die zu diesem Bauteil passt!" & vbLf & vbLf & _ CurrentFilename & DWGType & vbLf & vbLf & _ "Bitte stelle sicher das sich das File im gleichen Ordner befindet, den gleichen Namen hat und die richtige Dateierweiterung '" & DWGType & "'", 64, "Revision Speichern") Return End If 'Dim CurrRev As String = Mid(CurrentFilename, 8, 1) 'Gibt den aktuellen Revisionsstand anhand des Zeichnungsnamens wieder 'Dim CurrRev As String = iProperties.Value("Project", "Revision Number") 'Gibt den aktuellen Revisionsstand anhand des iProperties wieder Dim CurrRev As String = iProperties.Value("Project", "Revision Number") 'Gibt den aktuellen Revisionsstand anhand des iProperties wieder 'Dim NextRev As String = Chr(Asc(CurrRev) + 1) 'Stellt den aktuellen Revisionsstand als ASCII Code dar und addiert eins gibt bei A also B wieder Dim NextRev As Integer = CurrRev + 1 'Stellt den aktuellen Revisionsstand einen Wert nach oben Dim StrNextRev As String = Microsoft.VisualBasic.Strings.Format(NextRev,"0#") Dim NextRevFileName As String = iProperties.Value("Project", "Stock Number") & "-" & StrNextRev & "_" & iProperties.Value("Project", "Description") ' Prompt user for job number Dim NewFileName As String = InputBox("Es wird eine Kopie der Baugruppe und seiner 2D-Zeichnung unter neuem Namen erzeugt." & vbLf & vbLf & _ "Vorschlag für neuen Dateinamen anhand aktuellem Revisionsstand." & vbLf & vbLf & _ "Die aktuelle Assembly wird nicht geschlossen jedoch die Neue zusätzlich geöffnet..." & vbLf & vbLf & _ "Fortfahren?", "Revision Speichern - Baugruppe und Zeichnung Kopieren", NextRevFileName) If NewFileName = "" Then ' Cancel was hit Return End If Dim RevText As String = InputBox("Text für Revision " & StrNextRev & " eingeben.", "Was wurde geändert?", iProperties.Value("Custom", "Revision " & CurrRev)) ' Perform Save As of Assembly oDoc.SaveAs(Path & "\" & NewFileName & ".iam", False) Dim AssemblyDoc As AssemblyDocument = ThisApplication.Documents.Open(Path & "\" & CurrentFilename & ".iam") iProperties.Value("Project", "Revision Number") = StrNextRev iProperties.Value("Custom", "Revision " & StrNextRev) = RevText iProperties.Value("Custom", "Revision " & StrNextRev & " Datum") = Now 'aktuelles Datum oDoc.Activate() ' Open the current drawing (in same folder location) Dim DrawingDoc As DrawingDocument = ThisApplication.Documents.Open(Path & "\" & CurrentFilename & DWGType) ' Replace reference to assembly model Dim oFD As FileDescriptor oFD = DrawingDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor oFD.ReplaceReference(NewFileName & ".iam") DrawingDoc.Update() ' Perform 'Save As' on the drawing - change this to reflect your drawing type .dwg or .idw DrawingDoc.SaveAs(Path & "\" & NewFileName & ".idw", False) ' Make the assembly model active again... oDoc.Activate() ' End of iLogic code ---------------------------------------------------------------------------------------------