Change model reference in a drawing rule. Why it doesn't work in Inv 2019?

Change model reference in a drawing rule. Why it doesn't work in Inv 2019?

mikhail_tsarev
Enthusiast Enthusiast
410 Views
4 Replies
Message 1 of 5

Change model reference in a drawing rule. Why it doesn't work in Inv 2019?

mikhail_tsarev
Enthusiast
Enthusiast

Hello!

I have a rule that perfectly works in 2017. But in Inventor 2019 it doesn't work and I can't understand why...

 

The rule changes model reference in a drawing to new model with the same name and located same folder as drawing document . This is very useful when you have to create drawings by copying existing documents.

 

Code:

odoc = ThisDoc.Document
Dim NF as String = ThisDoc.Path & "\" & ThisDoc.FileName(False)& ".ipt"
Dim oldFD As FileDescriptor
oldFD = odoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
oldFD.ReplaceReference(NF)

odoc.Update()
odoc.Save

Need help...

0 Likes
411 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Hello,

At the moment I can't test it on 2019; however please let me just make a note about two things on your code:

- As you are forcing the extension, it only works for .ipt references (if for some reason this drawing is for an iam, it will not work)

- Is the .idw read only? Don't know if you are using Autodesk Vault, but specially in that case, it may need a checkout

Later on, I will check it on 2019.

 

Hope it helps.

Message 3 of 5

mikhail_tsarev
Enthusiast
Enthusiast

Thank you for your response.

Yes, it's for .ipt only. And I don't use Vault.

Moreover, I noticed that the code still works! The problem was related to several specific files (however, I have not found what was the cause of this error).

0 Likes
Message 4 of 5

Sergio.D.Suárez
Mentor
Mentor
In 2018 its code works, try to find the file for which it does not work and if possible attach it to study the error. regards!

Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 5 of 5

Charlies_3D_T
Advocate
Advocate

@mikhail_tsarev 

 

Hello,

 

Try the rule below: 

 

oThisDoc = ThisDoc.Document
oThisFileName = ThisDoc.FileName(False) & ".ipt"
IPJ = ThisApplication.FileLocations.FileLocationsFile
IPJ_Folder_Location = Left(IPJ, Len(IPJ) - Len(IPJ_Name))

Dim Folder As New IO.DirectoryInfo(IPJ_Folder_Location)
Dim FileList As New List(Of String)
For Each File As IO.FileInfo In Folder.GetFiles(oThisFileName,IO.SearchOption.AllDirectories)
If File.FullName.Contains(oThisFileName) = True Then
FileList.Add(File.FullName)
NieuwFilePath = File.FullName
doc = ThisDoc.Document
'Change the Referenced File'
oFD = doc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
oFD.ReplaceReference(NieuwFilePath)

Else
MsgBox("the file " & oThisFileName & " not found in this project!")
End If

Next

iLogicVb.UpdateWhenDone = True
InventorVb.DocumentUpdate()

 

0 Likes