You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
La classe Leader représente une entité d'annotation ligne de repère dans AutoCAD. Une ligne de repère est une ligne ou une spline avec une pointe de flèche qui connecte un texte d'annotation ou des blocs à des caractéristiques spécifiques dans un dessin. Les lignes de repère sont couramment utilisées pour les étiquettes, notes et annotations dimensionnelles.
using(Transactiontr=db.TransactionManager.StartTransaction()){BlockTableRecordbtr=tr.GetObject(db.CurrentSpaceId,OpenMode.ForWrite)asBlockTableRecord;// Créer le repèreLeaderleader=newLeader();leader.SetDatabaseDefaults();// Ajouter des sommets (du point d'annotation vers l'élément)leader.AppendVertex(newPoint3d(10,10,0));// Point d'annotationleader.AppendVertex(newPoint3d(5,5,0));// Point coudéleader.AppendVertex(newPoint3d(0,0,0));// Point élément (flèche)// Définir les propriétésleader.HasArrowHead=true;leader.ColorIndex=1;// Rouge// Ajouter au dessinbtr.AppendEntity(leader);tr.AddNewlyCreatedDBObject(leader,true);// Évaluer pour mettre à jour la géométrieleader.EvaluateLeader();tr.Commit();}
Exemple 2: Créer un Repère avec Annotation Texte
using(Transactiontr=db.TransactionManager.StartTransaction()){BlockTableRecordbtr=tr.GetObject(db.CurrentSpaceId,OpenMode.ForWrite)asBlockTableRecord;// Créer l'annotation texteMTextmtext=newMText();mtext.SetDatabaseDefaults();mtext.Location=newPoint3d(10,10,0);mtext.Contents="Ceci est une note";mtext.TextHeight=2.5;ObjectIdmtextId=btr.AppendEntity(mtext);tr.AddNewlyCreatedDBObject(mtext,true);// Créer le repèreLeaderleader=newLeader();leader.SetDatabaseDefaults();leader.AppendVertex(newPoint3d(10,10,0));leader.AppendVertex(newPoint3d(5,5,0));leader.AppendVertex(newPoint3d(0,0,0));leader.HasArrowHead=true;// Attacher l'annotationleader.Annotation=mtextId;btr.AppendEntity(leader);tr.AddNewlyCreatedDBObject(leader,true);leader.EvaluateLeader();tr.Commit();}
Exemple 3: Créer un Repère Spline
using(Transactiontr=db.TransactionManager.StartTransaction()){BlockTableRecordbtr=tr.GetObject(db.CurrentSpaceId,OpenMode.ForWrite)asBlockTableRecord;Leaderleader=newLeader();leader.SetDatabaseDefaults();// Ajouter plusieurs sommets pour une courbe lisseleader.AppendVertex(newPoint3d(15,15,0));leader.AppendVertex(newPoint3d(12,10,0));leader.AppendVertex(newPoint3d(8,8,0));leader.AppendVertex(newPoint3d(5,5,0));leader.AppendVertex(newPoint3d(0,0,0));// Rendre en splineleader.IsSplined=true;leader.HasArrowHead=true;leader.ColorIndex=3;// Vertbtr.AppendEntity(leader);tr.AddNewlyCreatedDBObject(leader,true);leader.EvaluateLeader();tr.Commit();}
Exemple 4: Lire les Propriétés du Repère
using(Transactiontr=db.TransactionManager.StartTransaction()){Leaderleader=tr.GetObject(leaderId,OpenMode.ForRead)asLeader;ed.WriteMessage("\n=== Information Leader ===");ed.WriteMessage($"\nA une Flèche : {leader.HasArrowHead}");ed.WriteMessage($"\nA une Ligne Crochet : {leader.HasHookLine}");ed.WriteMessage($"\nEst Spline : {leader.IsSplined}");ed.WriteMessage($"\nNombre de Sommets : {leader.NumVertices}");ed.WriteMessage($"\nAnnotation : {leader.Annotation}");ed.WriteMessage("\n\nSommets :");for(inti=0;i<leader.NumVertices;i++){Point3dvertex=leader.GetVertexAt(i);ed.WriteMessage($"\n Sommet {i} : ({vertex.X:F2}, {vertex.Y:F2}, {vertex.Z:F2})");}tr.Commit();}
Exemple 5: Modifier les Sommets du Repère
using(Transactiontr=db.TransactionManager.StartTransaction()){Leaderleader=tr.GetObject(leaderId,OpenMode.ForWrite)asLeader;// Déplacer le sommet du milieuif(leader.NumVertices>=3){Point3dmiddleVertex=leader.GetVertexAt(1);Point3dnewVertex=newPoint3d(middleVertex.X+5,middleVertex.Y+5,middleVertex.Z);leader.SetVertexAt(1,newVertex);leader.EvaluateLeader();}tr.Commit();}
Exemple 6: Repère avec Annotation Bloc
using(Transactiontr=db.TransactionManager.StartTransaction()){BlockTablebt=tr.GetObject(db.BlockTableId,OpenMode.ForRead)asBlockTable;BlockTableRecordbtr=tr.GetObject(db.CurrentSpaceId,OpenMode.ForWrite)asBlockTableRecord;// Créer une référence de bloc (en supposant que le bloc "DetailCallout" existe)if(bt.Has("DetailCallout")){BlockReferenceblockRef=newBlockReference(newPoint3d(10,10,0),bt["DetailCallout"]);blockRef.SetDatabaseDefaults();ObjectIdblockRefId=btr.AppendEntity(blockRef);tr.AddNewlyCreatedDBObject(blockRef,true);// Créer le repèreLeaderleader=newLeader();leader.SetDatabaseDefaults();leader.AppendVertex(newPoint3d(10,10,0));leader.AppendVertex(newPoint3d(5,5,0));leader.AppendVertex(newPoint3d(0,0,0));leader.HasArrowHead=true;leader.Annotation=blockRefId;btr.AppendEntity(leader);tr.AddNewlyCreatedDBObject(leader,true);leader.EvaluateLeader();}tr.Commit();}
Exemple 7: Définir le Style de Dimension du Repère
using(Transactiontr=db.TransactionManager.StartTransaction()){Leaderleader=tr.GetObject(leaderId,OpenMode.ForWrite)asLeader;// Obtenir la table de style de dimensionDimStyleTabledst=tr.GetObject(db.DimStyleTableId,OpenMode.ForRead)asDimStyleTable;if(dst.Has("Annotative")){leader.DimStyle=dst["Annotative"];leader.EvaluateLeader();ed.WriteMessage("\nStyle de dimension 'Annotative' appliqué");}tr.Commit();}