Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Replacing multiple file references in a single .idw using iLogic?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
LOONYLEN
708 Views, 2 Replies

Replacing multiple file references in a single .idw using iLogic?

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

 

Senior Designer/Cad Administrator
Inventor 2012, w/SP2
Vault Collaboration 2012
Dell Precision T3500, Intel Xeon CPU
W3680 @3.33GHz, 16.0 GB of RAM
Microsoft Windows 7 Pro, 64 Bit Edition
Version 2009, w/SP1
2 REPLIES 2
Message 2 of 3
adam.nagy
in reply to: LOONYLEN

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 Nagy
Autodesk Platform Services
Message 3 of 3
LOONYLEN
in reply to: adam.nagy

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

 

Senior Designer/Cad Administrator
Inventor 2012, w/SP2
Vault Collaboration 2012
Dell Precision T3500, Intel Xeon CPU
W3680 @3.33GHz, 16.0 GB of RAM
Microsoft Windows 7 Pro, 64 Bit Edition
Version 2009, w/SP1

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report