Inventor VBA Macro - Copying Parts/Drawings

Inventor VBA Macro - Copying Parts/Drawings

isocam
Collaborator Collaborator
224 Views
2 Replies
Message 1 of 3

Inventor VBA Macro - Copying Parts/Drawings

isocam
Collaborator
Collaborator

Can any body help?

 

Does anybody know if the following is possible using a Inventor VBA macro?

 

Say I have a Inventor part and drawing, called Part1.ipt & Part1.idw.

 

If I copy these two files into the same directory and call them Part2.ipt & Part2.idw, when I open the drawing Part2.idw it displays Part1.ipt

 

Is there any way I can, using a VBA macro, re-reference the part in Part2.idw so it references the correct part called Part2.ipt?

 

Hope you ca understand the above.

 

Many thanks in advance!

 

Darren  

0 Likes
225 Views
2 Replies
Replies (2)
Message 2 of 3

ryan.rittenhouse
Advocate
Advocate

There's a method to replace the referenced document in a drawing view, but you have to get to it in a slightly roundabout way. I have not had success going through the DrawingView to swap it. I have been able to drill down from the Drawing Document to find the Referenced Document Descriptor for the file I want to change and swap it out from there. Here's a code example:

 

'Many ways to get the current document. ThisApplication.ActiveDocument would also work
'If you in straight VB, GetObject(, "Inventor.Application").ActiveDocument will work
Dim drawDoc As DrawingDocument = ThisDrawing.Document
Dim newFileName As String = "C:\$WorkingFolder\Engineering Data\Part 1.ipt"
Dim oldFileName As String = "C:\$WorkingFolder\Engineering Data\Part 2.ipt"
Dim RFD As FileDescriptor = Nothing

'Loop through referenced documents in the drawing to find the correct one
For Each docDesc As DocumentDescriptor In drawDoc.ReferencedDocumentDescriptors
	'Verify document by file name
	If docDesc.ReferencedFileDescriptor.FullFileName = oldFileName Then
		RFD = docDesc.ReferencedFileDescriptor
		Exit For
	End If
Next docDesc

If RFD Is Nothing Then
	'Log if the file is not found
	Logger.Error("Old file not found")
Else
	'Replace file if found
	RFD.ReplaceReference(newFileName)
End If

 

Hope this helps.

If this solved your problem, or answered your question, please click Accept Solution.
0 Likes
Message 3 of 3

bradeneuropeArthur
Mentor
Mentor

For this I would recommend to use ilogic copy design found in the ribbon of zero documents when no files are opened.

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes