I want to change part name and idw name at the same time. Ican change it now, but references do not occur in changed files. I have atached the video of the situation.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Inventor;
using System.Runtime.InteropServices;
namespace Barida_Power_Tools.Classes
{
public partial class SelectedRename
{
private Inventor.Application Application { get; set; }
public static void GetSelection()
{
Inventor.Application inventorApp21;
inventorApp21 = (Application)Marshal.GetActiveObject("Inventor.Application");
var SelectedComOcc = inventorApp21.ActiveDocument.SelectSet[1] as ComponentOccurrence;
string oldFilename = SelectedComOcc.ReferencedFileDescriptor.FullFileName;
FileManager fileManager = inventorApp21.FileManager;
//Create new File new file name
string newFile = oldFilename.Substring(0, oldFilename.Length - 4) + "_new.ipt";
string Oldidw = oldFilename.Substring(0, oldFilename.Length - 4) + ".idw";
string newidw = Oldidw.Substring(0, Oldidw.Length - 4) + "_new.idw";
try
{
fileManager.CopyFile(oldFilename, newFile);
fileManager.CopyFile(Oldidw, newidw);
}
catch { };
Document idwDoc = inventorApp21.Documents.Open(Oldidw, false);
var drawingDoc = idwDoc as DrawingDocument;
PartDocument c = inventorApp21.Documents.Open(newFile, false) as PartDocument;
foreach (Sheet sheet in drawingDoc.Sheets)
{
foreach (DrawingView drawingView in sheet.DrawingViews)
{
var b = drawingView.ReferencedDocumentDescriptor.ReferencedDocument as PartDocument;
b = c;
}
}
SelectedComOcc.ReferencedDocumentDescriptor.ReferencedFileDescriptor.ReplaceReference(newFile);
fileManager.DeleteFile(oldFilename);
}
}
}
Solved! Go to Solution.
Solved by A.Acheson. Go to Solution.
Sorry about my reccord. it didnt catch dropdown and file dialogs. so it seems like work good but actualy didn't. Ipicked the referance file with openfiledialog at the end. But it didnt seen on reccord.
It would be better to save as the part document from within the assembly then occurrence.replace the part, save as the drawing and then file reference replace the part in the drawing. Copying the file in windows is not the correct route to go.
Can't find what you're looking for? Ask the community or share your knowledge.