Hi
I convert Excel file to Shape file and import it to Mysql database
when I connect to MYSQL I get the data but can not get the Text only Point
is it possible I can do this in VB.NET connect to MYSQL insert it as Mtext or Block X,Y?
I have postcode and house number was thinking about query from postcode and insert the house number as Mtext or Block
anyone here who can help me how I can do this Please
Regards
Sgear
Solved! Go to Solution.
Solved by Sgear. Go to Solution.
Try this sample, tested on SQLEXPRESS 2008, AutoCAD 2014
public static List<object[]> GetRoomRecords() { List<object[]> records = new List<object[]>(); //custom connection string string connStr = "Data Source=.\\SQLEXPRESS;Initial Catalog=MySQLAutoCAD;Integrated Security=True;"; string sqlQuery = @"SELECT [ID] ,[postcode] ,[roomnumber] ,[description] ,[X] ,[Y] FROM [MySqlAutoCAD].[dbo].[Rooms] WHERE ([postcode]=99211 AND [roomnumber]> 99)";// change on your condition here SqlDataAdapter sqlAdapter = null; using (SqlConnection sqlCon = new SqlConnection(connStr)) { try { sqlAdapter = new SqlDataAdapter(sqlQuery, sqlCon); using (SqlCommand sqlCommand = new SqlCommand(sqlAdapter.SelectCommand.CommandText)) { System.Data.DataSet dataset = new System.Data.DataSet(); sqlAdapter.Fill(dataset, "Table1");// default table name, do not you change it System.Data.DataTable dt = dataset.Tables["Table1"]; foreach (System.Data.DataRow dr in dt.Rows) { object[] items = dr.ItemArray; records.Add(items); } } sqlCon.Close(); return records; } catch (System.Exception ex) { System.Diagnostics.Debug.Print(ex.Message); return null; } } } [CommandMethod("msql")] public static void AddRecordsFromSQL() { List<object[]> data = new List<object[]>(); try { data = GetRoomRecords(); } catch { return; } if (data != null) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; try { using (DocumentLock doclock = doc.LockDocument()) { using (Transaction tr = doc.TransactionManager.StartTransaction()) { doc.TransactionManager.EnableGraphicsFlush(true); BlockTable bt = (BlockTable)tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); foreach (object[] item in data) { int roomnumber = Convert.ToInt32(item[2], CultureInfo.CurrentCulture); string description = Convert.ToString(item[3], CultureInfo.CurrentCulture); double X = Convert.ToDouble(item[4], CultureInfo.CurrentCulture); double Y = Convert.ToDouble(item[5], CultureInfo.CurrentCulture); Point3d pt = new Point3d(X, Y, 0); MText mtx = new MText(); mtx.SetDatabaseDefaults(); mtx.Attachment = AttachmentPoint.MiddleCenter; mtx.Contents = string.Format("{0}\n\n{1}", roomnumber, description); mtx.Normal = Vector3d.ZAxis; mtx.Location = pt; mtx.Location = mtx.Location; ObjectId mtxId = btr.AppendEntity(mtx); tr.AddNewlyCreatedDBObject(mtx, true); tr.TransactionManager.QueueForGraphicsFlush(); } ed.Regen(); doc.TransactionManager.FlushGraphics(); tr.Commit(); } } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { ed.WriteMessage(ex.StackTrace); } finally { } } }
fixo Thanks this help me a Lot !!! this is mutch faster using VB.NET 🙂
tell me what is best to do when you insert Mtext like this about font size
change the font when you insert or can you insert all text into one block or somthing so when you change the font you change all
this is my sample in VB.NET
1. I use command to open the form
2. in combobox I select postcode then I insert data into Listview
3. I insert into Autocad from Listview , in Combobox I can select font size
what is missing I need to insert ProgressBar to know when I am finish to insert to Autocad 🙂
mabye to fast for the ProgressBar hehe
the attachment is a .rar file just rename it to .rar
I don't use winzip
Regards
Sgear