Getting ModelFeatureControlFrames in PartDocument via VBA code

By Chandra shekar Gopal

In a PartDocument, hoping that ModelFeatureControlFrames can be retrieved from “ModelFeatureControlFrames” Inventor API. Instead of this, ModelFeatureControlFrames are encapsulated in “ModelCompositeAnnotations”.

Annotations in ModelCompositeAnnotations doesn’t count only the number of ModelFeatureControlFrames. It also includes variety of annotations.

To demonstrate this, a sample part can be downloaded from this Link which looks as shown below. In this part, there are 9 FeatureControlFrames and 8 FeatureControlFrames as base in composite.

ModelFeatureControlFrame

VBA code:

Sub Main()

    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument

    Dim compDef As PartComponentDefinition
    Set compDef = oDoc.ComponentDefinition

    Dim cnt As Integer
    cnt = compDef.ModelAnnotations.ModelFeatureControlFrames.Count

    Dim compositeCnt As Integer
    compositeCnt = compDef.ModelAnnotations.ModelCompositeAnnotations.Count

    Dim fcfCnt As Integer
    fcfCnt = 0

    Dim fcfBaseCnt As Integer
    fcfBaseCnt = 0

    For Each CompositeAnnotation In compDef.ModelAnnotations.ModelCompositeAnnotations

        For Each childAnno In CompositeAnnotation.Definition.Annotations

            If childAnno.Type = kModelFeatureControlFrameObject Then

                fcfCnt = fcfCnt + 1

                Dim fcf As ModelFeatureControlFrame
                Set fcf = childAnno
                fcf.Definition.FeatureControlFrameRows.Item(1).DisplayFreeStateModifier = True

            End If

        Next

        If CompositeAnnotation.Definition.BaseAnnotation.Type = kModelFeatureControlFrameObject Then

            fcfBaseCnt = fcfBaseCnt + 1

            Dim fcfBase As ModelFeatureControlFrame
            Set fcfBase = CompositeAnnotation.Definition.BaseAnnotation
            fcfBase.Definition.FeatureControlFrameRows.Item(1).DisplayTangentPlaneModifier = True

        End If

    Next

    Debug.Print "standalone FCFs"; cnt
    Debug.Print "Copmosite annotations"; compositeCnt
    Debug.Print "FCFs in Composite"; fcfCnt
    Debug.Print "FCFs as Base in Composite"; fcfBaseCnt

End Sub

Result for sample part:

standalone FCFs 0

Copmosite annotations 9

FCFs in Composite 9

FCFs as Base in Composite 8

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading