Message 1 of 5

Not applicable
06-13-2019
01:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have a slight problem that I don’t understand as I am not a coder in the slightest.
I have modified Enhanced SaveAs ilogic to display a standard saveas dialog box by slicing together two lots of code.
The problem is I want to reset some iProperties in the drawing file before I save it to the new name. My code does not work when within the rest of the code but works in isolation when triggered manually. My code is an external rule.
Any help is greatly appreciated.
Here is the problem area that is not working;
'Reset Drawing creation date to today Dim oTime As String = Now.ToShortDateString iProperties.Value("Project", "Creation Date") = oTime 'Reset plot date stamp iProperties.Value("Custom", "Plotdatestamp") = "" iLogicVb.UpdateWhenDone = True DrawingDoc.Update()
Full code (sorry if its messy 🙂 );
' Start of iLogic code ------------------------------------------------------------------------------------- ' Note this iLogic rule takes a copy of the active part and associated drawing file ' ...then associates the drawing with the newly copied Part. ' 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 Part, 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 PartDocument = Nothing Try oDoc = ThisApplication.ActiveEditDocument Catch MsgBox("This rule must be run from the part document that you wish to copy! - Exiting...", 64, "Enhanced Save As") 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("Unable to locate the drawing file below for this assembly:" & vbLf & vbLf & _ CurrentFilename & DWGType & vbLf & vbLf & _ "Please make sure it's in the same folder as this assembly, has the same name, and has the file extension '" & DWGType & "'", 64, "Enhanced Save As") Return End If 'define the active document oDoc = ThisDoc.Document 'create a file dialog box Dim oFileDlg As Inventor.FileDialog = Nothing InventorVb.Application.CreateFileDialog(oFileDlg) 'check file type and set dialog filter If oDoc.DocumentType = kPartDocumentObject Then oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt" Else If oDoc.DocumentType = kAssemblyDocumentObject Then oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam" Else If oDoc.DocumentType = kDrawingDocumentObject Then oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw" End If 'set the directory to open the dialog at oFileDlg.InitialDirectory = ThisDoc.WorkspacePath() 'set the file name string to use in the input box oFileDlg.FileName = CurrentFilename 'work with an error created by the user backing out of the save Try oFileDlg.CancelError = True oFileDlg.ShowSave() Catch Return End Try 'catch an empty string in the imput If Err.Number <> 0 Then ElseIf oFileDlg.FileName <> "" Then MyFile = oFileDlg.FileName 'save the file oDoc.SaveAs(MyFile, False) 'True = Save As Copy & False = Save As End If iLogicVb.RunExternalRule("Clear Properties") iLogicVb.RunExternalRule("Extract_Properties") ' Prompt user for New Project Name Dim NewProjectName As String = InputBox("You are creating a new copy of this design and its 2D drawing file" & vbLf & vbLf & _ "Please input a new project name.", "New Project Name", "Enter New Project Name Here") If NewProjectName = "" Then ' Cancel was hit Return End If iProperties.Value("Project", "Project") = NewProjectName MyFile = ThisDoc.FileName(False) Dim PathNew As String = ThisDoc.Path ' Open the current drawing (in same folder location) Dim DrawingDoc As DrawingDocument = ThisApplication.Documents.Open(Path & "\" & CurrentFilename & DWGType) ' Replace reference to Part model Dim oFD As FileDescriptor oFD = DrawingDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor oFD.ReplaceReference(PathNew & "\" & MyFile & ".ipt") DrawingDoc.Update() 'Update drawing properties to model properties Dim oControlDef As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("UpdateCopiedModeliPropertiesCmd") oControlDef.Execute2(True) 'Reset Drawing creation date to today Dim oTime As String = Now.ToShortDateString iProperties.Value("Project", "Creation Date") = oTime 'Reset plot date stamp iProperties.Value("Custom", "Plotdatestamp") = "" iLogicVb.UpdateWhenDone = True DrawingDoc.Update() ' Perform 'Save As' on the drawing - change this to reflect your drawing type .dwg or .idw DrawingDoc.SaveAs(PathNew & "\" & MyFile & ".dwg", False) 'Close Drawing 'ThisApplication.ActiveDocument.Close(True) ' Make the Part model active again... oDoc.Activate() ' End of iLogic code ---------------------------------------------------------------------------------------------
Solved! Go to Solution.