Replace Model Reference unable to update

Replace Model Reference unable to update

will_roe
Enthusiast Enthusiast
1,084 Views
4 Replies
Message 1 of 5

Replace Model Reference unable to update

will_roe
Enthusiast
Enthusiast

Hi,

 

I'm trying to get some code to work to make a workflow as easy as possible for non inventor users using a design calculator.

 

Current workflow (we use vault but are avoiding it in this scenario)

Copy .ipt and .idw from master folder into new folder

Rename files to the same unique filenames

open .ipt

once inputs are complete click button that runs the below rule-

'opens drawing with same filename

Try
 oIDW = ThisDoc.FileName(False) & ".idw"
 ThisDoc.Launch(oIDW)
Catch
 MessageBox.Show("No Drawing Found", "Title")
End Try

Drawing opens

below rule triggers on open

'replaces model reference with same file name but with .ipt

oDoc = ThisDoc.Document

oFilepathext = ThisDoc.ChangeExtension(".ipt")

Dim oFD As FileDescriptor
oFD = oDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
oFD.ReplaceReference(oFilepathext)
InventorVb.DocumentUpdate()

 The model reference shows correctly in "Replace Model Reference" but the view doesn't update.

 

The sheet has the lightning bolt like it needs updating but it won't let me update anywhere (I've also tried getting to update with a ilogic rule)

 

will_roe_1-1631687409140.png

 

If I save and close it and reopen it fixes the link but this is a step I want to avoid.

 

Any help appreciated.

0 Likes
Accepted solutions (2)
1,085 Views
4 Replies
Replies (4)
Message 2 of 5

CattabianiI
Collaborator
Collaborator

Have you tried Sheet.Update?

oDoc.Sheets.Item(1).Update()


I think it has the same behaviour of

InventorVb.DocumentUpdate()

but could please give a try to oDoc.Update()

oDoc.Update()

 

0 Likes
Message 3 of 5

will_roe
Enthusiast
Enthusiast

Hadn't tried it but, it didn't work ☹️

0 Likes
Message 4 of 5

A.Acheson
Mentor
Mentor
Accepted solution

You will need to change the initial workflow in windows. Once you lose a reference only a manual linking will re-establish this. 

 

What works:

Copy both files and rename then open the new drawing. Run the replace reference rule and your done. Delete the old files then if you need. You can set this all to be done in the rule if you want.

 

Windows renaming is not best practice unless you know what will fail etc, so to reduce the error put all the copy/save as/rename work/replace reference in the rule. The drawing in this case is the top level so renaming that is fine where as the part is referenced internally in the drawing so renaming the part breaks the link. 

Drawing:

What is happening:

Internal information stored (part I am referencing is test1) After a rename of the part it goes to look for the reference and has no knowledge of the rename and will not find the file. The rule will not work until the original links are established 

 

AAcheson_0-1631722142478.png

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 5

will_roe
Enthusiast
Enthusiast
Accepted solution

So I'm not sure why but moving the rule to an external rule and triggering it with a rule has seemed to fix the problem.

 

iLogicVb.RunExternalRule("REPLACE MODEL REF WITH SAME FILE NAME")
InventorVb.DocumentUpdate()
 

 

I also tried the below for the drawing open button but couldn't quite figure it out

 

'If the drawing open button hadn't been pressed before it will open the drawing, replace the reference save, close & reopen it. This worked when i did it manually.

Dim idwPathName = ThisDoc.ChangeExtension(".idw")        
Dim oDrawDoc As DrawingDocument 

If RESOLVED = False Then


	ThisApplication.Documents.Open(idwPathName, True)


	iLogicVb.RunExternalRule("REPLACE MODEL REF WITH SAME FILE NAME")
		oDrawDoc.Save
		oDrawDoc.Close()

RESOLVED = True

	ThisApplication.Documents.Open(idwPathName, True)

ElseIf RESOLVED = True Then
	
	ThisApplication.Documents.Open(idwPathName, True)

End If

 

0 Likes