<?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 Partnumber - automatic change by VBA macro in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862087#M82087</link>
    <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to change partnumber in my project in "automatic mode " like on scheme below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 705px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/476986iC22C47BB3EA8F250/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have a simple code, but it works only for parts on one BOM level and does not save the scheme 0.001 ... 1.001 etc. (I do not think that's the way):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Sub Zmiana_partnumber()
Dim asmDoc As AssemblyDocument
Set asmDoc = ThisApplication.ActiveDocument
Dim oBom As BOM
Set oBom = asmDoc.ComponentDefinition.BOM
oBom.StructuredViewEnabled = True
oBom.StructuredViewFirstLevelOnly = False
Dim oBOMView As BOMView
Set oBOMView = oBom.BOMViews(2)
Dim compDef As ComponentDefinition
Dim doc As Document
Dim row As BOMRow
Dim prop As Property
Dim NUMER As String
Dim Licznik As Long
NUMER = InputBox("Wprowadź NUMER", "Okno wprowadzania", xx_xxxx)
For Each row In oBOMView.BOMRows
Set compDef = row.ComponentDefinitions(1)
Set doc = compDef.Document
If compDef.Type = kVirtualComponentDefinitionObject Then
Set prop = compDef.PropertySets("Design Tracking Properties")("Part Number")
Else
Set prop = doc.PropertySets("Design Tracking Properties")("Part Number")
End If
Licznik = Licznik + 1
If doc.IsModifiable Then
If prop.Value &amp;lt;&amp;gt; NUMER Then prop.Value = NUMER &amp;amp; "-" &amp;amp; Licznik
End If
Next
End Sub&lt;/PRE&gt;&lt;DIV class="g-unit"&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="translit"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="g-unit"&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV class="trans-verified-button-small"&gt;&lt;SPAN class=""&gt;The next thing would be copying the entire file structure to a new folder, changing the names of files to part numbers &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@B4D44A73814D7FC0D950DEDFACB97081/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to do this type of macro in VBA at all?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;ralfmj&lt;/P&gt;</description>
    <pubDate>Sat, 17 Mar 2018 15:28:20 GMT</pubDate>
    <dc:creator>ralfmja</dc:creator>
    <dc:date>2018-03-17T15:28:20Z</dc:date>
    <item>
      <title>Partnumber - automatic change by VBA macro</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862087#M82087</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to change partnumber in my project in "automatic mode " like on scheme below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 705px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/476986iC22C47BB3EA8F250/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have a simple code, but it works only for parts on one BOM level and does not save the scheme 0.001 ... 1.001 etc. (I do not think that's the way):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Sub Zmiana_partnumber()
Dim asmDoc As AssemblyDocument
Set asmDoc = ThisApplication.ActiveDocument
Dim oBom As BOM
Set oBom = asmDoc.ComponentDefinition.BOM
oBom.StructuredViewEnabled = True
oBom.StructuredViewFirstLevelOnly = False
Dim oBOMView As BOMView
Set oBOMView = oBom.BOMViews(2)
Dim compDef As ComponentDefinition
Dim doc As Document
Dim row As BOMRow
Dim prop As Property
Dim NUMER As String
Dim Licznik As Long
NUMER = InputBox("Wprowadź NUMER", "Okno wprowadzania", xx_xxxx)
For Each row In oBOMView.BOMRows
Set compDef = row.ComponentDefinitions(1)
Set doc = compDef.Document
If compDef.Type = kVirtualComponentDefinitionObject Then
Set prop = compDef.PropertySets("Design Tracking Properties")("Part Number")
Else
Set prop = doc.PropertySets("Design Tracking Properties")("Part Number")
End If
Licznik = Licznik + 1
If doc.IsModifiable Then
If prop.Value &amp;lt;&amp;gt; NUMER Then prop.Value = NUMER &amp;amp; "-" &amp;amp; Licznik
End If
Next
End Sub&lt;/PRE&gt;&lt;DIV class="g-unit"&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="translit"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="g-unit"&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV class="trans-verified-button-small"&gt;&lt;SPAN class=""&gt;The next thing would be copying the entire file structure to a new folder, changing the names of files to part numbers &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@B4D44A73814D7FC0D950DEDFACB97081/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to do this type of macro in VBA at all?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;ralfmj&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 15:28:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862087#M82087</guid>
      <dc:creator>ralfmja</dc:creator>
      <dc:date>2018-03-17T15:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Partnumber - automatic change by VBA macro</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862147#M82088</link>
      <description>&lt;P&gt;Yes, it's definitely possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest your read up more on VBA and search the forums a little better as there are many, many examples of the same thing being done.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 16:19:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862147#M82088</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2018-03-17T16:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Partnumber - automatic change by VBA macro</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862172#M82092</link>
      <description>&lt;P&gt;Thank for your reply,&lt;BR /&gt;Can you give me similar example of topic which can be useful for me ??&lt;/P&gt;&lt;P&gt;I can't find solution which I can use in my case ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;ralfmj&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 16:52:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862172#M82092</guid>
      <dc:creator>ralfmja</dc:creator>
      <dc:date>2018-03-17T16:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Partnumber - automatic change by VBA macro</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862212#M82093</link>
      <description>&lt;P&gt;Below is a link to a thread with multiple different approaches encompassed in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/inventor-forum/renaming-mass-amounts-of-files/td-p/6801209" target="_blank"&gt;https://forums.autodesk.com/t5/inventor-forum/renaming-mass-amounts-of-files/td-p/6801209&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 17:48:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862212#M82093</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2018-03-17T17:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: Partnumber - automatic change by VBA macro</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862304#M82098</link>
      <description>&lt;P&gt;Sorry but it's not for me. I tried to use many tools but it wasn't good for me ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best for me is a design assistant but it's very manual tool.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you use DA in case a 1000part assembly you must click 1000 time change filename etc. If you do 1 mistake you can start again. You loose many time which can be dedicate for design.&lt;/P&gt;&lt;P&gt;For me the best way is dedicated macro in VBA which I can't write alone ... I need help VBA master who has time for me and my problem &lt;img class="lia-deferred-image lia-image-emoji" src="https://forums.autodesk.com/html/@B4D44A73814D7FC0D950DEDFACB97081/emoticons/1f642.png" alt=":slightly_smiling_face:" title=":slightly_smiling_face:" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 18:50:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862304#M82098</guid>
      <dc:creator>ralfmja</dc:creator>
      <dc:date>2018-03-17T18:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: Partnumber - automatic change by VBA macro</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862315#M82100</link>
      <description>&lt;P&gt;Well thanks for not even looking at the link then.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are 2 excel vba tools in there that rename parts without the drawback of the Design Assitant stuff.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is also a lot of code in there that is very similar and requires subtle tweaks to get it to how you want it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sounds like you just want somebody to do all of the work for you, for free. An alternative would be to do some learning on VBA/vb.net so you fix it yourself.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 19:04:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862315#M82100</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2018-03-17T19:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: Partnumber - automatic change by VBA macro</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862345#M82101</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;'Code adapted from Owner2229.

Sub Test()&lt;BR /&gt;    'ThisApplication.SilentOperation = True&lt;BR /&gt;    Dim oDoc As Document&lt;BR /&gt;    Set oDoc = ThisApplication.ActiveDocument
    oPrefix = InputBox("Enter new prefix", "Helper", "XXX")&lt;BR /&gt;    oInt = 1&lt;BR /&gt;
    oNewName = GetNewName(oDoc.FullFileName)&lt;BR /&gt;    Call UpdatePartNumber(oDoc, oNewName)&lt;BR /&gt;    Call oDoc.SaveAs(oNewName, False)

    Call RenameChildFiles(oDoc)
    Call oDoc.Save&lt;BR /&gt;    'ThisApplication.SilentOperation = False&lt;BR /&gt;End Sub

Dim oInt As Integer&lt;BR /&gt;Dim oPrefix As String&lt;BR /&gt;
Public Sub RenameChildFiles(oDoc As Inventor.Document)&lt;BR /&gt;    Dim oRefFile As FileDescriptor&lt;BR /&gt;    For Each oRefFile In oDoc.File.ReferencedFileDescriptors&lt;BR /&gt;        Dim oName As String&lt;BR /&gt;        oName = oRefFile.FullFileName&lt;BR /&gt;        Dim aDoc As Inventor.Document&lt;BR /&gt;        Set aDoc = ThisApplication.Documents.Open(oName, False)&lt;BR /&gt;&lt;BR /&gt;        If aDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then&lt;BR /&gt;            Call RenameChildFiles(aDoc)&lt;BR /&gt;        End If&lt;BR /&gt;
        Dim oNewName As String&lt;BR /&gt;        oNewName = GetNewName(oName)&lt;BR /&gt;        Call UpdatePartNumber(aDoc, oNewName)&lt;BR /&gt;        Call aDoc.SaveAs(oNewName, False)&lt;BR /&gt;        Call aDoc.Close (True)&lt;BR /&gt;        Call oRefFile.ReplaceReference (oNewName)&lt;BR /&gt;    Next&lt;BR /&gt;End Sub&lt;BR /&gt;&lt;BR /&gt;Public Function GetNewName(oName As String) As String&lt;BR /&gt;    Dim FNP As Integer&lt;BR /&gt;    FNP = InStrRev(oName, "\", -1)&lt;BR /&gt;&lt;BR /&gt;    Dim oPath As String&lt;BR /&gt;    oPath = Left(oName, FNP)
    oExt = RIGHT(oName, 4)&lt;BR /&gt;
    Dim oNumber As String&lt;BR /&gt;    oNumber = oInt.ToString("0000")&lt;BR /&gt;&lt;BR /&gt;    Dim oNewName As String&lt;BR /&gt;    GetNewName = oPath &amp;amp; oPref &amp;amp; "-" &amp;amp; oNumber &amp;amp; oExt&lt;BR /&gt;End Function&lt;BR /&gt;&lt;BR /&gt;Public Sub UpdatePartNumber(oDoc As Inventor.Document, PN As String)&lt;BR /&gt;    Dim FNP As Integer&lt;BR /&gt;    FNP = InStrRev(PN, "\", -1)&lt;BR /&gt;    PN = Mid(PN, FNP + 1)&lt;BR /&gt;    PN = Left(PN, Len(PN) - 4)&lt;BR /&gt;    iProperty(oDoc, "Part Number").Expression = PN&lt;BR /&gt;End Sub&lt;BR /&gt;&lt;BR /&gt;Public Function iProperty(oDoc As Inventor.Document, oProp As String) As Inventor.Property&lt;BR /&gt;    Dim iPro As Inventor.Property&lt;BR /&gt;&lt;BR /&gt;  On Error GoTo IPCatch&lt;BR /&gt;    Dim oPropsets As PropertySets&lt;BR /&gt;    Set oPropsets = oDoc.PropertySets&lt;BR /&gt;    Dim oPropSet As PropertySet&lt;BR /&gt;    Set oPropSet = oPropsets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")&lt;BR /&gt;    iProperty = oPropSet.Item(oProp)&lt;BR /&gt;  IPCatch: &lt;BR /&gt;    Call oPropSet.Add("", oProp)&lt;BR /&gt;    iProperty = oPropSet.Item(oProp)&lt;BR /&gt;End Function&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 19:24:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862345#M82101</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2018-03-17T19:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Partnumber - automatic change by VBA macro</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862383#M82103</link>
      <description>&lt;P&gt;Thanks alot for your help &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;You have right I don't have knowledge about VB so I count for good people on this forum &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; I'm very happy that you want help me.&lt;/P&gt;&lt;P&gt;In this way I "wrote" few very helpfull macro which help me in daily work.&lt;/P&gt;&lt;P&gt;I know itsn't easy but I think it's possible.&lt;/P&gt;&lt;P&gt;Below you can see what kind of problem I have with code above.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="3.png" style="width: 582px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/477054i8B7DB61D3AE5984E/image-size/large?v=v2&amp;amp;px=999" role="button" title="3.png" alt="3.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I know that should convert number of occurance to string (like on my photos in first post)&amp;nbsp; but we have error .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 20:17:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7862383#M82103</guid>
      <dc:creator>ralfmja</dc:creator>
      <dc:date>2018-03-17T20:17:25Z</dc:date>
    </item>
    <item>
      <title>Re: Partnumber - automatic change by VBA macro</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7863705#M82115</link>
      <description>&lt;P&gt;So what that line does is changes the "part id number" into a 4 character digit. Using any available VBA method that turns "1" into "0001" would be fine. Should be able to google it and find an answer quick. I don't have inventor on this computer to test and debug.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 03:38:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7863705#M82115</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2018-03-19T03:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: Partnumber - automatic change by VBA macro</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7876295#M82332</link>
      <description>&lt;P&gt;I think this version should function better...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Dim oInt As Integer
Dim oPrefix As String

Sub Test()
    'ThisApplication.SilentOperation = True
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    oPrefix = InputBox("Enter new prefix", "Helper", "XXX")
    oInt = 1
    
    Dim oNewName As String
    oNewName = GetNewName(oDoc.FullFileName)
    Call UpdatePartNumber(oDoc, oNewName)
    Call oDoc.SaveAs(oNewName, False)

    Call RenameChildFiles(oDoc)
    Call oDoc.Save
    'ThisApplication.SilentOperation = False
End Sub

Public Sub RenameChildFiles(oDoc As Inventor.Document)
    Dim oRefFile As FileDescriptor
    For Each oRefFile In oDoc.File.ReferencedFileDescriptors
        Dim oName As String
        oName = oRefFile.FullFileName
        Dim aDoc As Inventor.Document
        Set aDoc = ThisApplication.Documents.Open(oName, False)

        If aDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
            Call RenameChildFiles(aDoc)
        End If

        Dim oNewName As String
        oNewName = GetNewName(oName)
        Call UpdatePartNumber(aDoc, oNewName)
        Call aDoc.SaveAs(oNewName, False)
        Call aDoc.Close(True)
        Call oRefFile.ReplaceReference(oNewName)
    Next
End Sub

Public Function GetNewName(oName As String) As String
    Dim FNP As Integer
    FNP = InStrRev(oName, "\", -1)

    Dim oPath As String
    oPath = Left(oName, FNP)
    oExt = Right(oName, 4)

    Dim oNumber As String
    oNumber = Format(oInt, "0000")

    Dim oNewName As String
    GetNewName = oPath &amp;amp; oPref &amp;amp; "-" &amp;amp; oNumber &amp;amp; oExt
End Function

Public Sub UpdatePartNumber(oDoc As Inventor.Document, PN As String)
    Dim FNP As Integer
    FNP = InStrRev(PN, "\", -1)
    PN = Mid(PN, FNP + 1)
    PN = Left(PN, Len(PN) - 4)
    iProperty(oDoc, "Part Number").Expression = PN
End Sub

Public Function iProperty(oDoc As Inventor.Document, oProp As String) As Inventor.Property

  On Error GoTo IPCatch
    Dim oPropsets As PropertySets
    Set oPropsets = oDoc.PropertySets
    Dim oPropSet As PropertySet
    Set oPropSet = oPropsets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")
    Set iProperty = oPropSet.Item(oProp)
    Exit Function
IPCatch:
    Call oPropSet.Add("", oProp)
    Set iProperty = oPropSet.Item(oProp)
End Function&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Mar 2018 19:00:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/partnumber-automatic-change-by-vba-macro/m-p/7876295#M82332</guid>
      <dc:creator>MechMachineMan</dc:creator>
      <dc:date>2018-03-22T19:00:07Z</dc:date>
    </item>
  </channel>
</rss>

