.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

insert a block, and in the sequel want the data of this block,

1 REPLY 1
Reply
Message 1 of 2
dariowbc
294 Views, 1 Reply

insert a block, and in the sequel want the data of this block,

  //Hello my name is Dario 
        //'m from Brazil 
 
        //I'm still having problem 
        //need help
 
        //can someone help me? 
 
        //insert a block, and in the sequel want the data of this block, 
        //and then delete this block 
        //as the example in the main code, just below .. 
 
 
        //I have these questions that are commented no Main method >>???????
 
 
        //Main method 
        //===================================================================================================
 
        [CommandMethod("Blockk")]
        public void blockk()
        {
          Document doc = Host.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
 
          string[] data = new string[3];
          data[0= "data 1";
          data[1= "data 2";
          data[2= "data 3";
 
          BlockReference db = InsertBlockFromFile_(doc@"C:\wbc\orienta.dwg"new Point3d(505050), Math.PI * 0.25,
            "wbc_insert"data303017truenull"wbcd");
 
            //??????? return..>>> Example
 
            //??????? db.insertionPoint
            //??????? db.angle
            //??????? db.handle
            //??????? db.Xproprierts
            //??????? db.Atrib
            //??????? db.erase
 
 
        }
 
 
 
 
        //Complementary methods
        //===============================================================================================================================
        public static BlockReference InsertBlockFromFile_(Document docstring DrawingFilePoint3d Pinsertdouble Angle,
        string Layerstring[] DadosExtendidos = nulldouble escalax = 1.0double escalay = 1.0double escalaz = 1.0short ColorLayer = 7,
        bool ModelSpace = truestring[] Atributos = nullstring RegAplicacao = "wbc")
        {
            if (!System.IO.File.Exists(DrawingFile))
            {
                MessageBox.Show("Drawing not found\n" + DrawingFile);
                return null;
            }
            string sourceFileName = DrawingFile;
            string Blockname = System.IO.Path.GetFileNameWithoutExtension(sourceFileName);
            try
            {
                using (Transaction tr = doc.TransactionManager.StartTransaction())
                {
                    Database db = new Database(falsefalse);
                    db.ReadDwgFile(DrawingFileSystem.IO.FileShare.Readtruenull);
                    ObjectId BlkId = doc.Database.Insert(Blocknamedbtrue); // ISL: Small fix, use correct block name
                    tr.Commit();
                }
            }
            catch (IOException ioe)
            {
                MessageBox.Show(ioe.Message);
 
                return null;
            }
 
            return AddBlockTest_(docBlocknamePinsertAngleLayerDadosExtendidosescalaxescalayescalazColorLayerAtributosRegAplicacao);
        }
 
 
 
 
 
        private static BlockReference AddBlockTest_(Document docstring blockNamePoint3d Pinsertdouble Angle,
        string Layerstring[] DadosExtendidos = nulldouble escalax = 1.0double escalay = 1.0double escalaz = 1.0,
        short ColorLayer = 7string[] Atributos = nullstring Regaplicacao = "wbc")
        {
            Database db = doc.Database;
            using (Transaction myT = db.TransactionManager.StartTransaction())
            {
                //Get the block definition "Check".
 
                BlockTable bt =
                    db.BlockTableId.GetObject(OpenMode.ForReadas BlockTable;
                BlockTableRecord blockDef =
                  bt[blockName].GetObject(OpenMode.ForReadas BlockTableRecord;
 
                BlockTableRecord ms = (BlockTableRecord)myT.GetObject(db.CurrentSpaceIdOpenMode.ForWrite);
 
 
                //Create new BlockReference, and link it to our block definition
                using (BlockReference blockRef =
                        new BlockReference(PinsertblockDef.ObjectId))
                {
 
                    blockRef.Rotation = Angle;
                    blockRef.ScaleFactors = new Scale3d(escalaxescalayescalaz);
 
                    //Add the block reference to modelspace
                    ms.AppendEntity(blockRef);
                    myT.AddNewlyCreatedDBObject(blockReftrue);
 
                    SetXData_(blockRefRegaplicacao , DadosExtendidosdoc);
                    CreatLayer_(LayerdocColorLayer);
                    blockRef.Layer = Layer;
                }
                //Our work here is done
                myT.Commit();
 
            }
 
            return null;
        }
 
 
 
 
        static public void SetXData_(Entity brefstring nomestring[] dataDocument docstring VersaoEquipamento = "Without Version")
        {
            Database db = doc.Database;
 
            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {
                AddRegAppTableRecord_(nomedoc);
                ResultBuffer rb = new ResultBuffer();
                rb.Add(new TypedValue(1001nome));
 
                for (int i = 0i < data.Lengthi++)
                {
                    rb.Add(new TypedValue(1000data[i]));
                }
 
                rb.Add(new TypedValue(1000VersaoEquipamento));
                DateTime Wdata = DateTime.Now;
                Wdata.ToShortDateString();
                rb.Add(new TypedValue(1000Wdata.ToString()));
                rb.Add(new TypedValue(1000VariaveisGlobais.Wusuario + "_" + VariaveisGlobais.NumeroSerie));
                bref.XData = rb;
                tr.Commit();
            }
        }
 
 
 
        public static void CreatLayer_(string sLayerNameDocument docshort CorCamada = 7)
        {
            Document acDoc = doc;
            Database acCurDb = acDoc.Database;
            // Start a transaction
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Layer table for read
                LayerTable acLyrTbl;
                acLyrTbl = acTrans.GetObject(acCurDb.LayerTableId,
                                             OpenMode.ForReadas LayerTable;
                if (acLyrTbl.Has(sLayerName== false)
                {
                    Platform.DatabaseServices.LayerTableRecord acLyrTblRec = new LayerTableRecord();
                    // Assign the layer the ACI color 1 and a name
                    acLyrTblRec.Color = Platform.Colors.Color.FromColorIndex(Platform.Colors.ColorMethod.ByAciCorCamada);
                    acLyrTblRec.Name = sLayerName;
                    // Upgrade the Layer table for write
                    acLyrTbl.UpgradeOpen();
                    // Append the new layer to the Layer table and the transaction
                    acLyrTbl.Add(acLyrTblRec);
                    acTrans.AddNewlyCreatedDBObject(acLyrTblRectrue);
                }
                acTrans.Commit();
            }
        }
 
 
 
 
        public static void AddRegAppTableRecord_(string regAppNameDocument doc)
        {
            using (Transaction tr = doc.TransactionManager.StartTransaction())
            {
                RegAppTable rat = (RegAppTable)tr.GetObject(doc.Database.RegAppTableIdOpenMode.ForReadfalse);
 
                if (!rat.Has(regAppName))
                {
                    rat.UpgradeOpen();
                    RegAppTableRecord ratr = new RegAppTableRecord();
                    ratr.Name = regAppName;
                    rat.Add(ratr);
 
                    tr.AddNewlyCreatedDBObject(ratrtrue);
                }
 
                tr.Commit();
            }
        }
1 REPLY 1
Message 2 of 2
Balaji_Ram
in reply to: dariowbc

Hi Dario,

 

Sorry for the long delay.

 

Is this topic still a problem ?

 

The issue with your code seems more related to the structure of your code. Make sure each method does a specific task, like creating a block definition, inserting a block reference, modifying the block reference etc. Now ensure that those methods accept or return the ObjectId of the entity on which they will work. This should help in getting it to work in sequence.

 

Hope this helps. If not, please do let me know.

 

Regards,

Balaji



Balaji
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost