コード例 #1
0
        public static BlockReference InsertBlockReference(this BlockTableRecord target, string blkName, Point3d insertPoint, Dictionary <string, string> attValues = null)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            Database    db = target.Database;
            Transaction tr = db.TransactionManager.TopTransaction;

            if (tr == null)
            {
                throw new AcRx.Exception(ErrorStatus.NoActiveTransactions);
            }
            BlockReference br    = null;
            BlockTable     bt    = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
            ObjectId       btrId = bt.GetBlock(blkName);

            if (btrId != ObjectId.Null)
            {
                br = new BlockReference(insertPoint, btrId);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(btrId, OpenMode.ForRead);
                target.AppendEntity(br);
                tr.AddNewlyCreatedDBObject(br, true);
                br.AddAttributeReferences(attValues);
            }
            return(br);
        }
コード例 #2
0
        private void cbxBlock_Validating(object sender, CancelEventArgs e)
        {
            string text = this.cbxBlock.Text;

            if (text == "")
            {
                return;
            }
            BlockTable obj = this._db.BlockTableId.GetObject <BlockTable>();

            if (obj.Has(text))
            {
                BlockTableRecord      blockTableRecords = obj[text].GetObject <BlockTableRecord>();
                AttributeDefinition[] arrayAttDef       = (
                    from att in blockTableRecords.GetObjects <AttributeDefinition>()
                    where !att.Constant
                    select att).ToArray <AttributeDefinition>();
                if (arrayAttDef != null && arrayAttDef.Length != 0)
                {
                    this.cbxBlock.SelectedItem = blockTableRecords;
                    return;
                }
                AcAp.ShowAlertDialog(("Block terpilih tidak terdapat Attribute Reference."));
                this.cbxBlock.SelectAll();
                return;
            }
            ObjectId block = obj.GetBlock(text);

            if (block == ObjectId.Null)
            {
                AcAp.ShowAlertDialog("Block '" + text + "'Tidak ada.");
                this.cbxBlock.SelectAll();
                return;
            }
            BlockTableRecord obj1 = block.GetObject <BlockTableRecord>();

            AttributeDefinition[] arrayDef = (
                from att in obj1.GetObjects <AttributeDefinition>()
                where !att.Constant
                select att).ToArray <AttributeDefinition>();
            if (arrayDef == null || arrayDef.Length == 0)
            {
                AcAp.ShowAlertDialog("Tidak Ada Attribute pada Block yang dipilih.");
                this.cbxBlock.SelectAll();
                return;
            }
            if (!this.cbxBlock.Items.Contains(obj1))
            {
                this.cbxBlock.DataSource = this._db.GetBlocksWithAttribute();
            }
            this.cbxBlock.SelectedItem = obj1;
        }