Author Topic: PALETE İNSERT TO ARTİBUTE HOW TO BUILD THIS ERROR WHEN TRANSMITTING DATA  (Read 1913 times)

0 Members and 1 Guest are viewing this topic.

cihanbakı

  • Mosquito
  • Posts: 4
// Open the Block table for read
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

                ObjectId blkRecId = ObjectId.Null;

                if (!acBlkTbl.Has("ISITMA BORU ÇAPI "))
                {
                    using (BlockTableRecord acBlkTblRec = new BlockTableRecord())
                    {
                        acBlkTblRec.Name = "ISITMA ÇAP";

                        // Set the insertion point for the block
                        acBlkTblRec.Origin = new Point3d(0, 0, 0);

                        // Add a circle to the block
                        using (Circle acCirc = new Circle())
                        {
                            acCirc.Center = new Point3d(0, 0, 0);
                            acCirc.Radius = 10;

                            acBlkTblRec.AppendEntity(acCirc);

                            // Add an attribute definition to the block
                            using (AttributeDefinition acAttDef = new AttributeDefinition())
                            {
                                acAttDef.Position = new Point3d(0, 0, 0);
                                acAttDef.Prompt = textBox2.Text;
                                acAttDef.Tag = textBox3.Text;
                                acAttDef.TextString = comboBox1.Text;
                                acAttDef.Height = 1;
                                acAttDef.Justify = AttachmentPoint.MiddleCenter;
                                acBlkTblRec.AppendEntity(acAttDef);

                                acBlkTbl.UpgradeOpen();
                                acBlkTbl.Add(acBlkTblRec);
                                acTrans.AddNewlyCreatedDBObject(acBlkTblRec, true);
                            }
                        }

                        blkRecId = acBlkTblRec.Id;
                    }
                }
                else
                {
                    blkRecId = acBlkTbl["CircleBlockWithAttributes"];
                }

                // Insert the block into the current space
                if (blkRecId != ObjectId.Null)
                {
                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = acTrans.GetObject(blkRecId, OpenMode.ForRead) as BlockTableRecord;

                    // Create and insert the new block reference
                    using (BlockReference acBlkRef = new BlockReference(new Point3d(2, 2, 0), blkRecId))
                    {
                        BlockTableRecord acCurSpaceBlkTblRec;
                        acCurSpaceBlkTblRec = acTrans.GetObject(acCurDb.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

                        acCurSpaceBlkTblRec.AppendEntity(acBlkRef);
                        acTrans.AddNewlyCreatedDBObject(acBlkRef, true);

                        // Verify block table record has attribute definitions associated with it
                        if (acBlkTblRec.HasAttributeDefinitions)
                        {
                            // Add attributes from the block table record
                            foreach (ObjectId objID in acBlkTblRec)
                            {
                                DBObject dbObj = acTrans.GetObject(objID, OpenMode.ForRead) as DBObject;

                                if (dbObj is AttributeDefinition)
                                {
                                    AttributeDefinition acAtt = dbObj as AttributeDefinition;

                                    if (!acAtt.Constant)
                                    {
                                        using (AttributeReference acAttRef = new AttributeReference())
                                        {
                                            acAttRef.SetAttributeFromBlock(acAtt, acBlkRef.BlockTransform);
                                            acAttRef.Position = acAtt.Position.TransformBy(acBlkRef.BlockTransform);

                                            acAttRef.TextString = acAtt.TextString;

                                            acBlkRef.AttributeCollection.AppendAttribute(acAttRef);

                                            acTrans.AddNewlyCreatedDBObject(acAttRef, true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Save the new object to the database
                acTrans.Commit();

                // Dispose of the transaction
            }
        }

    }

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
You need to lock the database when writing to it.

One way is to wrap your code in a command, so when the user clicks the button, you send a command to execute your code.

Your code would live in MyUtilitys.InsertAtts() in the following example:

Code - C#: [Select]
  1. // a command
  2. [CommandMethod("MyCoolCommand")]
  3. public void MyCoolCommand()
  4. {
  5.   try
  6.   {
  7.     MyUtilitys.InsertAtts();
  8.   }
  9.   catch (Exception e)
  10.   {
  11.     MyApp.HandleError(e);
  12.   }
  13. }
  14.  
  15. // a button click event in your palette
  16. private void btnAttIns_Click(object sender, EventArgs e)
  17. {
  18.   Document doc = _CadAPP.DocumentManager.MdiActiveDocument;
  19.   doc.SendStringToExecute("MyCoolCommand", true, false, false);
  20. }
  21.  
Hope that helps.
« Last Edit: June 02, 2018, 08:40:07 PM by Atook »

WILL HATCH

  • Bull Frog
  • Posts: 450
no need for upgrade on the newly created block table record, it isn't database resident