0

我正在使用 vb.net 进行 Inventor API 编程。我需要使用 api 更改材料并获取更新的体积。我这样编码。

Dim oDoc As PartDocument
        oDoc = inventorApp.ActiveDocument

        Dim oDTProps As PropertySet
        oDTProps = oDoc.PropertySets.Item("{32853F0F-3444-11d1-9E93-0060B03C1CA6}")
        Dim oDesignerProp As Inventor.Property
        oDesignerProp = oDTProps.ItemByPropId( _
        PropertiesForDesignTrackingPropertiesEnum.kMaterialDesignTrackingProperties)
        oDesignerProp = oDTProps.Item("Material")
        oDesignerProp.Value = "Titanium"
        oDoc.Update()

但在属性中,材料名称发生了变化,但没有更新质量和体积。有谁知道为什么?

4

1 回答 1

1

您必须找到材料并将其分配给组件定义。

        var app =(Application) System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
        var doc = app.ActiveDocument;
        var partDoc = (PartDocument)doc;
        var compDef = partDoc.ComponentDefinition;
        var mass1 = compDef.MassProperties.Mass;
        var mat =
            (from Material material in partDoc.Materials
             where material.Name == "Titan"
             select material).First();

        partDoc.ComponentDefinition.Material = mat;

        if (mat.StyleLocation == StyleLocationEnum.kLibraryStyleLocation)
            mat.ConvertToLocal();

        var mass2 = compDef.MassProperties.Mass;
于 2014-01-15T11:10:52.760 回答