- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.