Adding ModelFeatureControlFrame in PartDocument via VBA code

by Chandra shekar Gopal

In a PartDocument, ModelFeatureControlFrame is added through Inventor API by creating of definition of ModelFeatureControlFrameDefinition. Along with definition, at least one ModelFeatureControlFrameRow should be added to ModelFeatureControlFrameDefinition. Otherwise, ModelFeatureControlFrame.Add() method failed to generate ModelFeatureControlFrame.

Usually, ModelFeatureControlFrameDefinition are defined with geometry intent, Annotation Plane definition and Point to locate ModelFeatureControlFrameRow.

To demonstrate this, a sample part can be downloaded from this link

After downloading the part, open the same part in Inventor. Copy and paste below VBA code in VBA editor.

VBA code: 


Sub Main()

    Dim doc As PartDocument
    Set doc = ThisApplication.ActiveDocument

    Dim oDef As PartComponentDefinition
    Set oDef = doc.ComponentDefinition

    Dim oFace As Face
    Set oFace = ThisApplication.CommandManager.Pick(kPartFaceFilter, "Select a face to add Model feature control frame")

    Dim oAnnotationPlaneDef As AnnotationPlaneDefinition
    Set oAnnotationPlaneDef = oDef.ModelAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(oFace)

    ' Set a reference to the TransientGeometry object.
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry

    Dim oIntent As GeometryIntent
    Set oIntent = oDef.CreateGeometryIntent(oFace)

    Dim oPt As Point
    Set oPt = oTG.CreatePoint(12, 15, 0)

    Dim oMFCFDef As ModelFeatureControlFrameDefinition
    Set oMFCFDef = oDef.ModelAnnotations.ModelFeatureControlFrames.CreateDefinition(oIntent, oAnnotationPlaneDef, oPt)

    Dim oMFCFRow As ModelFeatureControlFrameRow
    Set oMFCFRow = oMFCFDef.FeatureControlFrameRows.Add(kFlatness, 0.02)

    Dim oMFCF As ModelFeatureControlFrame
    Set oMFCF = oDef.ModelAnnotations.ModelFeatureControlFrames.Add(oMFCFDef)

End Sub

On successful running code, a prompt will pop up which is looking for face selection as shown below image.

image

Output:

image

 

Try below VBA code to add ModelGeneralNote into PartDocument.

Sub ModelGeneralNote()

    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument

    Dim oDef As PartComponentDefinition
    Set oDef = oDoc.ComponentDefinition

    Dim oDescription As String
    oDescription = "<styleoverride><property document="model" propertyset="Design Tracking Properties" property="Description" formatid="{32853F0F-3444-11D1-9E93-0060B03C1CA6}" propertyid="29">DESCRIPTION</property></styleoverride>"

    Dim oTitle As String
    oTitle = "<styleoverride><property document="model" propertyset="Inventor Summary Information" property="Title" formatid="{F29F85E0-4FF9-1068-AB91-08002B27B3D9}" propertyid="2">TITLE</property></styleoverride>"

    Dim oText As String
    oText = oDescription & oTitle

    Dim oModeldef As ModelGeneralNoteDefinition
    Set oModeldef = oDef.ModelAnnotations.ModelGeneralNotes.CreateDefinition(oText, True)

    Dim oNote As ModelGeneralNote
    Set oNote = oDef.ModelAnnotations.ModelGeneralNotes.Add(oModeldef)

End Sub

Comments

2 responses to “Adding ModelFeatureControlFrame in PartDocument via VBA code”

  1. Liansuo Xie Avatar
    Liansuo Xie

    Hi Chandra,
    Thanks for sharing the knowledge.
    This is indeed very useful.
    Could you please show an example on Adding a ModelGeneralNote with formatted text
    linked to file property (such as “Title” and “Description”)?
    Thanks,
    Liansuo Xie

  2. Hi Liansuo,
    Blog content is updated with VBA code to add ModelGeneralNote into PartDocument.
    Thanks and regards,
    Chandra shekar G

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading