- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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;
}