/// <summary> /// <inheritdoc cref="IPresentation.SaveAs"/> /// </summary> public void SaveAs(string filePath) { Check.NotEmpty(filePath, nameof(filePath)); _sdkPre = (PresentationDocument)_sdkPre.SaveAs(filePath); }
internal void MakeInvCopy(string templateAssemblyPath, string targetDirectory, OccurrenceList occurrenceList, UniqueModuleEvaluator uniqueModuleEvaluator) { // TODO Test for the existance of folders and assemblies. TemplateAssemblyPath = templateAssemblyPath; UniqueModules = uniqueModuleEvaluator; //Get the folder name that will be used to store the files associated with this Module. string folderName = GetModuleFolderPath(); //Need to get number of the parent occ, top level name as foldername ModulePath = System.IO.Path.Combine(targetDirectory, folderName); string topFileFullName = occurrenceList.TargetAssembly.FullDocumentName; string topFileNameOnly = System.IO.Path.GetFileName(topFileFullName); ModuleAssemblyPath = System.IO.Path.Combine(ModulePath, topFileNameOnly); //If this file already exists in the current location, for now we are //going to just skip the file creation, and assume it was previously done //correctly. Probably need to give the user the option to redo and //overwrite files if they want to. if (!System.IO.File.Exists(ModuleAssemblyPath)) { FilePathPair = new TupleList <string, string>(); for (int i = 0; i < occurrenceList.Items.Count; i++) { string targetOccPath = occurrenceList.Items[i].ReferencedFileDescriptor.FullFileName; string newCopyName = System.IO.Path.GetFileName(targetOccPath); string newFullCopyName = System.IO.Path.Combine(ModulePath, newCopyName); FilePathPair.Add(targetOccPath, newFullCopyName); } //Check if an earlier module already made the folder, if not, create it. if (!System.IO.Directory.Exists(ModulePath)) { //This property is needed later when placing occurrences of the assembly this Module instance //refers to. If FirstTime is false, we will want to have a slightly different strategry for constraint //placement. If FirstTime is true, all constraints are important and we need not relax them. If //FirstTime is false, then we need tolerance in the constraints because of double precision. When //FirstTime is false, we really just want to position the occurrence correctly, not drive its //geometry. if (FirstTime == null) { FirstTime = true; } System.IO.Directory.CreateDirectory(ModulePath); ReplaceReferences(occurrenceList.TargetAssembly, FilePathPair, ModulePath); AssemblyDocument oAssDoc = (AssemblyDocument)PersistenceManager.InventorApplication.Documents.Open(TemplateAssemblyPath, false); oAssDoc.SaveAs(ModuleAssemblyPath, true); oAssDoc.Close(true); //Need to copy presentation files if there are any. For now this is only going to work with the top assembly. string templateDirectory = System.IO.Path.GetDirectoryName(TemplateAssemblyPath); string[] presentationFiles = System.IO.Directory.GetFiles(templateDirectory, "*.ipn"); //If we want the ability to have subassemblies with .ipn files or multiple ones, this will have to be changed //to iterate over all the .ipn files. if (presentationFiles.Length != 0) { string newCopyPresName = System.IO.Path.GetFileName(presentationFiles[0]); string newFullCopyPresName = System.IO.Path.Combine(ModulePath, newCopyPresName); PresentationDocument presentationDocument = (PresentationDocument)PersistenceManager.InventorApplication.Documents.Open(presentationFiles[0], false); DocumentDescriptorsEnumerator presFileDescriptors = presentationDocument.ReferencedDocumentDescriptors; foreach (DocumentDescriptor refPresDocDescriptor in presFileDescriptors) { if (refPresDocDescriptor.FullDocumentName == TemplateAssemblyPath) { refPresDocDescriptor.ReferencedFileDescriptor.ReplaceReference(ModuleAssemblyPath); presentationDocument.SaveAs(newFullCopyPresName, true); presentationDocument.Close(true); } } } } else { FirstTime = false; } } }