[C#] autodesk inventor API – iProperty屬性

使用autodesk inventor API讀取文件中的Property
可以先閱讀前一篇
https://timshyue.com/autodesk-inventor-api-c-%e5%9f%ba%e6%9c%ac%e6%87%89%e7%94%a8%ef%bc%8c%e5%8f%a6%e5%ad%98%e6%88%90%e5%9c%96%e6%aa%94-idw-to-image-%ef%bc%8cipt-to-image-autodesk-inventor-%e4%ba%8c%e6%ac%a1/

參考:
https://modthemachine.typepad.com/my_weblog/2010/02/accessing-iproperties.html

得知分成三層:

iProperty對話框=> PropertySets

對話框中的選項卡 => PropertySet

特定的屬性 => Property

裡面的資料分成以下幾種型態

  • String
  • IPictureDisp
  • Currency
  • Date
  • Boolean
  • Long

除了IPictureDisp以外,其他的都可以轉成string(文字)

範例:取得資料
每層是一個集合,所以我使用foreach來做簡單的讀取

try
{
    Inventor.Document doc = m_application.ActiveDocument as Document;
    Inventor.PropertySets customPropSet = doc.PropertySets;
    LogMessage_Property(data2);
    foreach (Inventor.PropertySet propertySet in customPropSet)
    {
        try
        {
            LogMessage_Property(propertySet.Name + "/" + propertySet.InternalName);
            foreach (Inventor.Property Property in propertySet)
            {
                try
                {

                    LogMessage_Property("\t" + Property.Name + " /" + Property.PropId.ToString() + " /" + Property.Value);
                }
                catch (Exception mm)
                {
                    LogMessage_Property("Property\t\t" + mm.GetBaseException().Message);
                }
            }
        }
        catch (Exception mm)
        {

            LogMessage_Property("propertySet\t\t" + mm.GetBaseException().Message);
        }

    }
}
catch (Exception m)
{
    LogMessage_Property("PropertySets\t" + m.GetBaseException().Message);
}

可以得到類似下面的結果:

Inventor Summary Information/{F29F85E0-4FF9-1068-AB91-08002B27B3D9}.
Title /2 /text.
Subject /3 /.
Author /4 /Author.
Keywords /5 /.
Comments /6 /.
Last Saved By /8 /.
Revision Number /9 /.
Property 災難性的失敗 (發生例外狀況於 HRESULT: 0x8000FFFF (E_UNEXPECTED)).
Inventor Document Summary Information/{D5CDD502-2E9C-101B-9397-08002B2CF9AE}.
Category /2 /原料.
Manager /14 /.
Company /15 /.
Design Tracking Properties/{32853F0F-3444-11D1-9E93-0060B03C1CA6}.
Creation Time /4 /2014/6/12 下午 05:35:01.
Part Number /5 /M160110013.
Project /7 /.
Cost Center /9 /.
Checked By /10 /.
Date Checked /11 /1601/1/1 上午 12:00:00.
Engr Approved By /12 /.
Engr Date Approved /13 /1601/1/1 上午 12:00:00.
User Status /17 /.
Material /20 /FC25.
Part Property Revision Id /21 /{79762A94-73E9-40A6-9EA7-FC7FA86D5476}.
Catalog Web Link /23 /.
Property 災難性的失敗 (發生例外狀況於 HRESULT: 0x8000FFFF (E_UNEXPECTED)).
Description /29 /.
Vendor /30 /廠商.
Document SubType /31 /{4D29B490-49B2-11D0-93C3-7E0706000000}.
Document SubType Name /32 /SubType.
Proxy Refresh Date /33 /1601/1/1 上午 12:00:00.
Mfg Approved By /34 /.
Mfg Date Approved /35 /1601/1/1 上午 12:00:00.
Cost /36 /0.0000.
Standard /37 /.
Design Status /40 /1.
Designer /41 /設計者.
Engineer /42 /.
Authority /43 /.
Parameterized Template /44 /False.
Template Row /45 /.
External Property Revision Id /46 /{4D29B490-49B2-11D0-93C3-7E0706000000}.
Standard Revision /47 /.
Manufacturer /48 /.
Standards Organization /49 /.
Language /50 /.
Defer Updates /51 /False.
Size Designation /52 /.
Categories /56 /.
Stock Number /55 /.
Weld Material /57 /.
Mass /58 /22390.5488908168.
SurfaceArea /59 /8584.56955353982.
Volume /60 /3046.33318242406.
Density /61 /7.35.
Valid MassProps /62 /31.
Flat Pattern Width /63 /0.
Flat Pattern Length /64 /0.
Flat Pattern Area /65 /0.
Sheet Metal Rule /66 /.
Last Updated With /67 /2019 (Build 230136000, 136).
Sheet Metal Width /68 /.
Sheet Metal Length /69 /.
Sheet Metal Area /70 /.
Material Identifier /71 /D:\test.ipt.adsklib#1:FC25
MaterialInv_103.
Appearance /72 /鋼鐵藍. Flat Pattern Defer Update /73 /False.
Inventor User Defined Properties/{D5CDD505-2E9C-101B-9397-08002B2CF9AE}.
自訂屬性 /12 /我是自訂的