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

Draw Tower WIth Dialog Box

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
bvyas89
977 Views, 14 Replies

Draw Tower WIth Dialog Box

Hello

 

I am making Customise tool for autocad which can draw tower automatically. user need to fill excel sheet. Which has all input like panel upper width ,lower width ,height. I want to draw continous all panel one by one  as per the panel type user has select.

 

 With Form1 and following code i am able to draw each thing seperately but now i want to draw a tower in single button click.

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 Form1
Dim tra_upperwidth As String = Nothing
Dim tra_lowerwidth As String = Nothing
Dim tra_height As String = Nothing
Dim FileName As String

Private Sub btnpeak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpeak.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(ByVal 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(ByVal 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


Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
Dim OpenFileDialog As New Windows.Forms.OpenFileDialog
OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
OpenFileDialog.Filter = "Excel Worksheets (*.xls)|*.xls|Text File(*.txt)|*.txt|All Files (*.*)|*.*"

If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
FileName = OpenFileDialog.FileName
End If
Try
'place the excelfile path
Dim excelFilePath = FileName
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 btnLeg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeg.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 Xx As Double = ((base - uWidth) / 2)
' Dim pt1 As Point2d = New Point2d(0, 0)
Dim pt1 As Point2d = New Point2d(0, 0)
Dim pt2 As Point2d = New Point2d(base / 2, tHeight)
Dim pt3 As Point2d = New Point2d(base, 0)
Dim pt4 As Point2d = New Point2d(base - Xx, tHeight)
Dim pt5 As Point2d = New Point2d(0 + Xx, 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.AddVertexAt(3, pt4, 0, 0, 0)
tra.AddVertexAt(4, pt5, 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

Private Sub btnKpanel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKpanel.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 Xx As Double = ((base - uWidth) / 2)
' Dim pt1 As Point2d = New Point2d(0, 0)
Dim pt1 As Point2d = New Point2d(0, 0)
Dim pt2 As Point2d = New Point2d(base / 2, tHeight)
Dim pt3 As Point2d = New Point2d(base, 0)
Dim pt4 As Point2d = New Point2d(base - Xx, tHeight)
Dim pt5 As Point2d = New Point2d(0 + Xx, 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.AddVertexAt(3, pt4, 0, 0, 0)
tra.AddVertexAt(4, pt5, 0, 0, 0)
tra.AddVertexAt(5, pt1, 0, 0, 0)
tra.AddVertexAt(6, 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

Private Sub btnXpanel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXpanel.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 Xx As Double = ((base - uWidth) / 2)
' Dim pt1 As Point2d = New Point2d(0, 0)
Dim pt1 As Point2d = New Point2d(0, 0)
Dim pt2 As Point2d = New Point2d(base, 0)
Dim pt3 As Point2d = New Point2d(base - Xx, tHeight)
Dim pt4 As Point2d = New Point2d(0, 0)
Dim pt5 As Point2d = New Point2d(0 + Xx, tHeight)
Dim pt6 As Point2d = New Point2d(base, 0)
'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.AddVertexAt(3, pt4, 0, 0, 0)
tra.AddVertexAt(4, pt5, 0, 0, 0)
tra.AddVertexAt(5, pt6, 0, 0, 0)
tra.Closed = True
'add triangle in model space
ms.AppendEntity(tra)
tx.AddNewlyCreatedDBObject(tra, True)
Dim line1 As Line = New Line(New Point3d(pt5.X, pt5.Y, 0), New Point3d(pt3.X, pt3.Y, 0))
ms.AppendEntity(line1)
tx.AddNewlyCreatedDBObject(line1, True)
tx.Commit()
End Using
End Using
End Sub
End Class

 

 

 

14 REPLIES 14
Message 2 of 15
bvyas89
in reply to: bvyas89

Now I want to draw Tower on draw button burt not getting idea how to draw it. Please help me.

Message 3 of 15
mzakiralam
in reply to: bvyas89

Use a loop to get all data of a tower from datagrid view and draw it as you did with above code
Message 4 of 15
bvyas89
in reply to: bvyas89

Yupp i tried that but not working for me... As i need the last point as first point for next panel. Canyou please help me. I know There is very small thing which i am missing in my code.Waiting for reply.

Message 5 of 15
mzakiralam
in reply to: bvyas89

HI,
first Thing is I can not open your drawing as I have only ACAD 2010 and ACAD 2011. Kindly save your drawing file in 2010 or 2011 Format so that I can see your drawing. Another issue is from where K-Panel and L-Panel data should be read? because for base triangle data are read from Excel file. but in your new_draw_tower.png Picture it seems like that data Need to read from datagrid view or something else? please clarify from stat to end once more.. if all data are in Excel sheet then please provide me that sheet as well. for better clarification you can draw a Picture like before.
Message 6 of 15
bvyas89
in reply to: mzakiralam

please find attach drawing.  Sir If i take starting point zero i can do that easily . bt now i want to draw continously by reading data row by row. and start from end point.

 

my current code is as follow:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim Panel_name, Panel_type As String
Dim Panel_height, Panel_lwidth, Panel_uwidth As Double
Dim Panel_no As Integer
Panel_name = String.Empty
Panel_type = String.Empty

'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)

For Each row As System.Windows.Forms.DataGridViewRow In DataGridView1.Rows
Panel_no = row.Cells(0).Value
Panel_name = row.Cells(1).Value
Panel_height = row.Cells(2).Value
Panel_uwidth = row.Cells(3).Value
Panel_lwidth = row.Cells(4).Value
Panel_type = row.Cells(5).Value
Dim Xx As Double = ((Panel_lwidth - Panel_uwidth) / 2)
Dim pt1 As Point2d
Dim pt_start As Point2d
Dim pt2 As Point2d = New Point2d(Panel_lwidth / 2, Panel_height)
Dim pt3 As Point2d = New Point2d(Panel_lwidth, 0)
Dim pt4 As Point2d = New Point2d(Panel_lwidth - Xx, Panel_height)
Dim pt5 As Point2d = New Point2d(0 + Xx, Panel_height)
pt1 = New Point2d(0, 0)
Dim tra As Polyline = New Polyline()

If Panel_type = "LEG" Then
tra.AddVertexAt(0, pt1, 0, 0, 0)
tra.AddVertexAt(1, pt2, 0, 0, 0)
tra.AddVertexAt(2, pt3, 0, 0, 0)
tra.AddVertexAt(3, pt4, 0, 0, 0)
tra.AddVertexAt(4, pt5, 0, 0, 0)
tra.Closed = True

End If
If Panel_type = "K-PANEL" Then
'draw traiangle
tra.AddVertexAt(0, pt_start, 0, 0, 0)
tra.AddVertexAt(1, pt2, 0, 0, 0)
tra.AddVertexAt(2, pt3, 0, 0, 0)
tra.AddVertexAt(3, pt4, 0, 0, 0)
tra.AddVertexAt(4, pt5, 0, 0, 0)
tra.Closed = True
ElseIf Panel_type = "X-PANEL" Then
tra.AddVertexAt(0, pt_start, 0, 0, 0)
tra.AddVertexAt(1, pt4, 0, 0, 0)
tra.AddVertexAt(2, pt3, 0, 0, 0)
tra.AddVertexAt(3, pt5, 0, 0, 0)
tra.Closed = True
'add triangle in model space
End If
'add triangle in model space
ms.AppendEntity(tra)
tx.AddNewlyCreatedDBObject(tra, True)
tx.Commit()
pt_start = pt5
Next
End Using
End Using
End Sub

Message 7 of 15
mzakiralam
in reply to: bvyas89

Hi , below you will find some code to draw tower. I did not test but should be ok in logical point of view.

 

 Dim htLegPanel As String = Nothing
 Dim uWidthLegPanel As String = Nothing
 Dim lWidthLegPanel As String = Nothing
 'K-Panel
 Dim htKPanel As String = Nothing
 Dim uWidthKPanel As String = Nothing
 Dim lWidthKPanel As String = Nothing
 'X-panel
 Dim htXPanel As String = Nothing
 Dim uWidthXPanel As String = Nothing
 Dim lWidthXPanel As String = Nothing

 

  <CommandMethod("DT")> Public Sub DrawTraingle()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        'add your excel file path
        Dim fPath As String = "C:\Users\alamzaki\Desktop\TowerInput.xls"
        Call READEXCELFILE(fPath)
        Dim base As Double = Nothing
        Dim ht As Double = Nothing
        Dim basePoint As Point2d = New Point2d(0, 0)
        'Leg Triangle
        base = CDbl(lWidthLegPanel)
        ht = CDbl(htLegPanel)
        'start point
        Dim L_pt1 As Point2d = basePoint
        'mid point
        Dim L_pt2 As Point2d = New Point2d(((base / 2) + ht), ht)
        'end point
        Dim L_pt3 As Point2d = New Point2d(base, 0)
        'K triangle
        base = CDbl(lWidthKPanel)
        ht = CDbl(htKPanel)
        basePoint = L_pt2
        'start point
        Dim K_pt1 As Point2d = New Point2d(basePoint.X - (base / 2), basePoint.Y)
        'mid point
        Dim K_pt2 As Point2d = New Point2d(basePoint.X, basePoint.Y + ht)
        'end point
        Dim K_pt3 As Point2d = New Point2d(basePoint.X + (base / 2), basePoint.Y)
        'X triangle
        base = CDbl(lWidthXPanel)
        ht = CDbl(htXPanel)
        basePoint = K_pt2
        Dim X_pt1 As Point2d = New Point2d(basePoint.X - (base / 2), basePoint.Y)
        Dim X_pt2 As Point2d = New Point2d(basePoint.X, basePoint.Y + ht)
        Dim X_pt3 As Point2d = New Point2d(basePoint.X + (base / 2), basePoint.Y)

        Using tx As Transaction = db.TransactionManager.StartTransaction()
            Dim bt As BlockTable = tx.GetObject(db.BlockTableId, OpenMode.ForRead)
            Dim ms As BlockTableRecord = tx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
            'draw leg
            Call TraingleBuild(L_pt1, L_pt2, L_pt3, False, tx, ms)
            'draw k
            Call TraingleBuild(K_pt1, K_pt2, K_pt3, True, tx, ms)
            'draw x
            Call TraingleBuild(X_pt1, X_pt2, X_pt3, True, tx, ms)
            tx.Commit()
        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
            htLegPanel = xlSheet.Cells(2, 3).Value
            uWidthLegPanel = xlSheet.Cells(2, 4).Value
            lWidthLegPanel = xlSheet.Cells(2, 5).Value
            'kpanel
            htKPanel = xlSheet.Cells(3, 3).Value
            uWidthKPanel = xlSheet.Cells(3, 4).Value
            lWidthKPanel = xlSheet.Cells(3, 5).Value
            ''xpanel
            htXPanel = xlSheet.Cells(4, 3).Value
            uWidthXPanel = xlSheet.Cells(4, 4).Value
            lWidthXPanel = xlSheet.Cells(4, 5).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
    Public Sub TraingleBuild(pt1 As Point2d, pt2 As Point2d, pt3 As Point2d, triangleClosed As Boolean, trans As Transaction, blkTblRec As BlockTableRecord)
        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)
        'for leg do not close the polyline
        If triangleClosed = True Then
            tra.Closed = True
        End If
        blkTblRec.AppendEntity(tra)
        trans.AddNewlyCreatedDBObject(tra, True)
    End Sub

 

Message 8 of 15
bvyas89
in reply to: mzakiralam

hello... Thanx for your reply. It Doesnot woking for me... input ,No of panel and type can be very so i want it dynamic that read it and perform Action
Message 9 of 15
mzakiralam
in reply to: bvyas89

ok so if it is varied , I have to change the code. I just gave you some snippet so that you get some idea. I will rephrase the code and post later
Message 10 of 15
mzakiralam
in reply to: bvyas89

HI , please find below code. I have tested this and this is working. One thing I have changed in your excel file is a syntax. In your excel file it was 'Lower width'. I have changed it as 'Lower Width'. for your information, I have created a class 'Tower'. This tower class will collect all the necessary data from excel file. I have test this code and it is working fine. Hope you will find it useful. I did not put comment on the code as it is self explanatory. but incase if you do not get anything just ask me.

 

   <CommandMethod("TR")> Public Sub DrawTower()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim filePath As String = "C:\Users\alamzaki\Desktop\TowerInput.xls"
        Dim traTower As New Tower(filePath)
        'MsgBox(traTower.triInfoList.Count)
        'MsgBox(traTower.triInfoList.Item(0).panelHeight)
        Using docLock As DocumentLock = doc.LockDocument()
            Using tx As Transaction = db.TransactionManager.StartTransaction()
                Dim bt As BlockTable = tx.GetObject(db.BlockTableId, OpenMode.ForRead)
                Dim ms As BlockTableRecord = tx.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
                Dim basePoint As Point2d = New Point2d(traTower.triInfoList.Item(0).lowerWidth / 2, 0)
                For i As Integer = 0 To traTower.triInfoList.Count - 1
                    Dim base As Double = traTower.triInfoList.Item(i).lowerWidth
                    Dim ht As Double = traTower.triInfoList.Item(i).panelHeight
                    Dim point1 As Point2d = New Point2d(basePoint.X - base / 2, basePoint.Y)
                    Dim point2 As Point2d = New Point2d(basePoint.X, basePoint.Y + ht)
                    Dim point3 As Point2d = New Point2d(basePoint.X + base / 2, basePoint.Y)
                    Call TraingleBuild(point1, point2, point3, tx, ms)
                    basePoint = point2
                Next
                tx.Commit()
            End Using
        End Using
    End Sub

 Public Sub TraingleBuild(pt1 As Point2d, pt2 As Point2d, pt3 As Point2d, trans As Transaction, blkTblRec As BlockTableRecord)
        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)
        'for leg do not close the polyline
        tra.Closed = True
        blkTblRec.AppendEntity(tra)
        trans.AddNewlyCreatedDBObject(tra, True)
    End Sub

Public Class Tower
    Structure TriangleInfo
        Dim panelHeight As Double
        Dim upperWidth As Double
        Dim lowerWidth As Double
    End Structure
    Public triInfoList As New List(Of TriangleInfo)

    Sub New(excelFilePath As String)
        'read excel file
        Try
            Dim xlApp As New Excel.Application
            Dim xlWorkBook As Excel.Workbook = xlApp.Workbooks.Open(excelFilePath)
            Dim xlSheet As Excel.Worksheet = xlWorkBook.Worksheets("Sheet1")
            Dim range As Excel.Range
            Dim rCnt As Integer
            Dim cCnt As Integer
            Dim Obj As Object
            Dim stTriangleInfo As New TriangleInfo()
            range = xlSheet.UsedRange

            For rCnt = 2 To range.Rows.Count
                For cCnt = 1 To range.Columns.Count
                    Obj = CType(range.Cells(rCnt, cCnt), Excel.Range)
                    'MsgBox(Obj.value)
                    If xlSheet.Cells(1, cCnt).Value = "Panel Height" Then
                        stTriangleInfo.panelHeight = CDbl(Obj.Value)
                    ElseIf xlSheet.Cells(1, cCnt).Value = "Upper Width" Then
                        stTriangleInfo.upperWidth = CDbl(Obj.Value)
                    ElseIf xlSheet.Cells(1, cCnt).Value = "Lower Width" Then
                        stTriangleInfo.lowerWidth = CDbl(Obj.value)
                    End If
                Next
                triInfoList.Add(stTriangleInfo)
            Next
            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

    Private 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

 

Message 11 of 15
bvyas89
in reply to: mzakiralam

Thank you... With reference to your given code and modifications needed to draw tower my task is completed successfully. Thank you very much.

Message 12 of 15
bvyas89
in reply to: bvyas89

Hello mr mzakiralam,

 

Can you please help me. I want to assign Dtext or label to each polyline while drawing it or after drawing it. how can i do that. I know how to assign dtext to line.. but confused with polyline. Please help me. Please  find the dwg attach herewith for reference.

 

code using to draw polyline is as below:

 

'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 Xx As Double = ((base - uWidth) / 2)
' Dim pt1 As Point2d = New Point2d(0, 0)
Dim pt1 As Point2d = New Point2d(0, 0)
Dim pt2 As Point2d = New Point2d(base, 0)
Dim pt3 As Point2d = New Point2d(base - Xx, tHeight)
Dim pt4 As Point2d = New Point2d(0, 0)
Dim pt5 As Point2d = New Point2d(0 + Xx, tHeight)
Dim pt6 As Point2d = New Point2d(base, 0)
'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.AddVertexAt(3, pt4, 0, 0, 0)
tra.AddVertexAt(4, pt5, 0, 0, 0)
tra.AddVertexAt(5, pt6, 0, 0, 0)
tra.Closed = True
'add triangle in model space
ms.AppendEntity(tra)
tx.AddNewlyCreatedDBObject(tra, True)
Dim line1 As Line = New Line(New Point3d(pt5.X, pt5.Y, 0), New Point3d(pt3.X, pt3.Y, 0))
ms.AppendEntity(line1)
tx.AddNewlyCreatedDBObject(line1, True)
tx.Commit()
End Using
End Using

Message 13 of 15
mzakiralam
in reply to: bvyas89

Hi , I had a look into your drawing. But I did not get your requirement. Because that was a single poyline. How can I know that which Label shoul go where. if you make sure that for every vertex there will be a Label then it is easier. Please make clear your requirement. I recommend you to open a new thread for your Problem. As this thread has already been marked solved so other People will not look into your Problem.
Message 14 of 15
bvyas89
in reply to: mzakiralam

thank you... I had already open a new tread but didnot get any solution from last 2 days so replied here. 

link to new thread is as below:

 

http://forums.autodesk.com/t5/NET/Assign-nomenclature-to-each-polyline/m-p/4874426

 

yes they are connecting polylines. with reference to your code i am able to draw  complete tower.

 

no i  want to label each line. within it.

Message 15 of 15
mzakiralam
in reply to: bvyas89

HI,

Okay, I got your point now. As you know how to draw text for a line so it will be easier for you now. What you need to do just cast the polyline then you will be able to get all vertices of that polyline. If you get all vertex then I think your problem will be solved. Please see below code snippet which will help you to get the polyline and its vertices.

 

 <CommandMethod("tst")> Public Sub TestPoly()
        Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Dim peo As PromptEntityOptions = New PromptEntityOptions(vbLf & "Select a polyline to label it:")
        Dim per As PromptEntityResult = ed.GetEntity(peo)
        Using tx As Transaction = db.TransactionManager.StartTransaction()
            Dim ent As Entity = tx.GetObject(per.ObjectId, OpenMode.ForRead)
            If TypeOf ent Is Polyline Then
                Dim pl As Polyline = TryCast(ent, Polyline)
                Dim vn As Integer = pl.NumberOfVertices
                For i = 0 To vn - 2
                    'get adjacent vertices of a polyline
                    Dim pt1 As Point2d = pl.GetPoint2dAt(i)
                    Dim pt2 As Point2d = pl.GetPoint2dAt(i + 1)
                    'do what you need
                Next
            End If
            tx.Commit()
        End Using
    End Sub

 

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