Sie sind auf Seite 1von 5

'http://inventortrenches.blogspot.

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,

'the Revision Number, as found in the destination path,


'and the file extension from the original file being indexed
strNewFile = strDDir & "\" & strNewPN & " " & strNewRev & st
rExt
'copy the file, using the source directory & the original curren
tly indexed file,
'to the new file name
FileCopy (strSDir & strOrigFiles, strNewFile)
'set a message in Inventor's status bar
ThisApplication.StatusBarText = "Still Working"
End If
'call Dir again (looking at the source directory still) without any argu
ments
'this returns the next file in the same directory
strOrigFiles = Dir()
' re-index the file extension for the next file
strExt = LCase(System.IO.Path.GetExtension(strOrigFiles))
Loop
'- - - - now the code will look at the destination folder
'look at the destination directory for the new copied file names
Dim strCopiedFileName As String = Dir(strDDir & "\")
msgQuestion1 = MessageBox.Show("Change Description?" & vbLf & _
"If copying a design, select yes," & vbLf & _
"If rolling a revision, select no.", _
"Description - " & strPN & " " & strNewRev,MessageBoxButtons.YesNo)
If msgQuestion1 = vbYes Then
oDesc = InputBox("Enter Description.", _
"Description - " & strNewPN & " " & strNewRev,"")
Else
oDesc = ""
End If
Dim invDoc As Document
'loop through the files in the destination directory until all have been indexed
Do Until strCopiedFileName = ""
'get the file extension for the current indexed file
strExt = System.IO.Path.GetExtension(strCopiedFileName)
'check to see if the file has an Inventor file extension
If strExt <> ".iam" _
And strExt <> ".ipt" _
And strExt <> ".idw" _
And strExt <> ".dwg" _
And strExt <> ".ipn" Then
'do nothing if the file does not have an inventor extension
Else
'set the indexed file path, using the user supplied destination director
y,
'the Part Number, as found in the destination path,
'the Revision Number, as found in the destination path,
'and the file extension from the original file being indexed

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

invDTProperties.Item("Part Number").Value = strNewPN


'set the description if its a copied design, if it's a new revis
ion keep the description
If oDesc = "" Then
invDTProperties.Item("Description").Value = invDTProperties.Item
("Description").Value
Else
invDTProperties.Item("Description").Value = oDesc
End If
'set the Designer using the Application Options User Name
invDTProperties.Item("Designer").Value = ThisApplication.GeneralOptions.
UserName
'set the creation time/date to the current date
invDTProperties.Item("Creation Time").Value = Now()
'save the file
invDoc.Save
'close the file
invDoc.Close
End If
'reset the following items for the next file in the folder
invDoc = Nothing
strCopiedFileName = Dir()
'strExt = System.IO.Path.GetExtension(strCopiedFileName)
Loop
'set a message in the status bar
ThisApplication.StatusBarText = "Finished"
'tell the user the files were created
MessageBox.Show("New Files Created in " & strDDir, "iLogic")
'open the folder where the new folders are saved
Shell("explorer.exe " & strDDir,vbNormalFocus)

Das könnte Ihnen auch gefallen