<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Copy model and drawing. in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/copy-model-and-drawing/m-p/11505007#M144275</link>
    <description>&lt;P&gt;I have this iLogic application I copied and pasted together..&lt;/P&gt;&lt;P&gt;It seems to work great with a couple exceptions.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;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.&lt;/LI&gt;&lt;LI&gt;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.&lt;/LI&gt;&lt;LI&gt;Also Id like the default location to be where the file is that I'm copying... instead of the last used.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;does anyone have some advice or samples or best case... re-write the attached iLogic to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;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 &amp;amp; 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 &amp;amp; DWGType) Then
	MessageBox.Show("Unable to locate the drawing file below for this part:" &amp;amp; vbLf &amp;amp; vbLf &amp;amp; _
	CurrentFilename &amp;amp; DWGType &amp;amp; vbLf &amp;amp; vbLf &amp;amp; _
	"Please make sure it's in the same folder as this part, has the same name, and has the file extension. '"&amp;amp; DWGType  &amp;amp; "'", 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 &amp;lt;&amp;gt; 0 Then
MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
ElseIf oFileDlg.FileName &amp;lt;&amp;gt; "" Then
MyFile = oFileDlg.FileName
End If

' Get new filename (without extension)
NewFileName = MyFile'filePath &amp;amp;"\"&amp;amp; FileName 


' Perform Save As of Assembly
ThisDoc.Document.SaveAs(NewFileName &amp;amp; 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 &amp;amp; DWGType)

' Replace reference to assembly model
Dim oFD As FileDescriptor
oFD = DrawingDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
oFD.ReplaceReference(NewFileName &amp;amp; filex)
DrawingDoc.Update()
DrawingDoc.Activate()
' Perform 'Save As' on the drawing
newdwgname=NewFileName &amp;amp; ".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") = "=&amp;lt;Part Number&amp;gt;"
iProperties.Value("Project", "Creation Date" ) = Now

InventorVb.DocumentUpdate()

' Save the document and its dependents.
 oDoc.Save2(True)
	oDoc.Save2(True)
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Oct 2022 19:27:15 GMT</pubDate>
    <dc:creator>darrell.wcd</dc:creator>
    <dc:date>2022-10-24T19:27:15Z</dc:date>
    <item>
      <title>Copy model and drawing.</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/copy-model-and-drawing/m-p/11505007#M144275</link>
      <description>&lt;P&gt;I have this iLogic application I copied and pasted together..&lt;/P&gt;&lt;P&gt;It seems to work great with a couple exceptions.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;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.&lt;/LI&gt;&lt;LI&gt;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.&lt;/LI&gt;&lt;LI&gt;Also Id like the default location to be where the file is that I'm copying... instead of the last used.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;does anyone have some advice or samples or best case... re-write the attached iLogic to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;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 &amp;amp; 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 &amp;amp; DWGType) Then
	MessageBox.Show("Unable to locate the drawing file below for this part:" &amp;amp; vbLf &amp;amp; vbLf &amp;amp; _
	CurrentFilename &amp;amp; DWGType &amp;amp; vbLf &amp;amp; vbLf &amp;amp; _
	"Please make sure it's in the same folder as this part, has the same name, and has the file extension. '"&amp;amp; DWGType  &amp;amp; "'", 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 &amp;lt;&amp;gt; 0 Then
MessageBox.Show("No File Saved.", "iLogic: Dialog Canceled")
ElseIf oFileDlg.FileName &amp;lt;&amp;gt; "" Then
MyFile = oFileDlg.FileName
End If

' Get new filename (without extension)
NewFileName = MyFile'filePath &amp;amp;"\"&amp;amp; FileName 


' Perform Save As of Assembly
ThisDoc.Document.SaveAs(NewFileName &amp;amp; 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 &amp;amp; DWGType)

' Replace reference to assembly model
Dim oFD As FileDescriptor
oFD = DrawingDoc.ReferencedFileDescriptors(1).DocumentDescriptor.ReferencedFileDescriptor
oFD.ReplaceReference(NewFileName &amp;amp; filex)
DrawingDoc.Update()
DrawingDoc.Activate()
' Perform 'Save As' on the drawing
newdwgname=NewFileName &amp;amp; ".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") = "=&amp;lt;Part Number&amp;gt;"
iProperties.Value("Project", "Creation Date" ) = Now

InventorVb.DocumentUpdate()

