Tableau ligne lettre et chiffre sous autocad

Contenu du snippet

/*
  • Created by SharpDevelop.
  • Date: 18/08/2019
  • Time: 16:25
  • To change this template use Tools | Options | Coding | Edit Standard Headers.
  • /

using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

namespace MyFirstProject1

{
  public class TabCar
   {

   [CommandMethod("TabCars")]

 public static void TabCars()
  {
   string[] alpha = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
  
    // Le document courant et sa database
  
    Document acDoc = Application.DocumentManager.MdiActiveDocument;
  
    Database acCurDb = acDoc.Database;
  
    // lancement une  transaction
  
    using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
  
    {
        // Ouverture Block table en lecture
  
        BlockTable acBlkTbl;
  
        acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                     OpenMode.ForRead) as BlockTable;
  
        // Ouverture du Block table record de l'espace objet en ecriture
  
        BlockTableRecord acBlkTblRec;
  
        acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                        OpenMode.ForWrite) as BlockTableRecord;
  
    MText objText = new MText();
    
    // demande du nombre de colonne
    PromptStringOptions pStrOpts = new PromptStringOptions("nEntrer le nombre de colonne : ");
    pStrOpts.AllowSpaces = true;
    PromptResult pStprRes = acDoc.Editor.GetString(pStrOpts);
    int nbCol = Convert.ToInt32(pStprRes.StringResult);
    
    // demande du nombre de ligne
    pStrOpts = new PromptStringOptions("nEntrer le nombre de ligne : ");
    pStrOpts.AllowSpaces = true;
    pStprRes = acDoc.Editor.GetString(pStrOpts);
    int nbLig = Convert.ToInt32(pStprRes.StringResult);
    
     PromptPointResult pPtRes;
    PromptPointOptions pPtOpts = new PromptPointOptions("");
    // Prompt for the start point
    pPtOpts.Message = "nEntrer le point haut-gauche de la case : ";
    pPtRes = acDoc.Editor.GetPoint(pPtOpts);
    Point3d ptStart = pPtRes.Value;
    // Exit if the user presses ESC or cancels the command
    if (pPtRes.Status == PromptStatus.Cancel) return;
    
    // Prompt for the end point
    pPtOpts.Message = "nEntrer le point bas-droite de la case : ";
    pPtOpts.UseBasePoint = true;
    pPtOpts.BasePoint = ptStart;
    pPtRes = acDoc.Editor.GetPoint(pPtOpts);
    Point3d ptEnd = pPtRes.Value;
    // Exit if the user presses ESC or cancels the command
    if (pPtRes.Status == PromptStatus.Cancel) return;
    
    double dx = ptEnd.X - ptStart.X;
    double dy = ptEnd.Y - ptStart.Y;
  
    for(int lig=0;lig<nbLig;lig++){
     for(int col=0;col<nbCol;col++){
   
     /* Creation d un  new MText object et assignse la localisation, le text et le style  du text*/
     objText = new MText();
     
     // Set the default properties for the MText object
     objText.SetDatabaseDefaults();
     
     // Specifit le point d insertion du MText object
     
     objText.Location = new Autodesk.AutoCAD.Geometry.Point3d(ptStart.X + dx*col + dx/2 , ptStart.Y + dy*lig + dy/2 , 0);
     
     // Set the text string for the MText object
     
     objText.Contents = alpha [lig] + col.ToString();
     
     // Set the text style for the MText object
     
     objText.TextStyleId = acCurDb.Textstyle;
     
     // Ajout du nouveau MText object au model space
     
     acBlkTblRec.AppendEntity(objText);
     acTrans.AddNewlyCreatedDBObject(objText,true);
    }
        }
        // Save the new object to the database
        acTrans.Commit();
    }
  }
 }
}

Compatibilité : 1.0

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.