Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with macro

10 REPLIES 10
Reply
Message 1 of 11
Albeda8
512 Views, 10 Replies

Help with macro

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

10 REPLIES 10
Message 2 of 11
jdkriek
in reply to: Albeda8

Extracting the information to the iProperties is straightforward. However, how are the 300+ items organized locally? If they were all in the same folder or at least the same parent folder it would make this task much easier.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 3 of 11
Albeda8
in reply to: jdkriek

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... 

Message 4 of 11
jdkriek
in reply to: Albeda8

To make sure I understand:

 

Example: 

 

Full File Name: DIN 933 - M10 x 12.ipt

Extract Size "M10 x 12" To Keywords iProperty

Extract File Name "DIN 933 - M10 x 12" to Project iProperty

 

Is that correct?

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 5 of 11
jdkriek
in reply to: jdkriek

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
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 6 of 11
Albeda8
in reply to: jdkriek

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

 

Message 7 of 11
jdkriek
in reply to: Albeda8

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
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 8 of 11
Albeda8
in reply to: jdkriek

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 ?

 

 

Message 9 of 11
jdkriek
in reply to: Albeda8

Tools > VBA Editor 

 

Might want to create a project and a named module for it.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 10 of 11
bednarm.tl09
in reply to: jdkriek

Thank you, It is work now. Rly good macro and i can little modificate now.
My work has been done about 6 hours less.
Message 11 of 11
jdkriek
in reply to: bednarm.tl09

Great, glad it worked for you and it saved you 6HRS 😉

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report