Copy model and drawing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have this iLogic application I copied and pasted together..
It seems to work great with a couple exceptions.
- If I have an assembly open that contains the part I am copying... it replaces it in the assembly... which sometimes that is great, but I would like to only copy the part or the assembly I start the iLogic copy in.
- The other issue is if a user selects a file and changes the name in the dialogue box... and keeps the file extension. it will add another file extension on... the the file name for example would be "part.ipt.ipt" which is not correct. I would like to be able to input either way... with file extension or without and it would add it like it does now.
- Also Id like the default location to be where the file is that I'm copying... instead of the last used.
does anyone have some advice or samples or best case... re-write the attached iLogic to do this?
Sub main
Dim oVault As ApplicationAddIn
For Each oVault In ThisApplication.ApplicationAddIns
If oVault.DisplayName = "Inventor Vault" Then Exit For
Next
If oVault IsNot Nothing Then oVault.Deactivate
SilentOperation = True
' Set drawing extension
Dim DWGType As String = ".dwg"
Dim BoxNote As String = "Drawing Automation"
opendoc = ThisDoc.PathAndFileName()
iFileName = ThisDoc.FileName(False)
oDoc = ThisDoc.Document
filePath = ThisDoc.Path
'MessageBox.Show(filePath)
Dim filex As String
'check file type and set dialog filter
If oDoc.DocumentType = kPartDocumentObject Then
'oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"
filex = ".ipt"
Else If oDoc.DocumentType = kAssemblyDocumentObject Then
'oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"
filex = ".iam"
Else If oDoc.DocumentType = kDrawingDocumentObject Then
'oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.dwg)|*.dwg"
filex = ".dwg"
End If
doc = ThisApplication.Documents.Open(opendoc & filex)
' Get current filename
CurrentFilename = ThisDoc.PathAndFileName(False)
oPart = ThisDoc.PathAndFileName(False)
' Check that the drawing for this assembly can be found
If Not System.IO.File.Exists(CurrentFilename & DWGType) Then
MessageBox.Show("Unable to locate the drawing file below for this part:" & vbLf & vbLf & _
CurrentFilename & DWGType & vbLf & vbLf & _
"Please make sure it's in the same folder as this part, has the same name, and has the file extension. '"& DWGType & "'", BoxNote)
Return
End If
RestartInput :
'define the active document
oDoc = ThisDoc.Document
'create a file dialog box
Dim oFileDlg As Inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
'set the directory to open the dialog at
oFileDlg.InitialDirectory = ThisDoc.Path()
'MessageBox.Show(ThisDoc.Path)
'set the file name string to use in the input box
oFileDlg.FileName = iFileName 'iProperties.Value("Project", "Part Number")
'work with an error created by the user backing out of the save
oFileDlg.CancelError = True
On Error GoTo 1:
'specify the file dialog as a save dialog (rather than a open dialog)
oFileDlg.ShowSave()
'work with an error created by the user backing out of the save
oFileDlg.CancelError = True
'On Error GoTo 1:'Resume Next
'catch an empty string in the imput
If Err.Number <> 0 Then
MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
ElseIf oFileDlg.FileName <> "" Then
MyFile = oFileDlg.FileName
End If
' Get new filename (without extension)
NewFileName = MyFile'filePath &"\"& FileName
' Perform Save As of Assembly
ThisDoc.Document.SaveAs(NewFileName & filex, False)
'update model iProperties
iNewFileName = ThisDoc.FileName(False)
oDoc.PropertySets("Design Tracking Properties").Item("Part Number").Value = iNewFileName
'
' Open the current drawing (in same folder location)
Dim DrawingDoc As DrawingDocument = ThisApplication.Documents.Open(CurrentFilename & DWGType)
' Replace reference to assembly model
Dim oFD As FileDescriptor
oFD = DrawingDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
oFD.ReplaceReference(NewFileName & filex)
DrawingDoc.Update()
DrawingDoc.Activate()
' Perform 'Save As' on the drawing
newdwgname=NewFileName & ".dwg"
DrawingDoc.SaveAs(newdwgname, False)
'ThisApplication.Documents.Open(oDWGPath, True)
Call Prop
1:
ThisDoc.Document.Activate
Call Prop
SilentOperation = False
oVault.Activate
End Sub
Public Sub Prop
oDoc = ThisApplication.ActiveDocument
iProperties.Value("Summary", "Author") = ThisApplication.GeneralOptions.UserName
iProperties.Value("Project", "Designer") = ThisApplication.GeneralOptions.UserName
iProperties.Value("Project", "Stock Number") = "=<Part Number>"
iProperties.Value("Project", "Creation Date" ) = Now
InventorVb.DocumentUpdate()
' Save the document and its dependents.
oDoc.Save2(True)
oDoc.Save2(True)
End Sub