Replacing Referenced Files Using VBA

Replacing Referenced Files Using VBA

Anonymous
Not applicable
1,435 Views
3 Replies
Message 1 of 4

Replacing Referenced Files Using VBA

Anonymous
Not applicable

I have a project where I need to automate the creation of .ipt, .idw and .iam files based off of a set of template files.  All was working extremely well until I had to handle an .iam file that had two references to the same .ipt file.  If the new .iam file still links to the same .ipt file twice then everything works fine.  If the new .iam file has to point to two different .ipt files I have a problem.  The code I originally used was:

 

Assem.File.ReferencedFileDescriptors(Index).ReplaceReference(NewFilePath)

 

where Assem is defined as AssemblyDocument.  Now, in order to just change a single reference I use:

 

Assem.ComponentDefinition.Occurrences(Index).Replace(NewFilePath, False) 'or True if all the references still need to be the same

 

The problem is that using the second method of replacement works, but it leaves a reference to the old .ipt file in the ReferencedFileDescriptors collection.  I need to know how to get rid of that reference, or if there's a different way I can replace single or mulitple instances of the same reference with one function call.  I hope I've explained this clearly enough.

 

Tom

0 Likes
1,436 Views
3 Replies
Replies (3)
Message 2 of 4

YuhanZhang
Autodesk
Autodesk

Hi Tom,

 

"The problem is that using the second method of replacement works, but it leaves a reference to the old .ipt file in the ReferencedFileDescriptors collection." Do you mean that the ComponentOccurrence.Replace(filename,False) will leave a reference to the old .ipt? Does the top assembly references to the same .ipt twice? If you only replace one of them then it will sure leave one reference.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 4

MechMachineMan
Advisor
Advisor
Have you tried using the first method again to replace the file reference?

The differece is that the first method actually accesses the file system to change the reference, where as the second method only accesses the assembly information for what document it calls.

The only reason I could see a reference being left behind is if it is still being used somewhere. (Linked parameters, adaptivity, different occurrence?).

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 4 of 4

Anonymous
Not applicable

@YuhanZhang wrote:

Hi Tom,

 

"The problem is that using the second method of replacement works, but it leaves a reference to the old .ipt file in the ReferencedFileDescriptors collection." Do you mean that the ComponentOccurrence.Replace(filename,False) will leave a reference to the old .ipt? Does the top assembly references to the same .ipt twice? If you only replace one of them then it will sure leave one reference.


Hi, this is Eric.  I actually posted the original message, but at the time I didn't have an account so I posted under Tom's.  Anyway, yes, and I would certainly expect that.  However, once I've replaced all references the original reference is still there.  Basically what I start with is an .iam file with two occurances of the the same .ipt file, so Occurrence.Count = 2 and ReferenceFileDescriptors.Count = 1.  If I replace both occurences with the same new .ipt file, which could happen, I get Occurence.Count = 2 and ReferenceFileDescriptors.Count = 2.  If I replace each occurrence with a different .ipt file, which could also happen, I end up with Occurrence.Count = 2 and ReferenceFileDescriptors.Count = 3.

0 Likes