Hi
I have an excel file with a column containing lower width,upper width and height like follows:
Row 1 point
Row 2 10
Row 3 7
I am looking for a .Net code that can read each row cell and draw the triangle automatically in AutoCAD window. I am having a bout 100 rows and hence I prefer that the code will display all triangle and another polygons at once in AutoCAD window and not draw them one by one.
I want to open excel file from user read data from excel show it in textbox on form and when user press draw button triangle should be drawn. I wish to have a .Net code to allow batch Trianle drawing instead.
I am new in programming. Please help me as earliest.
Thanks a lot for any assistance
Solved! Go to Solution.
Solved by mzakiralam. Go to Solution.
hi,
Please find Attach file. I am working in civil company. I am intending to Draw tower from user input in excel. this exercise wiil be beneficial to me to complete my task. Lower width is base of triangle and height is height of triangle. Upper Width is not applicable here.
Actually i think that if i consider one starting point i can draw base line of traingle from lower width as i got secon poin. and from base line i can calculate mid point that x and from height y for upper point then it is posssible to me to draw triangle..
hope you can help me for this.
thank you so much for your prompt reply.
Hi ,
With below code you can start your project.
<CommandMethod("TRA")> Public Sub TriangleDraw() 'declare the form to open Dim frmTriangle As TestTraingle = Nothing If frmTriangle Is Nothing Then frmTriangle = New TestTraingle() ElseIf frmTriangle.IsDisposed Then frmTriangle = New TestTraingle() End If 'show the form Application.ShowModelessDialog(Application.MainWindow.Handle, frmTriangle, False) End Sub
Imports System.IO Imports Microsoft.Office.Interop Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.DatabaseServices Public Class TestTraingle Dim tra_upperwidth As String = Nothing Dim tra_lowerwidth As String = Nothing Dim tra_height As String = Nothing Private Sub TestTraingle_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Try 'place the excelfile path Dim excelFilePath = "Place your excel file path" If File.Exists(excelFilePath) Then Call READEXCELFILE(excelFilePath) End If TextBox1.Text = tra_upperwidth TextBox2.Text = tra_lowerwidth TextBox3.Text = tra_height Catch ex As System.Exception MsgBox(ex.Message) End Try End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 'get current document Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim db As Database = doc.Database 'lock document as using modeless form Using docLock As DocumentLock = doc.LockDocument Using tx As Transaction = db.TransactionManager.StartTransaction() 'open blocktable Dim bt As BlockTable = tx.GetObject(db.BlockTableId, OpenMode.ForRead) 'open model space for write Dim ms As BlockTableRecord = tx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite) 'converte text value Dim uWidth As Double = CDbl(TextBox1.Text) Dim base As Double = CDbl(TextBox2.Text) Dim tHeight As Double = CDbl(TextBox3.Text) Dim pt1 As Point2d = New Point2d(0, 0) Dim pt2 As Point2d = New Point2d(base, 0) Dim pt3 As Point2d = New Point2d(base / 2, tHeight) 'draw traiangle Dim tra As Polyline = New Polyline() tra.AddVertexAt(0, pt1, 0, 0, 0) tra.AddVertexAt(1, pt2, 0, 0, 0) tra.AddVertexAt(2, pt3, 0, 0, 0) tra.Closed = True 'add triangle in model space ms.AppendEntity(tra) tx.AddNewlyCreatedDBObject(tra, True) tx.Commit() End Using End Using End Sub Public Sub READEXCELFILE(filePath As String) 'read excel file Try Dim xlApp As New Excel.Application Dim xlWorkBook As Excel.Workbook = xlApp.Workbooks.Open(filePath) Dim xlSheet As Excel.Worksheet = xlWorkBook.Worksheets("Sheet1") 'get all cells value tra_upperwidth = xlSheet.Cells(1, 2).Value tra_lowerwidth = xlSheet.Cells(2, 2).Value tra_height = xlSheet.Cells(3, 2).Value xlWorkBook.Close() 'quit excel application xlApp.Quit() 'relaese excel object ReleaseExcelObject(xlWorkBook) ReleaseExcelObject(xlApp) Catch ex As System.Exception MsgBox(ex.Message) End Try End Sub Public Shared Sub ReleaseExcelObject(obj As Object) 'release excel object after finishing Try System.Runtime.InteropServices.Marshal.ReleaseComObject(obj) obj = Nothing Catch ex As Autodesk.AutoCAD.Runtime.Exception obj = Nothing Finally GC.Collect() End Try End Sub End Class