' Save the document and its dependents.
 oDoc.Save2(True)
	oDoc.Save2(True)
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 19:27:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/copy-model-and-drawing/m-p/11505007#M144275</guid>
      <dc:creator>darrell.wcd</dc:creator>
      <dc:date>2022-10-24T19:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: Copy model and drawing.</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/copy-model-and-drawing/m-p/11879080#M151095</link>
      <description>&lt;P&gt;Thank you and others for your starting code. Here's an ilogic macro for copying the part and drawing together. Basically does the same thing as a copy design in Vault.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Change log:&lt;/P&gt;&lt;P&gt;1. Doesn't replace it in the assembly anymore.&lt;/P&gt;&lt;P&gt;2. Extension will be dropped if user puts in the extension as part of its name.&lt;/P&gt;&lt;P&gt;3. Workaround implemented to correctly show the initial folder&lt;/P&gt;&lt;P&gt;4. Commented out touching the vault addin. Undesirable behaviour for my application.&lt;/P&gt;&lt;P&gt;5. Close out background openings of files.&lt;/P&gt;&lt;P&gt;6. Changed filetype to idw instead of dwg for my purposes.&lt;/P&gt;&lt;P&gt;7. Commented out some iproperty stuff I didn't want for what I need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;'Adapted from darrell.wcd  at https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/copy-model-and-drawing/td-p/11505007&lt;/SPAN&gt;

&lt;SPAN&gt;Sub&lt;/SPAN&gt; &lt;SPAN&gt;main&lt;/SPAN&gt;
&lt;SPAN&gt;'	Dim oVault As ApplicationAddIn&lt;/SPAN&gt;
&lt;SPAN&gt;'	For Each oVault In ThisApplication.ApplicationAddIns&lt;/SPAN&gt;
&lt;SPAN&gt;'	If oVault.DisplayName = "Inventor Vault" Then Exit For&lt;/SPAN&gt;
&lt;SPAN&gt;'	Next&lt;/SPAN&gt;
&lt;SPAN&gt;'	If oVault IsNot Nothing Then oVault.Deactivate&lt;/SPAN&gt;
		
&lt;SPAN&gt;'SilentOperation = True&lt;/SPAN&gt;

&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;SPAN&gt;  Set drawing extension&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;DWGType&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt; = &lt;SPAN&gt;".idw"&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;BoxNote&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt; = &lt;SPAN&gt;"Drawing Automation"&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;filex&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt; &lt;SPAN&gt;'file extension&lt;/SPAN&gt;
&lt;SPAN&gt;opendoc&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;PathAndFileName&lt;/SPAN&gt;()

&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;SPAN&gt;  Initial file dialogue box declarations&lt;/SPAN&gt;
&lt;SPAN&gt;oDoc&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Document&lt;/SPAN&gt;
&lt;SPAN&gt;filePath&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Path&lt;/SPAN&gt;
&lt;SPAN&gt;'MessageBox.Show(filePath)&lt;/SPAN&gt;

&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;SPAN&gt; check file type and set dialog filter&lt;/SPAN&gt;
&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;DocumentType&lt;/SPAN&gt; = &lt;SPAN&gt;kPartDocumentObject&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
	&lt;SPAN&gt;'oFileDlg.Filter = "Autodesk Inventor Part Files (*.ipt)|*.ipt"&lt;/SPAN&gt;
	&lt;SPAN&gt;filex&lt;/SPAN&gt; = &lt;SPAN&gt;".ipt"&lt;/SPAN&gt;
&lt;SPAN&gt;Else&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;DocumentType&lt;/SPAN&gt; = &lt;SPAN&gt;kAssemblyDocumentObject&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
	&lt;SPAN&gt;'oFileDlg.Filter = "Autodesk Inventor Assembly Files (*.iam)|*.iam"&lt;/SPAN&gt;
	&lt;SPAN&gt;filex&lt;/SPAN&gt; = &lt;SPAN&gt;".iam"&lt;/SPAN&gt;
&lt;SPAN&gt;Else&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;DocumentType&lt;/SPAN&gt; = &lt;SPAN&gt;kDrawingDocumentObject&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
	&lt;SPAN&gt;'oFileDlg.Filter = "Autodesk Inventor Drawing Files (*.idw)|*.idw"&lt;/SPAN&gt;
	&lt;SPAN&gt;filex&lt;/SPAN&gt; = &lt;SPAN&gt;".idw"&lt;/SPAN&gt;
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;

&lt;SPAN&gt;'doc = ThisApplication.Documents.Open(opendoc &amp;amp; filex,True)	&lt;/SPAN&gt;
	
&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;SPAN&gt; Get current filename&lt;/SPAN&gt;
&lt;SPAN&gt;CurrentFilename&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;PathAndFileName&lt;/SPAN&gt;(&lt;SPAN&gt;False&lt;/SPAN&gt;) 
&lt;SPAN&gt;oPart&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;PathAndFileName&lt;/SPAN&gt;(&lt;SPAN&gt;False&lt;/SPAN&gt;)

&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;SPAN&gt;  Check that the drawing for this assembly can be found&lt;/SPAN&gt;
&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;Not&lt;/SPAN&gt; &lt;SPAN&gt;System&lt;/SPAN&gt;.&lt;SPAN&gt;IO&lt;/SPAN&gt;.&lt;SPAN&gt;File&lt;/SPAN&gt;.&lt;SPAN&gt;Exists&lt;/SPAN&gt;(&lt;SPAN&gt;CurrentFilename&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;DWGType&lt;/SPAN&gt;) &lt;SPAN&gt;Then&lt;/SPAN&gt;
	&lt;SPAN&gt;MessageBox&lt;/SPAN&gt;.&lt;SPAN&gt;Show&lt;/SPAN&gt;(&lt;SPAN&gt;"Unable to locate the drawing file below for this part:"&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;vbLf&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;vbLf&lt;/SPAN&gt; &amp;amp; _
		&lt;SPAN&gt;CurrentFilename&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;DWGType&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;vbLf&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;vbLf&lt;/SPAN&gt; &amp;amp; _
		&lt;SPAN&gt;"Please make sure it's in the same folder as this part, has the same name, and has the file extension. '"&lt;/SPAN&gt;&amp;amp; &lt;SPAN&gt;DWGType&lt;/SPAN&gt;  &amp;amp; &lt;SPAN&gt;"'"&lt;/SPAN&gt;, &lt;SPAN&gt;BoxNote&lt;/SPAN&gt;)
	&lt;SPAN&gt;Return&lt;/SPAN&gt;
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;

&lt;SPAN&gt;'define the active document&lt;/SPAN&gt;
&lt;SPAN&gt;oDoc&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Document&lt;/SPAN&gt;

&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;SPAN&gt; create a file dialog box&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oFileDlg&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Inventor&lt;/SPAN&gt;.&lt;SPAN&gt;FileDialog&lt;/SPAN&gt; = &lt;SPAN&gt;Nothing&lt;/SPAN&gt;
&lt;SPAN&gt;InventorVb&lt;/SPAN&gt;.&lt;SPAN&gt;Application&lt;/SPAN&gt;.&lt;SPAN&gt;CreateFileDialog&lt;/SPAN&gt;(&lt;SPAN&gt;oFileDlg&lt;/SPAN&gt;)
&lt;SPAN&gt;oFileDlg&lt;/SPAN&gt;.&lt;SPAN&gt;InitialDirectory&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Path&lt;/SPAN&gt;() &lt;SPAN&gt;' Bug since Sept 2021 causes this line to be ignored at the .ShowAs() line&lt;/SPAN&gt;
&lt;SPAN&gt;'Work Around for ShowSave() bug. Thank you ThaleFUWKH (https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/file-dialog-initial-directory-stuck-on-workspace/m-p/6883307#M70261)&lt;/SPAN&gt;
&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;iFileName&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Path&lt;/SPAN&gt;() + &lt;SPAN&gt;"\"&lt;/SPAN&gt; + &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;FileName&lt;/SPAN&gt;(&lt;SPAN&gt;False&lt;/SPAN&gt;)

&lt;SPAN&gt;'set the file name string to use in the input box&lt;/SPAN&gt;
&lt;SPAN&gt;oFileDlg&lt;/SPAN&gt;.&lt;SPAN&gt;FileName&lt;/SPAN&gt; = &lt;SPAN&gt;iFileName&lt;/SPAN&gt; &lt;SPAN&gt;'iProperties.Value("Project", "Part Number")&lt;/SPAN&gt;
&lt;SPAN&gt;'work with an error created by the user backing out of the save&lt;/SPAN&gt;
&lt;SPAN&gt;oFileDlg&lt;/SPAN&gt;.&lt;SPAN&gt;CancelError&lt;/SPAN&gt; = &lt;SPAN&gt;True&lt;/SPAN&gt;
&lt;SPAN&gt;Logger&lt;/SPAN&gt;.&lt;SPAN&gt;Debug&lt;/SPAN&gt;(&lt;SPAN&gt;"oFileDlg.FileName "&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;oFileDlg&lt;/SPAN&gt;.&lt;SPAN&gt;FileName&lt;/SPAN&gt;)

