Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.