<?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 Modify Part Number help needed in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/modify-part-number-help-needed/m-p/8634412#M95198</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I have a code from&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/105031"&gt;@Curtis_Waguespack&lt;/a&gt;&amp;nbsp;&amp;nbsp;, which creates unique new parts in my project folder from library parts folder. Each new created part gets a new "Part Number" (=filename). That is not always preferable. I am looking for a way to modify the original "Part Number" iproperty in the new created part.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iproprty1.JPG" style="width: 474px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/609546i8940D77B19FAE4BF/image-size/large?v=v2&amp;amp;px=999" role="button" title="iproprty1.JPG" alt="iproprty1.JPG" /&gt;&lt;/span&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;In the library parts there is a custom iProperty called PTN_PARTNUMBER. I might be empty or it can have a text. If empty, do nothing, but if &amp;lt;&amp;gt; empty, I want to copy this value to the Part Number iproperty.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iproprty2.JPG" style="width: 665px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/609547i5F59059EB54E077E/image-size/large?v=v2&amp;amp;px=999" role="button" title="iproprty2.JPG" alt="iproprty2.JPG" /&gt;&lt;/span&gt;&lt;/DIV&gt;
&lt;DIV&gt;Could anyone help me to code this? Many Thanks!&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;Imports System.IO
GetInput :

Six_Digit = InputBox("Enter 6 Digit number", "iLogic", 000000)

If Six_Digit = "" Then
	Return
Else If Len(Six_Digit) &amp;lt;&amp;gt; "6" Then
MessageBox.Show("Input must be 6 digits", "ilogic")
GoTo GetInput

End If


Dim oDoc As Document
Dim sFilename As String

'hard code path
oLibrary_Folder = "U:\Johan\PTN_Part_Library\"


Dim oFilenames() As String
oFilenames = System.IO.Directory.GetFiles(oLibrary_Folder, _
"*.*", SearchOption.AllDirectories)

For Each oFilename As String In oFilenames
	If oFilename.Contains(Six_Digit) Then
		Dim oOptions As Inventor.NameValueMap
		oOptions = ThisApplication.TransientObjects.CreateNameValueMap
		oDoc = ThisApplication.Documents.OpenWithOptions(oFilename, oOptions, False)
		sFilename = oFilename
		Exit For
	End If
Next

If sFilename = "" Then
	MessageBox.Show("No matching libary file found.", "iLogic")
	Return
End If

iCounter = 0

'path from current file
oActiveAssemblyfolder = ThisDoc.Path &amp;amp; "\"

'path from current project file ( *.ipj)
oProjectfolder = _
ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath &amp;amp; "\"

Dim oProject_Filenames() As String
oProject_Filenames = System.IO.Directory.GetFiles(oProjectfolder, _
"*.*", SearchOption.AllDirectories)

'count existing project files					  
For Each oFilename As String In oProject_Filenames
	If oFilename.Contains(Six_Digit) Then
		iCounter = iCounter + 1
	End If
Next

'increment counter
iCounter = iCounter + 1


