.NET
cancel
Showing results forĀ 
ShowĀ Ā onlyĀ  | Search instead forĀ 
Did you mean:Ā 

Block parent layout name

1 REPLY 1
Reply
Message 1 of 2
Amremad
264 Views, 1 Reply

Block parent layout name

Hi every one ..

 

How Can I know the name of Block parent Layout?

1 REPLY 1
Message 2 of 2
Hallex
in reply to: Amremad

Try this code, wriiten in a hurry, so check on possible errors:

        [CommandMethod("ltname")]
        public void LayoutNameOfBlockRef()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
         Transaction tr = doc.TransactionManager.StartTransaction();

         using (tr)
         {

             PromptEntityOptions peo = new PromptEntityOptions("\nSelect block >>");
             peo.SetRejectMessage("\nSelect block only >>");
             peo.AddAllowedClass(typeof(BlockReference), false);
             PromptEntityResult res;
             res = ed.GetEntity(peo);
             if (res.Status != PromptStatus.OK)
                 return;
             Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
             if (ent == null)
                 return;
             BlockReference br = (BlockReference)ent as BlockReference;
             DBObject obj = tr.GetObject(br.OwnerId, OpenMode.ForRead);
             BlockTableRecord lbtr = tr.GetObject(br.OwnerId, OpenMode.ForRead) as BlockTableRecord;
             ObjectId ltId = lbtr.LayoutId;
             Layout lt = tr.GetObject(ltId, OpenMode.ForRead) as Layout;
             Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("BlockReference belongs to tab: " + lt.LayoutName);
             tr.Commit();
         }
    }

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

ā€Boost