• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Member
    Posts: 3
    Registered: ‎09-14-2005

    Silly question

    69 Views, 5 Replies
    09-14-2005 03:32 PM
    Hello,

    I've got a block reference called unitBREF. How do I determine its name? I've seen the other posts on names but for some reason I'm having trouble getting the BlockTableRecord:

    BlockReference unitBREF = (BlockReference)ent;
    BlockTableRecord blkBTR = ???
    string name = blkBTR.name;

    Thanks very much for any help!
    -Carlos
    Please use plain text.
    Member
    Posts: 3
    Registered: ‎09-14-2005

    Re: Silly question

    09-14-2005 03:33 PM in reply to: Carlos Cabrera
    BTW,

    I'm using C# with AutoCAD 2006 and VS 2003.

    -C
    Please use plain text.
    Active Member
    Posts: 10
    Registered: ‎05-31-2005

    Re: Silly question

    09-14-2005 03:42 PM in reply to: Carlos Cabrera
    Hey Carlos,

    Try this (I'm assuming you've already got a transaction object in your routine):

    BlockTableRecord blkBTR = (BlockTableRecord)trans.GetObject(unitBREF.BlockTableRecord, OpenMode.ForWrite);
    Please use plain text.
    Active Member
    Posts: 10
    Registered: ‎05-31-2005

    Re: Silly question

    09-14-2005 03:44 PM in reply to: Carlos Cabrera
    Just realized I wrote OpenMode.ForWrite in my reply. That will work, but there's no reason why OpenMode.ForRead wouldn't also work.
    Please use plain text.
    Member
    Posts: 3
    Registered: ‎09-14-2005

    Re: Silly question

    09-14-2005 06:11 PM in reply to: Carlos Cabrera
    Hi,

    For some reason, "BlockTableRecord" is not listed as a method or member variable of my block reference by Visual Studio. Is it possible that I don't have the correct namespace added? For this reason, I thought I must be doing something wrong.

    In spite of this, I made it unitBREF.BlockTableRecord and it works great! Thanks very much for your help.

    -Carlos
    Please use plain text.
    *Albert Szilvasy

    Re: Silly question

    09-16-2005 03:38 PM in reply to: Carlos Cabrera
    Try this:
    public string GetBlockName(ObjectId idRef)
    {
    using (Transaction t =
    idRef.Database.TransactionManager.StartTransaction())
    {
    BlockReference bref = (BlockReference)t.GetObject(idRef,
    OpenMode.ForRead);
    BlockTableRecord btr =
    (BlockTableRecord)t.GetObject(bref.BlockId,OpenMode.ForRead);
    return btr.Name;
    }
    }

    wrote in message news:4956854@discussion.autodesk.com...
    Hi,

    For some reason, "BlockTableRecord" is not listed as a method or member
    variable of my block reference by Visual Studio. Is it possible that I
    don't have the correct namespace added? For this reason, I thought I must
    be doing something wrong.

    In spite of this, I made it unitBREF.BlockTableRecord and it works great!
    Thanks very much for your help.

    -Carlos
    Please use plain text.