Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
wmgshurik
239 Views, 2 Replies

Model leader note annotation point collection

Hello friends!

 

I don't undarstand, why this code doesnt work.

I catch Argument Exception in .ModelLeaderNotes.CreateDefinition method.

 

If "ObjectCollection objects" has one point - it works, if it has more points - not works..

All points lie on the same plane. Documentation says thet Inventor project this points on the plane.

   

public void CreateTechNumberAnnotation(DependencyObjects DO, ComponentOccurrence occ)
{
    AssemblyComponentDefinition topCompDef = occ.Parent;

    WorkPlane workPlane;
    WorkPoints workPoints;
    if (occ.ReferencedFileDescriptor.FullFileName.EndsWith("iam"))
    {
        workPoints = ( (AssemblyDocument)occ.Definition.Document ).ComponentDefinition.WorkPoints;
    }
    else
    {
        workPoints = ( (PartDocument)occ.Definition.Document ).ComponentDefinition.WorkPoints;
    }

    //occ original point
    occ.CreateGeometryProxy(workPoints[1], out object temp);
    var workPointProxy = (WorkPointProxy)temp;
    GeometryIntent intentRoot = topCompDef.CreateGeometryIntent(workPointProxy);

   //occ last point
    Point endPoint = DO.TG.CreatePoint(workPoints[1].Point.X + 10, workPoints[1].Point.Y + 10, workPoints[1].Point.Z);
    workPoints.AddFixed(endPoint);

    endPoint = DO.TG.CreatePoint(workPoints[workPoints.Count].Point.X, workPoints[workPoints.Count].Point.Z,                workPoints[workPoints.Count].Point.Z);
    workPoints.AddFixed(endPoint);

    occ.Definition.Document.Update2();

    occ.CreateGeometryProxy(workPoints[workPoints.Count - 1], out temp);
    var workPointProxyText = (WorkPointProxy)temp;
    GeometryIntent intentText = topCompDef.CreateGeometryIntent(workPointProxyText);

    occ.CreateGeometryProxy(workPoints[workPoints.Count], out temp);
    var workPointProxyTextEnd = (WorkPointProxy)temp;
    GeometryIntent intentTextEnd = topCompDef.CreateGeometryIntent(workPointProxyTextEnd);


    workPlane = topCompDef.WorkPlanes[3];
    AnnotationPlaneDefinition annotationPlaneDef =         topCompDef.ModelAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(workPlane);

    ObjectCollection objects = DO.InvApp.TransientObjects.CreateObjectCollection();
    objects.Add(intentTextEnd);
    objects.Add(intentText);
    objects.Add(intentRoot);

    ModelLeaderNoteDefinition leaderDef = topCompDef.ModelAnnotations.ModelLeaderNotes.CreateDefinition(objects, "Text", annotationPlaneDef);
    topCompDef.ModelAnnotations.ModelLeaderNotes.Add(leaderDef);
}