Hello,
I'm doing the database bolts and it is a great slavery in click with mouse.
I would like to work to facilitate and mainly speed up by using a macro , but I need help to create a piece of code to VB.
So if is it possible, I would like to give me the macro did the following thing:
- from FILE name (in windows) example: DIN 933 - M10 x 12 select string "M10x12" to variable.
- The string I need to put iProperties -> Summary -> Keywords (example "M10x12")
- In iProperties -> Project tab -> Part I need to put the file name.(not sure if i use correct eng. words - I have Inventor in czech lng.)
If anyone knows how to do it, I would be really grateful. Otherwise, this activity will have to do it manually for about 300 + items.
PS: Sorry for my english.
Best regards
Martin
Thank you for reply!
Sorry i forgot on that. Yes, i have these files in one local folder or i have 200files in one folder, next 150files in another folder, etc...
I believe I understood correctly, if not it's a simple change
Be sure to Include the REF in VBA to the Scripting runtime.
Public Sub UpdateDocs() 'JDK 2013 ' Include REF to Microsoft Scripting Runtime Dim oApp As Application Set oApp = ThisApplication Dim oDoc As PartDocument Dim oPropSet As PropertySet Dim FSO As New Scripting.FileSystemObject Dim oFld As Scripting.Folder Dim oFile As Scripting.File Dim Path As String ' Define path to folder Path = "C:\Test" If FSO.FolderExists(Path) Then Set oFld = FSO.GetFolder(Path) Else MsgBox ("Folder Does Not Exist") Exit Sub End If oApp.SilentOperation = True For Each oFile In oFld.Files getExt = Split(oFile.name, ".") sExt = getExt(1) sName = getExt(0) sKey = Split(sName, "-") If InStr(sExt, "ipt") Then Set oDoc = oApp.Documents.Open(oFile, False) If oDoc.DocumentType = kPartDocumentObject Then Dim oSummaryPropSet As PropertySet Set oSummaryPropSet = oDoc.PropertySets.Item( _ "Summary Information") oSummaryPropSet.Item("Keywords").Value = sKey(1) Dim oDesignPropSet As PropertySet Set oDesignPropSet = oDoc.PropertySets.Item( _ "Design Tracking Properties") oDesignPropSet.Item("Project").Value = sName With oDoc .Update .Save .Close End With End If End If Next oApp.SilentOperation = False Set oFile = Nothing Set oFld = Nothing Set FSO = Nothing End Sub
Hi,
thank you very much for your macro.
Can you tell me how I Include the REF in VBA to the Scripting runtime? Im not sure where is it.
Your example is correct, but if is impossible i need this:
Full File Name: DIN 933 - M10 x 12.ipt
Extract Size "M10x12" To Summary -> Keywords iProperty (no space)
Extract File Name "DIN 933 - M10x12" to Project -> part number iProperty (no space too)
Thank you for helping me.
Student
Martin
Tools > Refrences > Check "Microsoft Scripting Runtime" > Click Ok
Updated code with your changes:
Public Sub UpdateDocs() 'JDK 2013 ' Include REF to Microsoft Scripting Runtime Dim oApp As Application Set oApp = ThisApplication Dim oDoc As PartDocument Dim oPropSet As PropertySet Dim FSO As New Scripting.FileSystemObject Dim oFld As Scripting.Folder Dim oFile As Scripting.File Dim Path As String ' Define path to folder Path = "C:\Test" If FSO.FolderExists(Path) Then Set oFld = FSO.GetFolder(Path) Else MsgBox ("Folder Does Not Exist") Exit Sub End If oApp.SilentOperation = True For Each oFile In oFld.Files getExt = Split(oFile.name, ".") sExt = getExt(1) sName = getExt(0) sKey = Split(sName, "-") If InStr(sExt, "ipt") Then Set oDoc = oApp.Documents.Open(oFile, False) If oDoc.DocumentType = kPartDocumentObject Then sKeya = Replace(sKey(1), " ", "") sName = sKey(0) & " - " & sKeya Dim oSummaryPropSet As PropertySet Set oSummaryPropSet = oDoc.PropertySets.Item( _ "Summary Information") oSummaryPropSet.Item("Keywords").Value = sKeya Dim oDesignPropSet As PropertySet Set oDesignPropSet = oDoc.PropertySets.Item( _ "Design Tracking Properties") oDesignPropSet.Item("Project").Value = sName With oDoc .Update .Save .Close End With End If End If Next oApp.SilentOperation = False Set oFile = Nothing Set oFld = Nothing Set FSO = Nothing End Sub
Hi again,
thank you for rework you code. I guess it will be ok now.
But excuse me, im beginner more than i thought. Where i have to put your code? In program Inventor -> macros or MS Visual basic program ?