iLogic - Replace model doesnt work after run rule

iLogic - Replace model doesnt work after run rule

ChristianAndersenIsmyname
Advocate Advocate
623 Views
3 Replies
Message 1 of 4

iLogic - Replace model doesnt work after run rule

ChristianAndersenIsmyname
Advocate
Advocate

Hello.

 

I've had this headscratcher for a while now, and I could need some help with this one.

 

I have a code that open part from drawing, and save that part as a copied part.

While this works great, doing this replaces the model reference in drawing to my newly made part. Because of this I also try to replace model back to the original in the same code, but for some reason this doesnt work.

 

Note: If I try to manually replace model reference, nothing happens.

I've tried to run this simple code both within the rule, and as a seperate rule, but nothing works. I basically have to close .idw and reopen without saving.

In the code below, I've changed the "c:\New Part" to the static path of the referenced part. This is just for testing, and should be a floating string depending on what part is referenced in the drawing, when the problem is fixed.

 

I hope someone could try to figure out why this happens, and hopefully I can learn something too.

 

Thanks!

 

Dim CurrentName As String
CurrentName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)
Dim oExtension As String
oExtension =
iProperties.Value(IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName), "Summary", "Category")

If oExension = PART Then
	oExtension = ".ipt"

Else If oExtension = ASSEMBLY Then
	oExtension = ".iam"
End If

Dim oFolder As String
Dim oLegacyFolder As String
oFolder = "K:\04. R&D\3D MODELING\KMG-MASTER"
oLegacyFolder = "K:\04. R&D\3D MODELING\KMG-MASTER\Legacy files"
Dim CurrentPart As String
CurrentPart = oFolder & "\" & ThisDoc.FileName(False) & oExtension

Dim LegacyName As String
LegacyName = oLegacyFolder & "\LEGACY " & iProperties.Value(IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName), "Project", "Part Number") & "-" & iProperties.Value("Project", "Revision Number") & " " & iProperties.Value(IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName),"Project", "Description") & oExtension

'---- check for file



If System.IO.File.Exists(LegacyName) Then
MessageBox.Show(LegacyName & vbLf & vbLf & "Already exist.","Warning!")
GoTo abort
Else
If System.IO.File.Exists(CurrentPart) Then
	
oPart = ThisApplication.Documents.Open(CurrentPart)
oPart.SaveAs(LegacyName,False)
oPart.Close
doc = ThisDoc.Document
Dim oFD As FileDescriptor
oFD = doc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
oFD.ReplaceReference("K:\04. R&D\3D MODELING\KMG-MASTER\N-51024 FITTING TOOL Ø220.ipt")
doc.Update()

'Dim oFile As System.IO.FileInfo 
'oFile = New System.IO.FileInfo(LegacyName)
'oFile.IsReadOnly = True

Else
MessageBox.Show(CurrentName & vbLf & vbLf & "Can't find this file!","Warning!")
GoTo abort

'---- Legacy file created
MessageBox.Show("Legacy file created!","Success!")
abort:
End If
End If

 

0 Likes
Accepted solutions (1)
624 Views
3 Replies
Replies (3)
Message 2 of 4

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @ChristianAndersenIsmyname 

It seems like you don't want to replace the reference in the first place? The SaveAs takes an argument "SaveCopyAs" that you have set to false. If you set it to true instead you'll save a copy without replacing the reference 🙂

Message 3 of 4

ChristianAndersenIsmyname
Advocate
Advocate

Thank you! It's "always" a simple solution.

 

Do you know why I couldn't change it back to original manually or with code?

0 Likes
Message 4 of 4

JhoelForshav
Mentor
Mentor

@ChristianAndersenIsmyname wrote:

Do you know why I couldn't change it back to original manually or with code?


Not at the top of my head... My best guess would be that the file is dirty as a result of the first reference replacement, and needs to be updated and saved before you can change again maybe? 🙂