Beruflich Dokumente
Kultur Dokumente
com/2011/08/copy-design-and-revision-rolling-w
ith.html
'this code is set up to use the user provided path to define
'part number, revision number, and file name for the copied file
'this code expects a path such as N:\12-3456-78\Design Outputs\Rev 1
'where 12-3456-78 is the part number and folder that all files for that part num
ber reside in
'where Design Outputs is an intermediate folder
'where Rev 1 is the folder containing the files to be copied
'source directory
Dim strSDir As String
'get the source directory path (folder to copy file from) from the user
strSDir = InputBox("Enter path of files to copy", _
"iLogic Copy/Roll Revision", "",MessageBoxButtons.OKCancel) & "\"
'Cancel if input path is empty
If strSDir = "" & "\" Then
Return
Else
End If
'destination directory
Dim strDDir As String
'get the destination directory path (folder to copy file to) from the user
strDDir = InputBox("Enter New Part Number Folder Path" & vbLf & _
"Or enter the same path again to update" & vbLf & _
"the linked file references and iProperties" & vbLf & _
"for the files at that path", "iLogic", "")
If strSDir = strDDir & "\" Then
oAlert = MessageBox.Show("The paths you entered are the same." & vbLf & _
"This will update the linked file references and iproperties" & vbLf & _
"for the files in this folder." & vbLf & _
"Do you want to continue?", "iLogic",MessageBoxButtons.YesNo)
If oAlert = vbNo Then
Return
Else
On Error Resume Next
End If
End If
'Cancel if input path is empty
If strDDir = "" Then
Return
Else
End If
'if the destination directory does not exist, then create it
If(Not System.IO.Directory.Exists(strDDir )) Then
System.IO.Directory.CreateDirectory(strDDir )
End If
'defines backslash as the subdirectory separator
Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar
'set array for each folder name found between backslashes in the source director
y path
Dim oOrigPathItems() As Object = strSDir.Split(strCharSep)
'set array for each folder name found between backslashes in the destination dir
ectory path
Dim oNewPathItems() As Object = strDDir.Split(strCharSep)
'get the first level folder name to use as the original Part Number, expects a p
ath such as
'N:\12-3456-78\Design Outputs\Rev 1
'returns: 12-3456-78
Dim strPN As String = oOrigPathItems(1)
'get the first level folder name to use as the new Part Number, expects a path s
uch as
'N:\20-2000-20\Design Outputs\Rev 2
'returns: 20-2000-20
Dim strNewPN As String = oNewPathItems(1)
'get the second level folder name, expects a path such as
'N:\12-3456-78\Design Outputs\Rev 1
'return2: Design Outputs
'Dim strPN As String = oOrigPathItems(2)
'get the thrird level folder name to use as the Revision Number, expects a path
such as
'N:\12-3456-78\Design Outputs\Rev 2
'returns: Rev 2
Dim strNewRev As String = oNewPathItems(3)
'look at the source directory for the original file names
Dim strOrigFiles As String = Dir(strSDir)
Dim strNewFile As String 'new file name
Dim strExt As String 'File Extension
Dim strPNShort As String
'loop through the files in the source directory until all have been indexed
Do Until strOrigFiles = ""
'set a message in Inventor's status bar
ThisApplication.StatusBarText = "Please Wait"
'On error resume Next
'get the file extension for the current indexed file
strExt = LCase(System.IO.Path.GetExtension(strOrigFiles))
'check to see if the file extension is not one of these 5 Invent
or file extensions
If strExt <> ".ipt" _
And strExt <> ".iam" _
And strExt <> ".idw" _
And strExt <> ".dwg" _
And strExt <> ".ipn" Then
'do nothing
Else
'set the new file name, using the user supplied destination dire
ctory,
'the Part Number, as found in the destination path,
strNewFile = strDDir & "\" & strNewPN & " " & strNewRev & strExt
'open the indexed file, false opens the file without generating the grap
hics
invDoc = ThisApplication.Documents.Open(strNewFile, False)
'check to see if the indexed file is an Inventor drawing
If (invDoc.DocumentType = kDrawingDocumentObject) Then
'if the file is an Inventor drawing set a reference to it
Dim DrgDoc As DrawingDocument
DrgDoc = invDoc
'crack the file and reset the internal references
'all references are reset to the same new reference
Dim oRefFile As FileDescriptor
For Each oRefFile In DrgDoc.file.ReferencedFileDescriptors
'get the full file path to the original internal referen
ces
Dim oOrigRefName As Object
oOrigRefName = oRefFile.FullFileName
'get the original referenced file externsions
Dim strRefExt As String = System.IO.Path.GetExtension(oO
rigRefName)
'set the new internal reference path and name
'using the new file name and the original reference exte
nsion
Dim strNewRefName As String = Mid(strNewFile, 1, Len(str
NewFile)- 4) & strRefExt
'if the new file name string is empty do nothing
If (strDDir & "\" & strNewRefName) = "" Then 'do nothing
'otherwise replace the reference
Else oRefFile.ReplaceReference (strNewRefName)
End If
Next
Else
End If
'--------this section sets the iproperties for the new files ------'note: see http://www.autodesk.com/us/community/mfg/Part_4.pdf f
or list of all property sets
'define the iproperties summary property set
Dim invSUMProperties As PropertySet
invSUMProperties = invDoc.PropertySets.Item("Inventor Summary Informatio
n")
'define the iproperties design tracking property set
Dim invDTProperties As PropertySet
invDTProperties = invDoc.PropertySets.Item("Design Tracking Properties")
'set the revision number
invSUMProperties.Item("Revision Number").Value = Mid(strNewRev,5)
'set the author using the Application Options User Name
invSUMProperties.Item("Author").Value = ThisApplication.GeneralOptions.U
serName
'set the part number