Results 1 to 3 of 3

Thread: Creating an annotative block

  1. #1
    Member
    Join Date
    2008-06
    Posts
    11
    Login to Give a bone
    0

    Default Creating an annotative block

    Having trawled forum after forum...

    I've got .Net code that is creating a brand new block in a drawing file in AutoCAD 2010. So far this is all working nicely, making allowances for any user UCS in use and the necessary rotations, etc.

    Now I'm trying to make my brand new block annotative at the time of creation.

    I've tried to adapt the code from Kean Walmsleys 'Throught the Interface' article here, however it throws an eInvalidInput exception whenever I get to the 'obj.Annotative = Annotative.True;' line.

    Of course this code is making an existing object annotative and doesn't accommodate blocks. There may be something in that, but blocks can be annotative after all.

    I've tried a number of alternatives from attempting to assign the annotative directly to the BlockReference:

    Code:
    AcDBS.BlockTableRecord ms = (AcDBS.BlockTableRecord)tr.GetObject(bt[AcDBS.BlockTableRecord.ModelSpace], AcDBS.OpenMode.ForWrite);
    AcGeom.Point3d InsPoint = Utilities.Get3dPt(doc, "Pick a top left location for the sign");
    InsPoint = Utilities.TranslateCoordinates(doc, InsPoint);
    AcDBS.BlockReference br = new AcDBS.BlockReference(InsPoint, btrId);
    br.Rotation = rotAngle;
    br.Annotative = AcDBS.AnnotativeStates.True;
    br.AddContext(occ.GetContext(curAnnoScale));
    ms.AppendEntity(br);
    tr.AddNewlyCreatedDBObject(br, true);
    to capturing the BlockReference Id and doing it Kean's way.

    Code:
    AcDBS.DBObject obj = tr.GetObject(br.ObjectId, AcDBS.OpenMode.ForRead);
    if (obj != null)
    {
     obj.UpgradeOpen();
     obj.Annotative = AcDBS.AnnotativeStates.True;
     obj.AddContext(occ.GetContext(curAnnoScale));
    }
    Any clues as to which to hold my tongue, and do I point east or west?

  2. #2
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    202
    Login to Give a bone
    0

    Default Re: Creating an annotative block

    Hi,

    Is the block defintion (BlockTableRecord) annotative ?

    Here's a little snippet working for me.
    If the block definition doesn't already exist in the drawing block table, it is created, and made annotative. Then the block is inserted at specified point according to the current annotative scale.

    Code:
            [CommandMethod("Test")]
            public void Test()
            {
                Document doc = AcAp.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                Editor ed = doc.Editor;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
    
                    // if the block table doesn't already contain the block definition, create it
                    if (!bt.Has("foo"))
                    {
                        BlockTableRecord btr = new BlockTableRecord();
                        btr.Name = "foo";
                        // make the block annotative
                        btr.Annotative = AnnotativeStates.True; 
                        bt.Add(btr);
                        tr.AddNewlyCreatedDBObject(btr, true);
                        // add some entities to the block definition
                        Circle c = new Circle(Point3d.Origin, Vector3d.ZAxis, 1.0);
                        btr.AppendEntity(c);
                        tr.AddNewlyCreatedDBObject(c, true);
                        Line l = new Line(new Point3d(-1.2, 0.0, 0.0), new Point3d(1.2, 0.0, 0.0));
                        btr.AppendEntity(l);
                        tr.AddNewlyCreatedDBObject(l, true);
                    }
                    // insert the block in the current space
                    PromptPointResult ppr = ed.GetPoint("\nInsertion point: ");
                    if (ppr.Status != PromptStatus.OK) 
                        return;
                    BlockTableRecord space =
                        (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    ObjectContextCollection occ = 
                        db.ObjectContextManager.GetContextCollection("ACDB_ANNOTATIONSCALES");
                    Matrix3d ucs = ed.CurrentUserCoordinateSystem;
                    Point3d pt = ppr.Value;
                    BlockReference br = new BlockReference(pt, bt["foo"]);
                    br.TransformBy(ucs);
                    br.AddContext(occ.CurrentContext);
                    space.AppendEntity(br);
                    tr.AddNewlyCreatedDBObject(br, true);
                    tr.Commit();
                }
            }

  3. #3
    Member
    Join Date
    2008-06
    Posts
    11
    Login to Give a bone
    0

    Default Re: Creating an annotative block

    Thanks. That did it.

    The clue was applying 'Annotative' at the BlockTableRecord (btr) rather than the BlockRecord (br).

    I guess that this makes sense when you consider how a block is both defined and used.

    Thanks also for the 'occ.CurrentContext' suggestion.

    A very helpful response.

Similar Threads

  1. 2014: Non annotative entity in an annotative block
    By matthew.221135 in forum AutoCAD General
    Replies: 3
    Last Post: 2013-11-17, 10:50 PM
  2. 2011: annotative text and annotative block failure
    By kuruczregina in forum ACA General
    Replies: 0
    Last Post: 2012-03-25, 06:56 PM
  3. Annotative Attribute in Non-Annotative Block
    By c.mcmahon in forum AutoCAD Annotation
    Replies: 5
    Last Post: 2010-04-09, 08:23 PM
  4. Replies: 3
    Last Post: 2009-10-08, 09:01 AM
  5. Annotative attribute in non-annotative block
    By thegreyguy in forum AutoCAD Annotation
    Replies: 0
    Last Post: 2009-07-24, 03:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •