Model leader note annotation point collection

Model leader note annotation point collection

wmgshurik
Enthusiast Enthusiast
296 Views
2 Replies
Message 1 of 3

Model leader note annotation point collection

wmgshurik
Enthusiast
Enthusiast

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);
}

0 Likes
Accepted solutions (1)
297 Views
2 Replies
Replies (2)
Message 2 of 3

abdullah_elq
Advocate
Advocate
Accepted solution

According to my understanding of the ModelLeaderNotes.CreateDefinition Method only the last item in the collection (even if it is the only item) can be a GeometryIntent object. The rest should be Point objects. 

 

Let me know if that works for you.

Message 3 of 3

wmgshurik
Enthusiast
Enthusiast

You are absolutely correct!

Thank you very much!

 

 

That is the code

 

public void CreateTechNumberAnnotation(ComponentOccurrence occ, string techNumber)
{
    if (techNumber == string.Empty) { return; }
    AssemblyComponentDefinition topCompDef = occ.Parent;
    Application invApp = occ.Application;
    TransientGeometry tg = invApp.TransientGeometry;

    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);

 

    //text point
    Matrix rootPosition = occ.Transformation;
    double textX = rootPosition.Cell[1, 4] + 30;
    double textY = rootPosition.Cell[2, 4] + 30;
    double textZ = rootPosition.Cell[3, 4];
    Point endPoint = tg.CreatePoint(textX, textY, textZ);

 

    //annotation plane will parallel to front view
    WorkPlane workPlane = topCompDef.WorkPlanes[3];
    AnnotationPlaneDefinition annotationPlaneDef = topCompDef.ModelAnnotations.CreateAnnotationPlaneDefinitionUsingPlane(workPlane);

    ObjectCollection objects = invApp.TransientObjects.CreateObjectCollection();
    objects.Add(endPoint);
    objects.Add(intentRoot);

 

    ModelLeaderNoteDefinition leaderDef =  topCompDef.ModelAnnotations.ModelLeaderNotes.CreateDefinition(objects, techNumber, annotationPlaneDef);
    ModelLeaderNote modelLeaderNote = topCompDef.ModelAnnotations.ModelLeaderNotes.Add(leaderDef);

    string name = techNumber + $"___suff{DateTime.Now:ffff}"; 
    modelLeaderNote.Name = name;
}