Does anyone know how to replace the reference of multiple .ipt's inside of a single .idw?
Background: I have a single drawing that has two very similar .ipt's (they are only different because of a feature or two).
The drawing may be named something like 485000.idw and the two .ipt's are 485000-001.ipt & 485000-002.ipt.
My company likes to keep these two models on the same drawing because of similar features.
I currently have a working code that is saving the drawing and replacing the reference file (485000-001.ipt) but, doesn't see or replace the other file (485000-002.ipt).
Can anyone modify or show me how to get the definition of the second .ipt?
Here is the code for the save .idw and replace the first .ipt that is currently working:
Sub SAVEDETAIL (ByVal TemplateDrawing As String, ByVal PLAINPN As String, ByVal PNWSUFFIX As String, ByVal PTASSYPN As String, ByVal filePath As String) DESTINATIONDOC = ThisApplication.DOCUMENTS.Open(TemplateDrawing, False) DESTINATIONDOC.SAVEAS(filePath & PLAINPN & ".idw", False) Dim STRNEWREFNAME As String Dim OREFFILE As FILEDESCRIPTOR For Each OREFFILE In DESTINATIONDOC.FILE.REFERENCEDFILEDESCRIPTORS Dim OORIGREFNAME As String OORIGREFNAME = OREFFILE.FULLFILENAME If OORIGREFNAME.EndsWith(".ipt") Then STRNEWREFNAME = filePath & PNWSUFFIX & ".ipt" OREFFILE.REPLACEREFERENCE(STRNEWREFNAME) ElseIf OORIGREFNAME.EndsWith(".iam") Then STRNEWREFNAME = filePath & PTASSYPN & ".iam" OREFFILE.REPLACEREFERENCE(STRNEWREFNAME) End If Exit For Next DESTINATIONDOC.Update() DESTINATIONDOC.Save DESTINATIONDOC.Close End Sub
Solved! Go to Solution.
Solved by LOONYLEN. Go to Solution.
Hi,
What parameters are you passing in to that function? - as an example.
Where are you copying the part files to the destination folder?
This does not change inside the For Each loop, so you'll replace both parts with the same part.
STRNEWREFNAME = filePath & PNWSUFFIX & ".ipt"
Cheers,
Adam,
Thanks for the reply and you are correct.
My part numbers end with -001.ipt and -002.ipt or -002.iam.
I think the issue was not specifing the difference between the -001.ipt & -002.ipt.
Also, the "Exit For" would not let the loop run again to catch the second .ipt if it was present.
I've corrected the code and posted it below for any other users facing this issue.
Thanks again for the reply,
Len
Sub SAVEDETAIL (ByVal TemplateDrawing As String, ByVal PLAINPN As String, ByVal PNWSUFFIX As String, ByVal PTASSYPN As String, ByVal filePath As String) DESTINATIONDOC = ThisApplication.DOCUMENTS.Open(TemplateDrawing, False) DESTINATIONDOC.SAVEAS(filePath & PLAINPN & ".idw", False) Dim STRNEWREFNAME As String Dim OREFFILE As FILEDESCRIPTOR For Each OREFFILE In DESTINATIONDOC.FILE.REFERENCEDFILEDESCRIPTORS Dim OORIGREFNAME As String OORIGREFNAME = OREFFILE.FULLFILENAME If OORIGREFNAME.EndsWith("-001.ipt") Then STRNEWREFNAME = filePath & PNWSUFFIX & ".ipt" OREFFILE.REPLACEREFERENCE(STRNEWREFNAME) ElseIf OORIGREFNAME.EndsWith("-002.ipt") Then STRNEWREFNAME = filePath & PTASSYPN & ".ipt" OREFFILE.REPLACEREFERENCE(STRNEWREFNAME) ElseIf OORIGREFNAME.EndsWith(".iam") Then STRNEWREFNAME = filePath & PTASSYPN & ".iam" OREFFILE.REPLACEREFERENCE(STRNEWREFNAME) End If Next DESTINATIONDOC.Update() DESTINATIONDOC.Save DESTINATIONDOC.Close End Sub