Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Anonymous
432 Views, 4 Replies

Issue with Save As(False) changing origional files...

I'm essentially performing a copy design on on an assembly by going through all the occurences, and copying them using the SaveAs command in ilogic. It is working well except for when i have the same part in 2 different assemblies. It will copy the first, and all the parts in it. This also does the parts in the second assembly, before it does a save as of that. The end result is it copies everything fine, However, when i come to open the original second assembly, it has the new copied parts in it.

I have not told inventor to save this file. I have also tried copying the assemblies first, and the parts second, but this also doesn;t seem to work. 

Does anyone have any ideas how i can get around this problem? I somehow need to refresh the file from vault, but it doesn;t even know it's changed, so i have to delete it, and get it again... but i cant do that with ilogic because it's read only!

 

Im looping through all my occurences with this sub

 

 SaveAsComponentAndDrawing(oOcc As ComponentOccurrence, TemplateFolder As String)
	
	i = i+1		
	oProgressBar.Message = ("Performing Copy Design on Part " & i & " of " & iStepCount & vbCrLf & oOcc.Name) '...and increase the progress bar scale
	oProgressBar.UpdateProgress

	'full file name with extension
	CurrentFullFilename = oOcc.ReferencedFileDescriptor.FullFileName
	'file name without extension
	CurrentFilename = TemplateFolder  & IO.Path.GetFileNameWithoutExtension(CurrentFullFilename)
	'file extension only
	oExtension = CurrentFullFilename.Substring(CurrentFullFilename.Length - 4)

	CheckIfDrawingExists(CurrentFilename)

	oNewFileName = ReturnNewFileName(oOcc)
	
	oNewDrawingName = oNewFileName.Substring(0,oNewFileName.Length - 4) & ".dwg"
	'True opens visible, False opens invisible
	ooDoc = ThisApplication.Documents.Open(CurrentFullFilename, True) ' opens ipt file
	'set part number
	ooDoc.PropertySets("Design Tracking Properties").Item("Part Number").Value = IO.Path.GetFileNameWithoutExtension(oNewFileName)
	
	ooDoc.SaveAs(oNewFileName, False) ' false means open new file
	'ooDoc.Update()
	ooDoc.Close 

	'Open the current drawing (In same folder location)
	Dim DrawingDoc As DrawingDocument = ThisApplication.Documents.Open(CurrentFilename & ".dwg",True)
		'Perform 'Save As' on the drawing
	DrawingDoc.SaveAs(oNewDrawingName, False) ' false means open new file
	'Replace reference to assembly model
	Dim oFD As FileDescriptor
	oFD = DrawingDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
	oFD.ReplaceReference(oNewFileName)
	DrawingDoc.Update()
	Try
		DrawingDoc.Parameters.Item("i").Value = 1
	Catch
	End Try
	DrawingDoc.Update
	DrawingDoc.Save
	DrawingDoc.Close
	'ooDoc.Close
	
	ComponentArray.Add(oNewName & oExtension)
				
		For Each subOcc As ComponentOccurrence In oOcc.SubOccurrences
						
			If subOcc.Name.Contains(TemplateCode) 
				SaveAsComponentAndDrawing(subOcc, TemplateFolder)
			End If
						
		Next
	
End Sub