'find the postion of the last backslash in the path
FNamePos = InStrRev(sFilename, "\", - 1)
'get the file name with the file extension
oName = Right(sFilename, Len(sFilename) - FNamePos)
'get the file name (without extension)
ShortName = Left(oName, Len(oName) - 4)
'get extension
oExt = Right(oName, 4)


If iCounter &amp;lt; 10 Then
	iCounter = "00" + CStr(iCounter)
ElseIf iCounter &amp;lt; 100 Then
	iCounter = "0" + CStr(iCounter)
Else
	iCounter = CStr(iCounter)
End If

oNewName = ShortName &amp;amp; "_" &amp;amp; iCounter

oPathandName = oActiveAssemblyfolder &amp;amp; oNewName &amp;amp; oExt

'save new document
oDoc.SaveAs(oPathandName, True)
oDoc.Close

'[ Place Component
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Create Matrix
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
Call oMatrix.SetTranslation(ThisApplication.TransientGeometry.CreateVector(50, 50, 50), True)


'insert new occurence
Dim oOcc As ComponentOccurrence
oOcc = oAsmCompDef.Occurrences.Add( _
oPathandName, oMatrix)

oOcc.Grounded = False
ThisDoc.Document.SelectSet.Select(oOcc)

']

'MessageBox.Show("New file created: " &amp;amp; vbLf &amp;amp; oPathandName, "iLogic")

&lt;/PRE&gt;
&lt;/DIV&gt;</description>
    <pubDate>Mon, 04 Mar 2019 13:33:59 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-03-04T13:33:59Z</dc:date>
    <item>
      <title>Modify Part Number help needed</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/modify-part-number-help-needed/m-p/8634412#M95198</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have a code from&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/105031"&gt;@Curtis_Waguespack&lt;/a&gt;&amp;nbsp;&amp;nbsp;, which creates unique new parts in my project folder from library parts folder. Each new created part gets a new "Part Number" (=filename). That is not always preferable. I am looking for a way to modify the original "Part Number" iproperty in the new created part.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iproprty1.JPG" style="width: 474px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/609546i8940D77B19FAE4BF/image-size/large?v=v2&amp;amp;px=999" role="button" title="iproprty1.JPG" alt="iproprty1.JPG" /&gt;&lt;/span&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;In the library parts there is a custom iProperty called PTN_PARTNUMBER. I might be empty or it can have a text. If empty, do nothing, but if &amp;lt;&amp;gt; empty, I want to copy this value to the Part Number iproperty.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iproprty2.JPG" style="width: 665px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/609547i5F59059EB54E077E/image-size/large?v=v2&amp;amp;px=999" role="button" title="iproprty2.JPG" alt="iproprty2.JPG" /&gt;&lt;/span&gt;&lt;/DIV&gt;
&lt;DIV&gt;Could anyone help me to code this? Many Thanks!&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;Imports System.IO
GetInput :

Six_Digit = InputBox("Enter 6 Digit number", "iLogic", 000000)

If Six_Digit = "" Then
	Return
Else If Len(Six_Digit) &amp;lt;&amp;gt; "6" Then
MessageBox.Show("Input must be 6 digits", "ilogic")
GoTo GetInput

End If


Dim oDoc As Document
Dim sFilename As String

'hard code path
oLibrary_Folder = "U:\Johan\PTN_Part_Library\"


Dim oFilenames() As String
oFilenames = System.IO.Directory.GetFiles(oLibrary_Folder, _
"*.*", SearchOption.AllDirectories)

For Each oFilename As String In oFilenames
	If oFilename.Contains(Six_Digit) Then
		Dim oOptions As Inventor.NameValueMap
		oOptions = ThisApplication.TransientObjects.CreateNameValueMap
		oDoc = ThisApplication.Documents.OpenWithOptions(oFilename, oOptions, False)
		sFilename = oFilename
		Exit For
	End If
Next

If sFilename = "" Then
	MessageBox.Show("No matching libary file found.", "iLogic")
	Return
End If

iCounter = 0

'path from current file
oActiveAssemblyfolder = ThisDoc.Path &amp;amp; "\"

'path from current project file ( *.ipj)
oProjectfolder = _
ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath &amp;amp; "\"

Dim oProject_Filenames() As String
oProject_Filenames = System.IO.Directory.GetFiles(oProjectfolder, _
"*.*", SearchOption.AllDirectories)

'count existing project files					  
For Each oFilename As String In oProject_Filenames
	If oFilename.Contains(Six_Digit) Then
		iCounter = iCounter + 1
	End If
Next

'increment counter
iCounter = iCounter + 1


'find the postion of the last backslash in the path
FNamePos = InStrRev(sFilename, "\", - 1)
'get the file name with the file extension
oName = Right(sFilename, Len(sFilename) - FNamePos)
'get the file name (without extension)
ShortName = Left(oName, Len(oName) - 4)
'get extension
oExt = Right(oName, 4)


If iCounter &amp;lt; 10 Then
	iCounter = "00" + CStr(iCounter)
ElseIf iCounter &amp;lt; 100 Then
	iCounter = "0" + CStr(iCounter)
Else
	iCounter = CStr(iCounter)
End If

oNewName = ShortName &amp;amp; "_" &amp;amp; iCounter

oPathandName = oActiveAssemblyfolder &amp;amp; oNewName &amp;amp; oExt

'save new document
oDoc.SaveAs(oPathandName, True)
oDoc.Close

'[ Place Component
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Create Matrix
Dim oMatrix As Matrix
oMatrix = ThisApplication.TransientGeometry.CreateMatrix
Call oMatrix.SetTranslation(ThisApplication.TransientGeometry.CreateVector(50, 50, 50), True)


'insert new occurence
Dim oOcc As ComponentOccurrence
oOcc = oAsmCompDef.Occurrences.Add( _
oPathandName, oMatrix)

oOcc.Grounded = False
ThisDoc.Document.SelectSet.Select(oOcc)

']

'MessageBox.Show("New file created: " &amp;amp; vbLf &amp;amp; oPathandName, "iLogic")

&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 04 Mar 2019 13:33:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/modify-part-number-help-needed/m-p/8634412#M95198</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-03-04T13:33:59Z</dc:date>
    </item>
  </channel>
</rss>

