Can't access drawing Property Sets

Can't access drawing Property Sets

Anonymous
Not applicable
1,244 Views
12 Replies
Message 1 of 13

Can't access drawing Property Sets

Anonymous
Not applicable

I am trying to access a drawing's custom iproperties using the following code.  When I Debug the customPropSet variable I get nothing, and when I run the complete macro it does not recognize the custom iproperty values.  Am I missing something?

 

 

    ' Get the active document.
    Dim drawDoc As Document
    Set drawDoc = ThisApplication.ActiveDocument
    
    ' Get the custom property set.
    Dim customPropSet As PropertySet
    Set customPropSet = drawDoc.PropertySets.Item("Inventor User Defined Properties")

    ' Get the custom property named "FRAME NUMBER".
    Dim frameNo As Property
    Set frameNo = customPropSet.Item("FRAME NUMBER")
    
    ' Get the custom property named "QUANTITY".
    Dim frameQty As Property
    Set frameQty = customPropSet.Item("QUANTITY")

Thanks in advance.

 

 

0 Likes
Accepted solutions (1)
1,245 Views
12 Replies
Replies (12)
Message 2 of 13

MechMachineMan
Advisor
Advisor

See additions below.

 

    On Error Resume Next ' Error handling in vba in case the Custom Property isn't yet made in the file 
' Get the active document. Dim drawDoc As Document Set drawDoc = ThisApplication.ActiveDocument ' Get the custom property set. Dim customPropSet As PropertySet Set customPropSet = drawDoc.PropertySets.Item("Inventor User Defined Properties") ' Get the custom property named "FRAME NUMBER". Dim frameNo As Property Set frameNo = customPropSet.Item("FRAME NUMBER").Value ' Get the custom property named "QUANTITY". Dim frameQty As Property Set frameQty = customPropSet.Item("QUANTITY").Value

 

 

 


 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 13

Anonymous
Not applicable

Thanks for the reply Justin.

 

I modified the code, but it is still not recognizing the customPropSet variable when I Debug it.

 

Gary

0 Likes
Message 4 of 13

MechMachineMan
Advisor
Advisor

    On Error Resume Next ' Error handling in vba in case the Custom Property isn't yet made in the file
'   Get the active document.
    Dim drawDoc As Document
    Set drawDoc = ThisApplication.ActiveDocument
   
    ' Get the custom property set.
    Dim customPropSet As PropertySet
    Set customPropSet = drawDoc.PropertySets.Item("Inventor User Defined Properties")

    ' Get the custom property named "FRAME NUMBER".
    Dim frameNo As String
    Set frameNo = customPropSet.Item("FRAME NUMBER").Value
   
    ' Get the custom property named "QUANTITY".
    Dim frameQty As String
    Set frameQty = customPropSet.Item("QUANTITY").Value

 

 

 

 

or you could always avoid the trouble and eat the insignificant loss in efficiency by directly calling it every time; ie;

 

 Dim frameQty As String
  Set frameQty = drawDoc.PropertySets.Item("Inventor User Defined Properties").Item("QUANTITY").Value


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 5 of 13

Anonymous
Not applicable

As usual, thanks for the reply Justin.

 

With your latest recommendations I get a compile error: Object required for the frameNo & frameQty variables.

 

Gary

0 Likes
Message 6 of 13

MechMachineMan
Advisor
Advisor
So you don't have the On Error Resume Next line in your program?

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 7 of 13

Anonymous
Not applicable

Yes I do.....

 

Public Sub ExportPartslisttoExcel()
    
    Dim FullFileName As String
    FullFileName = "\\SOTAWIN2\Drafting\Inventor\Templates\Frame Extraction Out.xls"
    
    On Error Resume Next ' Error handling in vba in case the Custom Property isn't yet made in the file
    'Get the active document.
    Dim drawDoc As Document
    Set drawDoc = ThisApplication.ActiveDocument
   
    ' Get the custom property set.
    Dim customPropSet As PropertySet
    Set customPropSet = drawDoc.PropertySets.Item("Inventor User Defined Properties")

    ' Get the custom property named "FRAME NUMBER".
    Dim frameNo As String
    Set frameNo = customPropSet.Item("FRAME NUMBER").Value
   
    ' Get the custom property named "QUANTITY".
    Dim frameQty As String
    Set frameQty = customPropSet.Item("QUANTITY").Value
0 Likes
Message 8 of 13

MechMachineMan
Advisor
Advisor
Seems like a vba problem which is beyond my skills. I would try the lines:
Set frameNo = "Test"

and see if that works, with the other relevant lines commented out.

I think the vba is having issues assigning the values to the variables, either because the type is off or the fetching of the properties is failing.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 9 of 13

MechMachineMan
Advisor
Advisor
Or try getting rid of the Set statements in front of frameNo and frameQty. Let me know how it works out!

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 10 of 13

Anonymous
Not applicable

Thanks anyway Justin.

 

I think you are right in that the problem seems to be a VBA issue.  For whatever reason it is not returning a value for drawDoc.PropertySets.Item when I run Debug.

 

Gary

0 Likes
Message 11 of 13

ekinsb
Alumni
Alumni
Accepted solution

I don't see any obvious problems with your code.  Below is a modification where I've created a little function that gets the value of the iProperty and will return an empty string in the case where the iProperty doesn't exist.

 

Public Sub TestCustomProps()
    ' Get the active document.
    Dim drawDoc As Document
    Set drawDoc = ThisApplication.ActiveDocument
    
    ' Get the custom property set.
    Dim customPropSet As PropertySet
    Set customPropSet = drawDoc.PropertySets.Item("Inventor User Defined Properties")

    ' Get the custom property named "FRAME NUMBER".
    Dim frameNo As String
    frameNo = GetProperty(customPropSet, "FRAME NUMBER")
    
    ' Get the custom property named "QUANTITY".
    Dim frameQty As String
    frameQty = GetProperty(customPropSet, "QUANTITY")
End Sub

Public Function GetProperty(PropSet As PropertySet, PropertyName As String) As Variant
    On Error Resume Next
    GetProperty = PropSet.Item(PropertyName).Value
    If Err Then
        GetProperty = ""
    End If
    On Error GoTo 0
End Function

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 12 of 13

Anonymous
Not applicable

Brian - once again you nailed it.

 

Thank you very much for your help.

 

Gary

0 Likes
Message 13 of 13

k14348
Advocate
Advocate

re.JPG

0 Likes