Author Topic: Question about block references in AutoCAD.  (Read 2292 times)

0 Members and 1 Guest are viewing this topic.

BillZndl

  • Guest
Question about block references in AutoCAD.
« on: July 16, 2014, 09:41:22 AM »
I noticed something when creating a new block reference in a drawing.
I thought I should be able to append the new blockReference to the blockTableRecord of that name, but it creates a duplicate block table record.
So appending the reference to the modelspace blocktablerecord works as expected but isn't the block reference owned by the blocktable record of that name?
I have both ways shown in the code below for an example.


Code: [Select]
//check for existence of block record.

                                    ObjectId bid = ObjectId.Null;
                                    bid = table[blkName];

                                    //if record exists.
                                    if (!bid.IsNull)
                                    {
                                        BlockTableRecord btr = (BlockTableRecord)transaction.GetObject(table[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                                        BlockTableRecord WBAY = (BlockTableRecord)transaction.GetObject(bid, OpenMode.ForWrite);

                                        //check for references in drawing.
                                        ObjectIdCollection oidc = WBAY.GetBlockReferenceIds(false, false);

                                        //if there are no existing references in the drawing.
                                        if (oidc.Count == 0)
                                        {
                                            //get scale information.
                                            ZoomToExtents(document);
                                            double vwsize = System.Convert.ToDouble(AcadApp.GetSystemVariable("VIEWSIZE"));
                                            ZoomToPercent(document);

                                            BlockReference bref = new BlockReference(Point3d.Origin, bid); //add new reference to database @ 0,0,0.

                                           > btr.AppendEntity(bref);  //if I use the modelspace  tablerecord, everything is fine.
                                           > WBAY.AppendEntity(bref);  //if I use the blocktablerecord of that name, it creates a circular (duplicate) block record(with not good results).

                                            transaction.AddNewlyCreatedDBObject(bref, true);

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Question about block references in AutoCAD.
« Reply #1 on: July 16, 2014, 04:27:51 PM »
Not sure what your question is.  The results you're getting are exactly as expected.  You cannot put a BlockReference inside the BlockTableRecord for that BlockReference.  Not sure of any any circumstance where you would want to.  The BlockReference is the "visual" side of the Block and needs to be in Modalspace so you can visually see it.
Revit 2019, AMEP 2019 64bit Win 10

BillZndl

  • Guest
Re: Question about block references in AutoCAD.
« Reply #2 on: July 16, 2014, 04:42:58 PM »
Not sure what your question is.  The results you're getting are exactly as expected.  You cannot put a BlockReference inside the BlockTableRecord for that BlockReference.  Not sure of any any circumstance where you would want to.  The BlockReference is the "visual" side of the Block and needs to be in Modalspace so you can visually see it.

I just thought that the blockTableRecord resided in the blockTable and the BlockReference resided in the blockTableRecord.
After all, you look at BlockTableRecord.GetBlockReferenceIds(); to get the number or references.
Guess I'd better quit thinking and look at the object model again. 

Thanks.

BlackBox

  • King Gator
  • Posts: 3770
Re: Question about block references in AutoCAD.
« Reply #3 on: July 16, 2014, 05:16:06 PM »
Not sure what your question is.  The results you're getting are exactly as expected.  You cannot put a BlockReference inside the BlockTableRecord for that BlockReference.  Not sure of any any circumstance where you would want to.  The BlockReference is the "visual" side of the Block and needs to be in Modalspace so you can visually see it.

I just thought that the blockTableRecord resided in the blockTable and the BlockReference resided in the blockTableRecord.
After all, you look at BlockTableRecord.GetBlockReferenceIds(); to get the number or references.
Guess I'd better quit thinking and look at the object model again. 

Building on MexicanCustard's comments, BlockReference inherits from Entity and has a BlockTableRecord Property that merely provides ObjectId to same, whereas BlockTableRecord (Block Definition) inherits from SymbolTableRecord... BlockReference simply 'references' the defining BlockTableRecord (Block Definition).

Hope that makes (more?) sense.
"How we think determines what we do, and what we do determines what we get."

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Question about block references in AutoCAD.
« Reply #4 on: July 16, 2014, 05:23:55 PM »
A BlockTableRecord is a container for entities.
A BlockReference is a way to draw each entity inside a BlockTableRecord and apply an transformations like position, rotation, scale to each entity.

Your printed output is basically just one BlockReference to ModelSpace.

When AutoCAD draws a BlockReference it gets the BlockReference properties and applies the transformations to the graphics pipeline(If scale = 2 will draw everything 2 times bigger) then draws each entity inside the BlockTableRecord and finally removes transformations from pipeline.

If you were to put a BlockReference inside a BlockTableRecord that referenced itself, then

It would draw each entity inside itself which contains a BlockReference to draw each entity inside itself, which contains a BlockReference to draw each entity inside itself,  which contains a BlockReference to draw each entity inside itself,  ......
and that goes on forever.

It would be same as trying to insert a drawing inside itself.

BillZndl

  • Guest
Re: Question about block references in AutoCAD.
« Reply #5 on: July 17, 2014, 12:12:08 PM »
okay, thanks! Makes it easier to understand.

That's what happens everytime I think I know something.   :laugh: