<?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 Re: name and location in code in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7417219#M75370</link>
    <description>&lt;P&gt;I got the location sorted just cant get my head around the naming part&lt;/P&gt;</description>
    <pubDate>Thu, 28 Sep 2017 14:57:10 GMT</pubDate>
    <dc:creator>JamieSENG</dc:creator>
    <dc:date>2017-09-28T14:57:10Z</dc:date>
    <item>
      <title>name and location in code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7416320#M75349</link>
      <description>&lt;P&gt;I found this code a while back and wanted to edit it to change the file name and the location the files save in. Currently it goes through open drawings exporting them as the file name with _acad2k saving the files in the original files location. However i would like the file name to be populated by the iproperties part number and revision and file path to be a folder on my c drive.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Imports SysIO = System.IO
Sub Main()
'See if there are any open views
If (ThisApplication.Views.Count &amp;gt; 0) Then
'Setup Translator to dwg
Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
'Go through each view and save if it's a drawing document
For Each view As View In ThisApplication.Views
If view.Document.DocumentType = kDrawingDocumentObject Then
'Get the directory file is saved in. Can replace this with specific directory
Dim dwgDir = SysIO.Path.GetDirectoryName(view.Document.FullFileName)
Get name Of file without the extension And add _acad2k To it.
oDataMedium.MediumType = kFileNameMedium
oDataMedium.FileName = dwgDir &amp;amp; "\\" &amp;amp; _
 SysIO.Path.GetFileNameWithoutExtension(view.Document.FullFileName) &amp;amp; _
 "_acad2k.dwg"

' Check whether the translator has 'SaveCopyAs' options
If DWGAddIn.HasSaveCopyAsOptions(view.Document, oContext, oOptions) Then
'Use Export To DWG to save drawing configuration and set here
Dim strIniFile As String = "C:\Export Copy Main Directory\dwg\Format2000DONOTDELETE.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
'Save File
Call DWGAddIn.SaveCopyAs(view.Document, oContext, oOptions, oDataMedium)
End If
End If
Next
End If
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 09:56:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7416320#M75349</guid>
      <dc:creator>JamieSENG</dc:creator>
      <dc:date>2017-09-28T09:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: name and location in code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7417018#M75367</link>
      <description>&lt;P&gt;revise this line as necessary to meet your needs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;oDataMedium.FileName = dwgDir &amp;amp; "\\" &amp;amp; _
 SysIO.Path.GetFileNameWithoutExtension(view.Document.FullFileName) &amp;amp; _
 "_acad2k.dwg"&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Sep 2017 14:08:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7417018#M75367</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2017-09-28T14:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: name and location in code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7417219#M75370</link>
      <description>&lt;P&gt;I got the location sorted just cant get my head around the naming part&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 14:57:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7417219#M75370</guid>
      <dc:creator>JamieSENG</dc:creator>
      <dc:date>2017-09-28T14:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: name and location in code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7417334#M75374</link>
      <description>&lt;P&gt;So i got the location and filename sorted. Only now when i run the code the exported files keep the&amp;nbsp;first filename and overwrite one another. Could you take a look...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Imports SysIO = System.IO
Sub Main()
'See if there are any open views
If (ThisApplication.Views.Count &amp;gt; 0) Then
'Setup Translator to dwg
Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
'Go through each view and save if it's a drawing document
For Each view As View In ThisApplication.Views
If view.Document.DocumentType = kDrawingDocumentObject Then

'Get the directory file is saved in. Can replace this with specific directory
Dim dwgDir = "C:\Export Copy Main Directory\dwg\"
'Get name Of file without the extension And add _acad2k To it.
oDataMedium.MediumType = kFileNameMedium

oDataMedium.FileName = dwgDir &amp;amp; iProperties.Value("Project", "Part Number") &amp;amp; " Rev. " &amp;amp; iProperties.Value("Project", "Revision Number") &amp;amp; ".dwg"

' Check whether the translator has 'SaveCopyAs' options
If DWGAddIn.HasSaveCopyAsOptions(view.Document, oContext, oOptions) Then
'Use Export To DWG to save drawing configuration and set here
Dim strIniFile As String = "C:\Export Copy Main Directory\dwg\Format2000DONOTDELETE.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
'Save File
Call DWGAddIn.SaveCopyAs(view.Document, oContext, oOptions, oDataMedium)
End If
End If
Next
End If
End Sub&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Sep 2017 15:31:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7417334#M75374</guid>
      <dc:creator>JamieSENG</dc:creator>
      <dc:date>2017-09-28T15:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: name and location in code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7418022#M75381</link>
      <description>&lt;P&gt;Your iProperties.Value call only ever grabs from the ACTIVE document. You need to DIRECT it to each document to grab that specific documents name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;iProperties.Value("Project", "Part Number")&lt;/PRE&gt;
&lt;P&gt;use&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;iProperties.Value(SysIO.Path.GetFileName(view.Document), "Project", "Part Number")&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Good luck!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: You would have to call view.Document.Activate for every new document during the loop in which you process it, which is very time consuming to make it work with just the base iProperties.Value() call. But&amp;nbsp;no one wants this, so use the info provided above instead.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 18:38:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7418022#M75381</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2017-09-28T18:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: name and location in code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7430808#M75486</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I realise my limitation was that the code ran through all open drawings but didn't&amp;nbsp;physically go to the next, hence why I kept getting the same file throughout. F&lt;/SPAN&gt;or the time being, I'm&amp;nbsp;just going to use the code as is. Seems more trouble than&amp;nbsp;it's worth&amp;nbsp;trying to fetch the iproperties.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You did mention before that you would need to "call view.Document.Activate for every new document during the loop"&lt;/P&gt;&lt;P&gt;Would this activate each drawing to apply the rule?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If&amp;nbsp;so out of curiosity how would you go about doing it?&amp;nbsp;I sense there could be an issue with the loop going back over the first?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 09:15:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7430808#M75486</guid>
      <dc:creator>JamieSENG</dc:creator>
      <dc:date>2017-10-04T09:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: name and location in code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7430873#M75487</link>
      <description>&lt;PRE&gt;Imports SysIO = System.IO&lt;BR /&gt;
Sub Main()
&lt;BR /&gt;   'Check pre-processing conditions.
   If (ThisApplication.Views.Count = 0) Then: Exit Sub: End if

   Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
   Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
   oContext.Type = kFileBrowseIOMechanism&lt;BR /&gt;
   Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
   Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
&lt;BR /&gt;
   For Each oVisDoc As View In ThisApplication.Documents.VisibleDocuments
      If oVisDoc.DocumentType = kDrawingDocumentObject Then &lt;BR /&gt;             DocName = SysIO.GetFileName(oVisDoc.FullFileName)&lt;BR /&gt;             Dim dwgDir = SysIO.Path.GetDirectoryName(oVisDoc.FullFileName)&lt;BR /&gt;             oDataMedium.MediumType = kFileNameMedium&lt;BR /&gt;             oDataMedium.FileName = dwgDir &amp;amp; iProperties.Value(DocName, "Project", "Part Number") &amp;amp; " Rev. " &amp;amp; iProperties.Value(DocName, "Project", "Revision Number") &amp;amp; ".dwg"
&lt;BR /&gt;             If DWGAddIn.HasSaveCopyAsOptions(oVisDoc, oContext, oOptions) Then&lt;BR /&gt;                 Dim strIniFile As String = "C:\Export Copy Main Directory\dwg\Format2000DONOTDELETE.ini"&lt;BR /&gt;                 oOptions.Value("Export_Acad_IniFile") = strIniFile&lt;BR /&gt;                 &lt;BR /&gt;                 Call DWGAddIn.SaveCopyAs(oVisDoc, oContext, oOptions, oDataMedium)&lt;BR /&gt;             End If&lt;BR /&gt;       End If &lt;BR /&gt;    Next&lt;BR /&gt;End Sub&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 09:44:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7430873#M75487</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2017-10-04T09:44:25Z</dc:date>
    </item>
    <item>
      <title>Re: name and location in code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7430950#M75489</link>
      <description>&lt;P&gt;Ran the code an get an error on line 18: GetFileName is not a member of IO&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I noticed there isn't a location anymore with this code. So does that mean the file will save in the location of the original files?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Dim dwgDir = SysIO.Path.GetDirectoryName(oVisDoc.FullFileName)

not

Dim dwgDir = "C:\Export Copy Main Directory\dwg\"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 10:14:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7430950#M75489</guid>
      <dc:creator>JamieSENG</dc:creator>
      <dc:date>2017-10-04T10:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: name and location in code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7431509#M75501</link>
      <description>Yeah. As you have across your combined version of codes... That error is&lt;BR /&gt;because I forgot to type in ".Path" after SysIO.&lt;BR /&gt;Also feel free to change the location to whatever you desired as you have&lt;BR /&gt;outlined in this last reply.&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Oct 2017 13:05:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7431509#M75501</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2017-10-04T13:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: name and location in code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7431800#M75507</link>
      <description>&lt;P&gt;Its throwing up the following error "&lt;/P&gt;&lt;P&gt;Error in rule: Rule0, in document: JE352-100-07TEMPL Hopper Joiner Plate.dwg&lt;/P&gt;&lt;P&gt;Unable to cast COM object of type 'Inventor._DocumentClass' to interface type 'Inventor.View'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{70109AA3-63C1-11D2-B78B-0060B0EC020B}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;More Info,&lt;/P&gt;&lt;P&gt;"System.InvalidCastException: Unable to cast COM object of type 'Inventor._DocumentClass' to interface type 'Inventor.View'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{70109AA3-63C1-11D2-B78B-0060B0EC020B}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).&lt;BR /&gt;at LmiRuleScript.Main()&lt;BR /&gt;at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)&lt;BR /&gt;at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, see code modified for the file path I require... have I done something wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Imports SysIO = System.IO

Sub Main()

   'Check pre-processing conditions.
   If (ThisApplication.Views.Count = 0) Then: Exit Sub: End If

   Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
   Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
   oContext.Type = kFileBrowseIOMechanism

   Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
   Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium


   For Each oVisDoc As View In ThisApplication.Documents.VisibleDocuments
      If oVisDoc.DocumentType = kDrawingDocumentObject Then 
             DocName = SysIO.Path.GetFileName(oVisDoc.FullFileName)
             Dim dwgDir = SysIO.Path.GetDirectoryName(oVisDoc.FullFileName)
  'required path - 'Dim dwgDir = "S:\Drawing Office\Inventor Design Folder\Export Copy Main Directory - Shared\dwg\"
			 oDataMedium.MediumType = kFileNameMedium
             oDataMedium.FileName = dwgDir &amp;amp; iProperties.Value(DocName, "Project", "Part Number") &amp;amp; " Rev. " &amp;amp; iProperties.Value(DocName, "Project", "Revision Number") &amp;amp; ".dwg"

             If DWGAddIn.HasSaveCopyAsOptions(oVisDoc, oContext, oOptions) Then
                 Dim strIniFile As String = "S:\Drawing Office\Inventor Design Folder\Export Copy Main Directory - Shared\dwg\Format2000DONOTDELETE.ini"
                 oOptions.Value("Export_Acad_IniFile") = strIniFile
                 
                 Call DWGAddIn.SaveCopyAs(oVisDoc, oContext, oOptions, oDataMedium)
             End If
       End If 
    Next
End Sub&lt;/PRE&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2017 14:20:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7431800#M75507</guid>
      <dc:creator>JamieSENG</dc:creator>
      <dc:date>2017-10-04T14:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: name and location in code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7432307#M75512</link>
      <description>&lt;PRE&gt;Imports SysIO = System.IO

Sub Main()

   'Check pre-processing conditions.
   If (ThisApplication.Views.Count = 0) Then: Exit Sub: End If

   Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
   Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
   oContext.Type = kFileBrowseIOMechanism

   Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
   Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium

&lt;STRONG&gt;
   For Each oVisDoc In ThisApplication.Documents.VisibleDocuments&lt;/STRONG&gt;
      If oVisDoc.DocumentType = kDrawingDocumentObject Then 
             DocName = SysIO.Path.GetFileName(oVisDoc.FullFileName)
&lt;STRONG&gt;             'Dim dwgDir = SysIO.Path.GetDirectoryName(oVisDoc.FullFileName)
             Dim dwgDir = "S:\Drawing Office\Inventor Design Folder\Export Copy Main Directory - Shared\dwg\"&lt;/STRONG&gt;
	     oDataMedium.MediumType = kFileNameMedium
             oDataMedium.FileName = dwgDir &amp;amp; iProperties.Value(DocName, "Project", "Part Number") &amp;amp; " Rev. " &amp;amp; iProperties.Value(DocName, "Project", "Revision Number") &amp;amp; ".dwg"

             If DWGAddIn.HasSaveCopyAsOptions(oVisDoc, oContext, oOptions) Then
                 Dim strIniFile As String = "S:\Drawing Office\Inventor Design Folder\Export Copy Main Directory - Shared\dwg\Format2000DONOTDELETE.ini"
                 oOptions.Value("Export_Acad_IniFile") = strIniFile
                 
                 Call DWGAddIn.SaveCopyAs(oVisDoc, oContext, oOptions, oDataMedium)
             End If
       End If 
    Next
End Sub&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Oct 2017 16:42:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7432307#M75512</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2017-10-04T16:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: name and location in code</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7434744#M75548</link>
      <description>&lt;P&gt;Get the following error...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;iProperties:The document named "testdrawing.dwg" was not found.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 12:08:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/name-and-location-in-code/m-p/7434744#M75548</guid>
      <dc:creator>JamieSENG</dc:creator>
      <dc:date>2017-10-05T12:08:18Z</dc:date>
    </item>
  </channel>
</rss>

