Community
hi everyone
has anybody made a program and can share it here? both source code in vb.net or dll file is fine.
thank you very much.
Take a look ath this example
http://through-the-interface.typepad.com/through_the_interface/2007/08/creating-an-aut.html
Hi there,
I've created a simple project to read the layernames from excel and add these to the drawing.
It's written in c# But there are enough converters around. Project is attached including an excel 2007 file.
Good luck,
Irvin
using System; using System.Text; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Excel = Microsoft.Office.Interop.Excel; namespace CreateLayerFromExcel { public class Layer { [CommandMethod("CreatLayersFromExcel")] public void CreatLayersFromExcel() { Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; Excel.Range range; string str; int rCnt = 0; int cCnt = 0; xlApp = new Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Open("c:\\temp\\test.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); range = xlWorkSheet.UsedRange; for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++) { for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++) { str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; CreateLayer(str); System.Windows.Forms.MessageBox.Show(str + " created!"); } } xlWorkBook.Close(true, null, null); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); } private void releaseObject(object obj) { try { System.Runtime.InteropServices.Marshal.ReleaseComObject(obj); obj = null; } catch (System.Exception ex) { obj = null; System.Windows.Forms.MessageBox.Show("Unable to release the Object " + ex.ToString()); } finally { GC.Collect(); } } private void CreateLayer(string layerName) { ObjectId layerId; Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction()) { LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead); if (lt.Has(layerName)) { layerId = lt[layerName]; } else { LayerTableRecord ltr = new LayerTableRecord(); ltr.Name = layerName; //ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, 2); lt.UpgradeOpen(); layerId = lt.Add(ltr); trans.AddNewlyCreatedDBObject(ltr, true); } trans.Commit(); } } } }