&lt;SPAN&gt;On&lt;/SPAN&gt; &lt;SPAN&gt;Error&lt;/SPAN&gt; &lt;SPAN&gt;GoTo&lt;/SPAN&gt; 1: &lt;SPAN&gt;'Error catch for if user cancels out&lt;/SPAN&gt;
&lt;SPAN&gt;'specify the file dialog as a save dialog (rather than a open dialog)&lt;/SPAN&gt;
&lt;SPAN&gt;oFileDlg&lt;/SPAN&gt;.&lt;SPAN&gt;ShowSave&lt;/SPAN&gt;()

&lt;SPAN&gt;'On Error GoTo 1:'Resume Next&lt;/SPAN&gt;

&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;SPAN&gt; catch an empty string in the input&lt;/SPAN&gt;
&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;Err&lt;/SPAN&gt;.&lt;SPAN&gt;Number&lt;/SPAN&gt; &amp;lt;&amp;gt; 0 &lt;SPAN&gt;Then&lt;/SPAN&gt;
	&lt;SPAN&gt;Logger&lt;/SPAN&gt;.&lt;SPAN&gt;Debug&lt;/SPAN&gt;(&lt;SPAN&gt;"Error at file dialogue box"&lt;/SPAN&gt;)
	&lt;SPAN&gt;MessageBox&lt;/SPAN&gt;.&lt;SPAN&gt;Show&lt;/SPAN&gt;(&lt;SPAN&gt;"No File Saved."&lt;/SPAN&gt;, &lt;SPAN&gt;"iLogic: Dialog Canceled"&lt;/SPAN&gt;)
