iProperties "Location" using VBA

iProperties "Location" using VBA

isocam
Collaborator Collaborator
864 Views
3 Replies
Message 1 of 4

iProperties "Location" using VBA

isocam
Collaborator
Collaborator

Can anybody help???

 

How can I get the "Location" iProperty using Inventors VBA?

 

Please see the attached picture!

 

I am using the following code to get other iProperties, thus.....

 

Set oStockNumberProperty = oCompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Stock Number")
        
StockNumber = Trim(oStockNumberProperty.Value)

 

This works OK.

 

Many thanks in advance!!!!

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

Vladimir.Ananyev
Alumni
Alumni

Location of the opened Inventor document can be easily found from its full file name. Here is the VBA sample:

Private Sub GetLocation_2()
  Dim oDoc As Inventor.Document
  Set oDoc = ThisApplication.ActiveDocument  
  Dim Filename As String
  Filename = oDoc.FullFileName  
  Debug.Print Location(Filename)
End Sub

Function Location(Filename As String) As String
  Location = Left(Filename, InStrRev(Filename, "\") - 1)
End Function

 

If you need an access to another file-related utility functions you may also consider Inventor.FileManager object functionality.  For example folder name can be found using powerful FileSystemObject that provides access to a computer's file system (see Microsoft VBA help on FileSystemObject methods and properties).

Private Sub GetLocation_1()
  
  Dim oDoc As Inventor.Document
  Set oDoc = ThisApplication.ActiveDocument
  Dim Filename As String
  Filename = oDoc.FullFileName
  
  Dim FSO As Object
  Set FSO = ThisApplication.FileManager.FileSystemObject
  
  Dim FolderName As String
  FolderName = FSO.GetParentFolderName(Filename)
  
  Debug.Print FolderName
  
End Sub

Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 4

isocam
Collaborator
Collaborator

Hi,

 

Thanks for the reply.

 

I should of mentioned that the "Location" property I require is part of a BOM export VBA module.

 

Here is a bigger snippet of code (reduced from its original to post to the forum)

 

Public Function QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator)
    For Counter = 1 To oBOMRows.Count
        Dim oRow As BOMRow

        Set oRow = oBOMRows.Item(Counter)

        Dim oCompDef As ComponentDefinition

        Set oCompDef = oRow.ComponentDefinitions.Item(1)

PROBLEM LINE!!!!
        Set oLocationProperty = oCompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Location")

        Set oPartNumberProperty = oCompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Part Number")

        Set oDescriptionProperty = oCompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Description")
       
        Set oStockNumberProperty = oCompDef.Document.PropertySets.Item("Design Tracking Properties").Item("Stock Number")

        Location = Trim(oLocationProperty.Value)

        PartNumber = Trim(oPartNumberProperty.Value)

        Description = UCase$(Trim(oDescriptionProperty.Value))

        StockNumber = Trim(oStockNumberProperty.Value)

        Quantity = Val(oRow.ItemQuantity)

        ItemNumber = oRow.ItemNumber

        If Not oRow.ChildRows Is Nothing Then Call QueryBOMRowProperties(oRow.ChildRows)
    Next
End Function

 

Everything else (Description, Stocknumber etc works fine, its just the "Location" property that is the problem!

 

Can you help?

 

Kindest Regards

 

IsoCAM

0 Likes
Message 4 of 4

Vladimir.Ananyev
Alumni
Alumni

There is no iProperty "Location" among Inventor predefined properties.   Try the following VBA sample - it prints names of all existing iPrpperties.

Private Sub PrintAllPropNames()

  Dim oDoc As Inventor.Document
  Set oDoc = ThisApplication.ActiveDocument
  
  Dim oPropSet As PropertySet
  Dim oProp As Inventor.Property
  
  For Each oPropSet In oDoc.PropertySets
    Debug.Print oPropSet.Name
    For Each oProp In oPropSet
      Debug.Print "    " & oProp.Name
    Next
  Next
  
  Beep
End Sub

 Nevertheless you are able to get the reference to the Document object from BOMRow and then you can get the current  file locatio. Methodsn were described above.

Cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

0 Likes