Replace Reference mark the Assembly as Dirty

Replace Reference mark the Assembly as Dirty

jmacapagal2CD9H
Contributor Contributor
376 Views
2 Replies
Message 1 of 3

Replace Reference mark the Assembly as Dirty

jmacapagal2CD9H
Contributor
Contributor

My goal is to replace the reference of an Assembly without marking it as Dirty.I tried to use ReplaceReference alone but this modified my assembly. I just found out when the replace reference has been executed, it will trigger the OnFileResolution, from that, I tried to handle the callback to start using ChildFileDesc2  but still the assembly has been modified. 

 

The only posible way I can see to achieve that is, Close the Assembly and open it again, from that, the onFileResolution will be fired again and if I try to handle that and start using the ChildFileDesc2  instead of original reference(ChildFileDesc1), the assembly is not modified, but I can't use that on my current operation. If you have any trick to do that, please share it to my. Thank you.

 

Sample Code Below:

 

ChildFileDesc1 = "C:\workspace\Part1.ipt"

ChildFileDesc2 = "C:\workspace2\Part1.ipt" // This is a copy of ChildFileDesc1 but located on different folder

 

foreach (Inventor.FileDescriptor ChildFileDesc1 in This.Assembly.File.ReferencedFileDescriptors) 

{

if (ChildFileDesc1.FullFileName.Equals(ChildFileDesc2 .FullName) == false)

continue;

ChildFileDesc.ReplaceReference(ChildFileDesc2 .FullName);//This mark the assembly as dirty, also this will trigger the OnFileResolution callback.

}

//This will not modify the assembly

Callback: 

void OnFileResolution(string RelativeFileName, string LibraryName, ref byte[]

CustomLogicalName, EventTimingEnum BeforeOrAfter, NameValueMap Context, out string FullFileName, out HandlingCodeEnum HandlingCode)

{

FullFileName = ChildFileDesc2 ;

HandlingCode = HandlingCodeEnum.kEventHandled;

}

0 Likes
Accepted solutions (1)
377 Views
2 Replies
Replies (2)
Message 2 of 3

petr.meduna
Advocate
Advocate
Accepted solution

Hi,

you can set the property back to False.

ThisAssembly.Document.Dirty = False
0 Likes
Message 3 of 3

jmacapagal2CD9H
Contributor
Contributor

Ow great! I thought it was a read-only property. Thank you!

0 Likes