예제 #1
0
        public static AttributeReference AddAttributeReferences(this BlockReference br, int index, string value)
        {
            BlockTableRecord   obj                = br.BlockTableRecord.GetObject <BlockTableRecord>();
            Transaction        topTransaction     = br.Database.TransactionManager.TopTransaction;
            AttributeReference attributeReference = null;

            AttributeDefinition[] array = obj.GetObjects <AttributeDefinition>().ToArray <AttributeDefinition>();
            for (int i = 0; i < (int)array.Length; i++)
            {
                AttributeDefinition attributeDefinition = array[i];
                AttributeReference  attributeReference1 = new AttributeReference();
                attributeReference1.SetAttributeFromBlock(attributeDefinition, br.BlockTransform);
                Point3d position = attributeDefinition.Position;
                attributeReference1.Position = position.TransformBy(br.BlockTransform);
                if (attributeDefinition.Justify != AttachmentPoint.BaseLeft)
                {
                    position = attributeDefinition.AlignmentPoint;
                    attributeReference1.AlignmentPoint = position.TransformBy(br.BlockTransform);
                    attributeReference1.AdjustAlignment(br.Database);
                }
                if (attributeReference1.IsMTextAttribute)
                {
                    attributeReference1.UpdateMTextAttribute();
                }
                if (i == index)
                {
                    attributeReference1.TextString = value;
                    attributeReference             = attributeReference1;
                }
                br.AttributeCollection.AppendAttribute(attributeReference1);
                topTransaction.AddNewlyCreatedDBObject(attributeReference1, true);
            }
            return(attributeReference);
        }
예제 #2
0
        protected override bool Update()
        {
            BlockReference br = Entity as BlockReference;

            br.Position = _pos;

            if (br.AttributeCollection.Count != 0)
            {
                foreach (ObjectId id in br.AttributeCollection)
                {
                    DBObject           obj = _tr.GetObject(id, OpenMode.ForRead);
                    AttributeReference ar  = obj as AttributeReference;

                    // Apply block transform to att def position
                    if (ar != null)
                    {
                        ar.UpgradeOpen();
                        AttInfo ai = _attInfo[ar.ObjectId];
                        ar.Position = ai.Position.TransformBy(br.BlockTransform);

                        if (ai.IsAligned)
                        {
                            ar.AlignmentPoint = ai.Alignment.TransformBy(br.BlockTransform);
                        }

                        if (ar.IsMTextAttribute)
                        {
                            ar.UpdateMTextAttribute();
                        }
                    }
                }
            }
            return(true);
        }
예제 #3
0
            //[CommandMethod("BJ")]
            public static void BlockJigCmd(Double finalCalcText)
            {
                Document doc =
                  Application.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                Editor ed = doc.Editor;

                //Set the block Name to use.
                string pr = "TagHgr";

                Transaction tr =
                  doc.TransactionManager.StartTransaction();
                using (tr)
                {
                    BlockTable bt =
                      (BlockTable)tr.GetObject(
                        db.BlockTableId,
                        OpenMode.ForRead
                      );

                    if (!bt.Has(pr))
                    {
                        ed.WriteMessage(
                          "\nBlock \"" + pr + "\" not found.");
                        return;
                    }

                    BlockTableRecord space =
                      (BlockTableRecord)tr.GetObject(
                        db.CurrentSpaceId,
                        OpenMode.ForWrite
                      );

                    BlockTableRecord btr =
                      (BlockTableRecord)tr.GetObject(
                        bt[pr],
                        OpenMode.ForRead);

                    // Block needs to be inserted to current space before
                    // being able to append attribute to it

                    BlockReference br =
                      new BlockReference(new Point3d(), btr.ObjectId);
                    space.AppendEntity(br);
                    tr.AddNewlyCreatedDBObject(br, true);

                    Dictionary<ObjectId, AttInfo> attInfo =
                      new Dictionary<ObjectId, AttInfo>();

                    if (btr.HasAttributeDefinitions)
                    {
                        foreach (ObjectId id in btr)
                        {
                            DBObject obj =
                              tr.GetObject(id, OpenMode.ForRead);
                            AttributeDefinition ad =
                              obj as AttributeDefinition;

                            if (ad != null && !ad.Constant)
                            {
                                AttributeReference ar =
                                  new AttributeReference();

                                ar.SetAttributeFromBlock(ad, br.BlockTransform);
                                ar.Position =
                                  ad.Position.TransformBy(br.BlockTransform);

                                if (ad.Justify != AttachmentPoint.BaseLeft)
                                {
                                    ar.AlignmentPoint =
                                      ad.AlignmentPoint.TransformBy(br.BlockTransform);
                                }
                                if (ar.IsMTextAttribute)
                                {
                                    ar.UpdateMTextAttribute();
                                }

                                //ar.TextString = ad.TextString;
                                ar.TextString = PopulateAttributes(ad.Tag, finalCalcText.ToString());

                                ObjectId arId =
                                  br.AttributeCollection.AppendAttribute(ar);
                                tr.AddNewlyCreatedDBObject(ar, true);

                                // Initialize our dictionary with the ObjectId of
                                // the attribute reference + attribute definition info

                                attInfo.Add(
                                  arId,
                                  new AttInfo(
                                    ad.Position,
                                    ad.AlignmentPoint,
                                    ad.Justify != AttachmentPoint.BaseLeft
                                  )
                                );
                            }
                        }
                    }
                    // Run the jig

                    BlockJig myJig = new BlockJig(tr, br, attInfo);

                    if (myJig.Run() != PromptStatus.OK)
                        return;

                    // Commit changes if user accepted, otherwise discard

                    tr.Commit();
                }
            }
예제 #4
0
            } //end ImportBlocks()

            //[CommandMethod("BJ")]
            static public void BlockJigCmd(Double finalCalcText)
            {
                Document doc =
                    Application.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                Editor   ed = doc.Editor;

                //Set the block Name to use.
                string pr = "TagHgr";

                Transaction tr =
                    doc.TransactionManager.StartTransaction();

                using (tr)
                {
                    BlockTable bt =
                        (BlockTable)tr.GetObject(
                            db.BlockTableId,
                            OpenMode.ForRead
                            );

                    if (!bt.Has(pr))
                    {
                        ed.WriteMessage(
                            "\nBlock \"" + pr + "\" not found.");
                        return;
                    }

                    BlockTableRecord space =
                        (BlockTableRecord)tr.GetObject(
                            db.CurrentSpaceId,
                            OpenMode.ForWrite
                            );

                    BlockTableRecord btr =
                        (BlockTableRecord)tr.GetObject(
                            bt[pr],
                            OpenMode.ForRead);

                    // Block needs to be inserted to current space before
                    // being able to append attribute to it

                    BlockReference br =
                        new BlockReference(new Point3d(), btr.ObjectId);
                    space.AppendEntity(br);
                    tr.AddNewlyCreatedDBObject(br, true);

                    Dictionary <ObjectId, AttInfo> attInfo =
                        new Dictionary <ObjectId, AttInfo>();

                    if (btr.HasAttributeDefinitions)
                    {
                        foreach (ObjectId id in btr)
                        {
                            DBObject obj =
                                tr.GetObject(id, OpenMode.ForRead);
                            AttributeDefinition ad =
                                obj as AttributeDefinition;

                            if (ad != null && !ad.Constant)
                            {
                                AttributeReference ar =
                                    new AttributeReference();

                                ar.SetAttributeFromBlock(ad, br.BlockTransform);
                                ar.Position =
                                    ad.Position.TransformBy(br.BlockTransform);

                                if (ad.Justify != AttachmentPoint.BaseLeft)
                                {
                                    ar.AlignmentPoint =
                                        ad.AlignmentPoint.TransformBy(br.BlockTransform);
                                }
                                if (ar.IsMTextAttribute)
                                {
                                    ar.UpdateMTextAttribute();
                                }

                                //ar.TextString = ad.TextString;
                                ar.TextString = PopulateAttributes(ad.Tag, finalCalcText.ToString());

                                ObjectId arId =
                                    br.AttributeCollection.AppendAttribute(ar);
                                tr.AddNewlyCreatedDBObject(ar, true);

                                // Initialize our dictionary with the ObjectId of
                                // the attribute reference + attribute definition info

                                attInfo.Add(
                                    arId,
                                    new AttInfo(
                                        ad.Position,
                                        ad.AlignmentPoint,
                                        ad.Justify != AttachmentPoint.BaseLeft
                                        )
                                    );
                            }
                        }
                    }
                    // Run the jig

                    BlockJig myJig = new BlockJig(tr, br, attInfo);

                    if (myJig.Run() != PromptStatus.OK)
                    {
                        return;
                    }

                    // Commit changes if user accepted, otherwise discard

                    tr.Commit();
                }
            }
예제 #5
0
        static public void BlockJigCmd(string strSourceBlockPath, string LayerName, bool displayAttEdit)
        {
            //same stuff
            Document         doc = Application.DocumentManager.MdiActiveDocument;
            Database         db  = doc.Database;
            Editor           ed  = doc.Editor;
            BlockTableRecord btr;

            Transaction tr = doc.TransactionManager.StartTransaction();

            using (tr)
            {
                string strSourceBlockName = Path.GetFileName(strSourceBlockPath);

                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);

                //if block already exists in drawing retrieve it, if not create if from external drawing
                if (bt.Has(strSourceBlockName))
                {
                    ObjectId id = bt[strSourceBlockName];
                    btr = (BlockTableRecord)tr.GetObject(id, OpenMode.ForRead, true, true);
                }
                else
                {
                    BlockTableRecord btrSource = GeneralMenu.GetBlock(strSourceBlockName, strSourceBlockPath);
                    if (btrSource == null)
                    {
                        return;
                    }
                    btr = (BlockTableRecord)tr.GetObject(btrSource.ObjectId, OpenMode.ForRead, true, true);
                }

                BlockTableRecord space = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

                // Block needs to be inserted to current space before
                // being able to append attribute to it
                BlockReference br = new BlockReference(new Point3d(), btr.ObjectId);

                GeneralMenu.CreateLayer(LayerName, false);
                br.Layer = LayerName;

                space.AppendEntity(br);
                tr.AddNewlyCreatedDBObject(br, true);

                Dictionary <ObjectId, AttInfo> attInfo = new Dictionary <ObjectId, AttInfo>();

                if (btr.HasAttributeDefinitions)
                {
                    foreach (ObjectId id in btr)
                    {
                        DBObject            obj = tr.GetObject(id, OpenMode.ForRead);
                        AttributeDefinition ad  = obj as AttributeDefinition;

                        if (ad != null && !ad.Constant)
                        {
                            AttributeReference ar = new AttributeReference();
                            ar.SetAttributeFromBlock(ad, br.BlockTransform);
                            ar.Position = ad.Position.TransformBy(br.BlockTransform);

                            if (ad.Justify != AttachmentPoint.BaseLeft)
                            {
                                ar.AlignmentPoint = ad.AlignmentPoint.TransformBy(br.BlockTransform);
                            }

                            if (ar.IsMTextAttribute)
                            {
                                ar.UpdateMTextAttribute();
                            }

                            ar.TextString = ad.TextString;
                            ObjectId arId = br.AttributeCollection.AppendAttribute(ar);
                            tr.AddNewlyCreatedDBObject(ar, true);

                            // Initialize our dictionary with the ObjectId of
                            // the attribute reference + attribute definition info

                            attInfo.Add(arId, new AttInfo(ad.Position, ad.AlignmentPoint, ad.Justify != AttachmentPoint.BaseLeft));
                        }
                    }
                }

                // Run the jig
                BlockJig myJig = new BlockJig(tr, br, attInfo);

                if (myJig.Run() != PromptStatus.OK)
                {
                    return;
                }
                if (btr.HasAttributeDefinitions && displayAttEdit)
                {
                    doc.SendStringToExecute("_.EATTEDIT l ", true, false, true);
                    //CommandLine.Command("_.EATTEDIT", br.ObjectId);
                }
                // Commit changes if user accepted, otherwise discard
                tr.Commit();
            }
        }