I’m trying to add annotations for every hole about thread description. I achieved adding names or dimensions to all of holes in part. But I wanted to add thread description like m16 etc…
I tried something like this but I got error and all of my annotations in middle of the 0 0 0 pozition. Is this possible writing come close to holes? But main problem is not getting thread descriptions.
Here is what I did in my code:
private void button1_Click(object sender, EventArgs e)
{
try
{
// CATIA'yı başlat
Type catiaType = Type.GetTypeFromProgID("CATIA.Application");
if (catiaType == null)
{
MessageBox.Show("CATIA uygulaması bulunamadı.");
return;
}
INFITF.Application catiaApp = (INFITF.Application)Activator.CreateInstance(catiaType);
if (catiaApp == null)
{
MessageBox.Show("CATIA uygulaması başlatılamadı.");
return;
}
// Açık olan belgeyi al
Documents documents = catiaApp.Documents;
if (documents.Count == 0)
{
MessageBox.Show("Açık belge bulunamadı.");
return;
}
PartDocument partDoc = (PartDocument)documents.Item(1);
Part part = partDoc.Part;
// AnnotationSets ve diğer öğeleri al
AnnotationSets annotationSets = (AnnotationSets)part.AnnotationSets;
AnnotationSet annotationSet = annotationSets.Add("ISO_3D");
Bodies bodies = part.Bodies;
Body body = bodies.Item("PartBody");
Shapes shapes = body.Shapes;
AnnotationFactory annotationFactory = annotationSet.AnnotationFactory;
int i = 0;
foreach (Shape shape in shapes)
{
if (shape is Hole hole)
{
i++;
// Deliğin çapını al
double diameter = hole.Diameter.Value;
// Deliğin metrik tanımını al
KnowledgewareTypeLib.StrParam strParam = hole.HoleThreadDescription;
string metric = strParam.get_Value();
// Kullanıcı yüzeyini oluşturmak için doğrudan Reference kullanma
Reference reference = part.CreateReferenceFromObject(shape);
// Referansı UserSurface olarak kullanma
UserSurface userSurface = (UserSurface)reference;
// Açıklama oluşturma
Annotation annotation = annotationFactory.CreateEvoluateText(userSurface, 0, 0, 0, true);
// Açıklama metnini ayarlama
annotation.set_Name(metric);
part.Update();
}
}