Add a custom iProperty to a directory of sheet metal parts

Add a custom iProperty to a directory of sheet metal parts

brendan.henderson
Advisor Advisor
450 Views
3 Replies
Message 1 of 4

Add a custom iProperty to a directory of sheet metal parts

brendan.henderson
Advisor
Advisor

I'm looking for input as to how I could 'batch' add a custom iProperty to a directory and apply it only to Sheet metal parts? By this I mean point a macro (or whatever) at a directory, filter the sheet metal parts and add the custom iProperty? I am using Vault which may complicate things.

Brendan Henderson
CAD Manager


New Blog | Old Blog | Google+ | Twitter


Inventor 2016 PDSU Build 236, Release 2016.2.2, Vault Professional 2016 Update 1, Win 7 64 bit


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
451 Views
3 Replies
Replies (3)
Message 2 of 4

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

Hope the following VBA macro helps a bit. It assumes the directory is C:\temp. And it will find out the sheetmetal part and adds one custom propertyset & property.

 

Sub addiPtoSM()

Dim oPathName As String
oPathName = "c:\temp"

 

Dim oPartDoc As Document

 Dim oFileName As String
 Dim lsFile As String
 lsFile = Dir(oPathName & "\*.ipt", vbNormal)


 On Error Resume Next

 Do While lsFile <> ""

     Set oPartDoc = ThisApplication.Documents.Open(oPathName & "\" & lsFile, False)
     ' is sheet metal part
     If oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
        
        Dim oNewPropertySet As PropertySet
        Set oNewPropertySet = oPropsets.Item("New PropertySet")

        ' If PropertySet does not exist then add the new PropertySet
         If Err Then
             ' Add the new PropertySet
             Set oNewPropertySet = oPropsets.Add("New PropertySet")
   
             ' Adding the new Property to the new PropertySet
           Call oNewPropertySet.Add("A Value", "New Property", 2)
        End If
        oPartDoc.Save
       
     End If
    
   
    oPartDoc.Close
    lsFile = Dir
Loop

End Sub

 

Regards,

Xiaodong Liang

Developer Technical Services

0 Likes
Message 3 of 4

brendan.henderson
Advisor
Advisor

Thanks for that. I'm a newbie at VBA so a bit more detail would be appreciated.

 

Specifically I want to add a new iProp to Custom tab, call the iProp "Pierces" and set the Type as number.

 

I can't figure out what code to change in the macro to make this happen.

Brendan Henderson
CAD Manager


New Blog | Old Blog | Google+ | Twitter


Inventor 2016 PDSU Build 236, Release 2016.2.2, Vault Professional 2016 Update 1, Win 7 64 bit


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 4 of 4

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

The code is updated. You would need to adjust till it meets your requirement. Please refer to the topic: Document Properties in API help document  and  for more details on relevant API. Also the webcast class:

http://www.adskconsulting.com/adn/cs/api_course_webcast_archive.php 

 

Sub addiPtoSM()

Dim oPathName As String
oPathName = "c:\temp"

 

Dim oPartDoc As Document

 Dim oFileName As String
 Dim lsFile As String
 lsFile = Dir(oPathName & "\*.ipt", vbNormal)


Dim oFM As FileManager
Set oFM = ThisApplication.FileManager


 'On Error Resume Next

 Do While lsFile <> ""

     Dim oFullFileName As String
     oFullFileName = oPathName & "\" & lsFile   
     
       
        Set oPartDoc = ThisApplication.Documents.Open(oFullFileName, False)
   
           ' is sheet metal part
         If oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
            
             'get default property set >> custom property
            Dim oCustomPropertySet As PropertySet
            'suggest use GUID, which is independent with language
            Set oCustomPropertySet = oPartDoc.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
                        
                Dim oDoubleV As Double
                oDoubleV = 1234567#
               
                Dim oProId As Integer
                oProId = 2   ' assumes this property is numbered 2
               
                 ' Adding the new Property to the new PropertySet
               Call oCustomPropertySet.Add(oDoubleV, "Pierces", 2)
          
            oPartDoc.Save
           
         End If
    
    oPartDoc.Close
        
    lsFile = Dir
Loop

End Sub

 

 

Regards,

Xiaodong Liang

Developer Technical Services

0 Likes