&lt;SPAN&gt;ElseIf&lt;/SPAN&gt; &lt;SPAN&gt;oFileDlg&lt;/SPAN&gt;.&lt;SPAN&gt;FileName&lt;/SPAN&gt; &amp;lt;&amp;gt; &lt;SPAN&gt;""&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt;
	&lt;SPAN&gt;MyFile&lt;/SPAN&gt; = &lt;SPAN&gt;oFileDlg&lt;/SPAN&gt;.&lt;SPAN&gt;FileName&lt;/SPAN&gt;
	&lt;SPAN&gt;Logger&lt;/SPAN&gt;.&lt;SPAN&gt;Debug&lt;/SPAN&gt;(&lt;SPAN&gt;"No Error for file save dialogue"&lt;/SPAN&gt;)


	&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;SPAN&gt; Get new filename (without extension)&lt;/SPAN&gt;
	&lt;SPAN&gt;NewFileName&lt;/SPAN&gt; = &lt;SPAN&gt;MyFile&lt;/SPAN&gt;&lt;SPAN&gt;'filePath &amp;amp;"\"&amp;amp; FileName &lt;/SPAN&gt;
	&lt;SPAN&gt;NewFileName&lt;/SPAN&gt; = &lt;SPAN&gt;System&lt;/SPAN&gt;.&lt;SPAN&gt;IO&lt;/SPAN&gt;.&lt;SPAN&gt;Path&lt;/SPAN&gt;.&lt;SPAN&gt;ChangeExtension&lt;/SPAN&gt;(&lt;SPAN&gt;NewFileName&lt;/SPAN&gt;, &lt;SPAN&gt;Nothing&lt;/SPAN&gt;)
	&lt;SPAN&gt;'If Str.Contains(MyFile, ".ipt") Or Str.Contains(MyFile, ".iam") Or Str.Contains(MyFile, ".idw") Or Str.Contains(MyFile, ".dwg") Then&lt;/SPAN&gt;
	&lt;SPAN&gt;'MyFile = Right(MyFile, (Len(MyFile) -4))&lt;/SPAN&gt;
	&lt;SPAN&gt;'End If&lt;/SPAN&gt;
	&lt;SPAN&gt;Logger&lt;/SPAN&gt;.&lt;SPAN&gt;Debug&lt;/SPAN&gt;(&lt;SPAN&gt;"NewFileName/MyFile: "&lt;/SPAN&gt; + &lt;SPAN&gt;MyFile&lt;/SPAN&gt; + &lt;SPAN&gt;filex&lt;/SPAN&gt;)
	
	&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;SPAN&gt; Perform Save As Of Assembly/Part&lt;/SPAN&gt;
	&lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Document&lt;/SPAN&gt;.&lt;SPAN&gt;SaveAs&lt;/SPAN&gt;(&lt;SPAN&gt;NewFileName&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;filex&lt;/SPAN&gt;, &lt;SPAN&gt;True&lt;/SPAN&gt;)
	&lt;SPAN&gt;Logger&lt;/SPAN&gt;.&lt;SPAN&gt;Debug&lt;/SPAN&gt;(&lt;SPAN&gt;"New file save successful"&lt;/SPAN&gt;)
	
	&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;SPAN&gt;  Update model iProperties&lt;/SPAN&gt;
	&lt;SPAN&gt;iNewFileName&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;FileName&lt;/SPAN&gt;(&lt;SPAN&gt;False&lt;/SPAN&gt;)
	&lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;PropertySets&lt;/SPAN&gt;(&lt;SPAN&gt;"Design Tracking Properties"&lt;/SPAN&gt;).&lt;SPAN&gt;Item&lt;/SPAN&gt;(&lt;SPAN&gt;"Part Number"&lt;/SPAN&gt;).&lt;SPAN&gt;Value&lt;/SPAN&gt; = &lt;SPAN&gt;iNewFileName&lt;/SPAN&gt;
	
	&lt;SPAN&gt;Logger&lt;/SPAN&gt;.&lt;SPAN&gt;Debug&lt;/SPAN&gt;(&lt;SPAN&gt;"File save attempted"&lt;/SPAN&gt;)
	&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;SPAN&gt;  Open the current drawing (in same folder location)&lt;/SPAN&gt;
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oDrawingDoc&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;DrawingDocument&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;Documents&lt;/SPAN&gt;.&lt;SPAN&gt;Open&lt;/SPAN&gt;(&lt;SPAN&gt;CurrentFilename&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;DWGType&lt;/SPAN&gt;,&lt;SPAN&gt;False&lt;/SPAN&gt;)
	&lt;SPAN&gt;oDrawingDoc&lt;/SPAN&gt;.&lt;SPAN&gt;SaveAs&lt;/SPAN&gt;(&lt;SPAN&gt;NewFileName&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;DWGType&lt;/SPAN&gt;, &lt;SPAN&gt;True&lt;/SPAN&gt;)
	&lt;SPAN&gt;oDrawingDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Close&lt;/SPAN&gt;
	&lt;SPAN&gt;oDrawingDoc&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;Documents&lt;/SPAN&gt;.&lt;SPAN&gt;Open&lt;/SPAN&gt;(&lt;SPAN&gt;NewFileName&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;DWGType&lt;/SPAN&gt;,&lt;SPAN&gt;False&lt;/SPAN&gt;)
	&lt;SPAN&gt;Logger&lt;/SPAN&gt;.&lt;SPAN&gt;Debug&lt;/SPAN&gt;(&lt;SPAN&gt;"File save successful :"&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;NewFileName&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;DWGType&lt;/SPAN&gt;)
	
	&lt;SPAN&gt;'''&lt;/SPAN&gt;&lt;SPAN&gt; Replace reference to assembly model&lt;/SPAN&gt;
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;oFD&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;FileDescriptor&lt;/SPAN&gt;
	&lt;SPAN&gt;oFD&lt;/SPAN&gt; = &lt;SPAN&gt;oDrawingDoc&lt;/SPAN&gt;.&lt;SPAN&gt;ReferencedFileDescriptors&lt;/SPAN&gt;(1).&lt;SPAN&gt;DocumentDescriptor&lt;/SPAN&gt;.&lt;SPAN&gt;ReferencedFileDescriptor&lt;/SPAN&gt;
	&lt;SPAN&gt;oFD&lt;/SPAN&gt;.&lt;SPAN&gt;ReplaceReference&lt;/SPAN&gt;(&lt;SPAN&gt;NewFileName&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;filex&lt;/SPAN&gt;)
	&lt;SPAN&gt;oDrawingDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Update&lt;/SPAN&gt;()
	&lt;SPAN&gt;'oDrawingDoc.Activate()&lt;/SPAN&gt;
	&lt;SPAN&gt;' Perform 'Save As' on the drawing&lt;/SPAN&gt;
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;newdwgname&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;String&lt;/SPAN&gt; = &lt;SPAN&gt;NewFileName&lt;/SPAN&gt; &amp;amp; &lt;SPAN&gt;DWGType&lt;/SPAN&gt;
	&lt;SPAN&gt;Logger&lt;/SPAN&gt;.&lt;SPAN&gt;Debug&lt;/SPAN&gt;(&lt;SPAN&gt;"newdwgname :"&lt;/SPAN&gt; + &lt;SPAN&gt;newdwgname&lt;/SPAN&gt;)
	&lt;SPAN&gt;oDrawingDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Save&lt;/SPAN&gt;()
	&lt;SPAN&gt;' ThisApplication.Documents.Open(oDWGPath, True)&lt;/SPAN&gt;
	&lt;SPAN&gt;oDrawingDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Close&lt;/SPAN&gt;
	&lt;SPAN&gt;Logger&lt;/SPAN&gt;.&lt;SPAN&gt;Debug&lt;/SPAN&gt;(&lt;SPAN&gt;"Replaced model reference"&lt;/SPAN&gt;)

	&lt;SPAN&gt;Call&lt;/SPAN&gt; &lt;SPAN&gt;Prop&lt;/SPAN&gt;
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
1:
&lt;SPAN&gt;'ThisDoc.Document.Activate&lt;/SPAN&gt;
&lt;SPAN&gt;'Call Prop&lt;/SPAN&gt;
&lt;SPAN&gt;'SilentOperation = False&lt;/SPAN&gt;
&lt;SPAN&gt;'oVault.Activate&lt;/SPAN&gt;
&lt;SPAN&gt;Logger&lt;/SPAN&gt;.&lt;SPAN&gt;Debug&lt;/SPAN&gt;(&lt;SPAN&gt;"completed"&lt;/SPAN&gt;)

&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;

&lt;SPAN&gt;Public&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt; &lt;SPAN&gt;Prop&lt;/SPAN&gt;
&lt;SPAN&gt;oDoc&lt;/SPAN&gt; = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;ActiveDocument&lt;/SPAN&gt;
&lt;SPAN&gt;iProperties&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt;(&lt;SPAN&gt;"Summary"&lt;/SPAN&gt;, &lt;SPAN&gt;"Author"&lt;/SPAN&gt;) = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;GeneralOptions&lt;/SPAN&gt;.&lt;SPAN&gt;UserName&lt;/SPAN&gt;
&lt;SPAN&gt;iProperties&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt;(&lt;SPAN&gt;"Project"&lt;/SPAN&gt;, &lt;SPAN&gt;"Designer"&lt;/SPAN&gt;) = &lt;SPAN&gt;ThisApplication&lt;/SPAN&gt;.&lt;SPAN&gt;GeneralOptions&lt;/SPAN&gt;.&lt;SPAN&gt;UserName&lt;/SPAN&gt;
&lt;SPAN&gt;'iProperties.Value("Project", "Stock Number") = "=&amp;lt;Part Number&amp;gt;"&lt;/SPAN&gt;
&lt;SPAN&gt;iProperties&lt;/SPAN&gt;.&lt;SPAN&gt;Value&lt;/SPAN&gt;(&lt;SPAN&gt;"Project"&lt;/SPAN&gt;, &lt;SPAN&gt;"Creation Date"&lt;/SPAN&gt; ) = &lt;SPAN&gt;Now&lt;/SPAN&gt;

&lt;SPAN&gt;InventorVb&lt;/SPAN&gt;.&lt;SPAN&gt;DocumentUpdate&lt;/SPAN&gt;()

&lt;SPAN&gt;' Save the document and its dependents.&lt;/SPAN&gt;
 &lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Save2&lt;/SPAN&gt;(&lt;SPAN&gt;True&lt;/SPAN&gt;)
	&lt;SPAN&gt;oDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Save2&lt;/SPAN&gt;(&lt;SPAN&gt;True&lt;/SPAN&gt;)
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2023 01:01:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/copy-model-and-drawing/m-p/11879080#M151095</guid>
      <dc:creator>zawthuratun</dc:creator>
      <dc:date>2023-04-07T01:01:34Z</dc:date>
    </item>
  </channel>
</rss>

