Accessing MultiViewBlockReference Definition using .NET API

By Saikat Bhattacharya

This post is to capture a question that was once asked by a partner who wanted to use the AutoCAD MEP .NET API to access the definition of a MultiViewBlockReference.

The definition of a MultiViewBlockReference is infact stored in the Style of the MultiViewBlockReference. Thus, using the StyleId property on a MultiViewBlockReference object, we can access its MultiViewBlockDefinition. The following code snippet shows the approach by accessing the name of the MultiViewBlockDefinition.

[Autodesk.AutoCAD.Runtime.CommandMethod(
      "TagTest", CommandFlags.Modal)]
    public void TagTestCmd()
    {
      Database db = HostApplicationServices.WorkingDatabase;
      using (Transaction trans = 
        db.TransactionManager.StartTransaction())
      {
        PromptEntityOptions peo = 
          new PromptEntityOptions("pick tag");
 
        peo.SetRejectMessage("nObject must be of type mvblock.");
        peo.AddAllowedClass(typeof(MultiViewBlockReference), true);
 
        Autodesk.AutoCAD.EditorInput.Editor ed = 
          Autodesk.AutoCAD.ApplicationServices
          .Application.DocumentManager.MdiActiveDocument.Editor;
 
        PromptEntityResult per = ed.GetEntity(peo);
        MultiViewBlockReference mvbr = 
          trans.GetObject(per.ObjectId, OpenMode.ForRead) 
          as MultiViewBlockReference;
 
        MultiViewBlockDefinition def = 
          trans.GetObject(mvbr.StyleId, OpenMode.ForRead) 
          as MultiViewBlockDefinition;
 
        System.Windows.Forms.MessageBox.Show(def.Name);
 
        trans.Commit();
      }
    }

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading