Sorry for missing details !
There is no error, I know that is does'nt work because I put a message and I see it, but not the line...
If I put back the <CommandMethod("AddLine")> _ the line is drawn...
I use MVS Express 2012 and Autocad 2015.
Here is the code:
Code:
Imports System.Collections.Generic
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Internal
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
Namespace CRGagnonPlugin 'Declares the name of a namespace
'Declares the name of a class
Public Class myCommands
' Function EffectiveName: GET EFFECTIVE NAME OF DYNAMIC BLOCK
Public Function EffectiveName(tr As Transaction, blkRef As BlockReference) As String
Dim blkTr As BlockTableRecord = Nothing
If (blkRef.IsDynamicBlock) Or (blkRef.Name.StartsWith("*U", StringComparison.InvariantCultureIgnoreCase)) Then
blkTr = TryCast(tr.GetObject(blkRef.DynamicBlockTableRecord, OpenMode.ForRead), BlockTableRecord)
Else
blkTr = TryCast(tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead), BlockTableRecord)
End If
'Return Effective Name
Return blkTr.Name
End Function
' Function InsertionPoint: GET INSERTION POINT
Public Function InsertionPoint() As Point3d
'Get the current database and start the Transaction Manager
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
'Declare prompt
Dim pPtRes As PromptPointResult
Dim pPtOpts As PromptPointOptions = New PromptPointOptions("")
'Prompt for insertion point
pPtOpts.Message = vbLf & "Specify insertion point: "
pPtRes = acDoc.Editor.GetPoint(pPtOpts)
Dim ptStart As Point3d = pPtRes.Value
'Exit if the user presses ESC or cancels the command
If pPtRes.Status = PromptStatus.Cancel Then
'Return 0,0,0 when cancelled
ptStart = New Point3d(0, 0, 0)
Return ptStart
Exit Function
End If
'Return Insertion Point
Return ptStart
End Function
' SUB BuildTable: BUILD TABLE WITH DATAS
Public Sub BuildTable(intTableRows As Integer)
'Ask for insertion point
InsertionPoint()
'Draws actual line
Dim acadApp As Object
acadApp = Application.AcadApplication
Dim startPoint(0 To 2) As Double
Dim endPoint(0 To 2) As Double
startPoint(0) = 0 : startPoint(1) = 0 : startPoint(2) = 0
endPoint(0) = 500 : endPoint(1) = 500 : endPoint(2) = 0
acadApp.ActiveDocument.ModelSpace.AddLine(startPoint, endPoint)
MsgBox("The line is supposed to be drawn...")
End Sub
' Sub WindowsList: WINDOWS LIST (Get quantity of each window types)
'Declares Autocad command name
<CommandMethod("wli")> _
Public Sub WindowsList()
'Declares variables and objects
Dim blkname As String
Dim doc As Document = Application.DocumentManager.MdiActiveDocument()
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
'Handle all possible errors...
Try
'Beginning of a Using block
Using tr As Transaction = db.TransactionManager.StartTransaction
'Asks for Selection Set (use this for select all: res = ed.SelectAll(filt))
Dim res As PromptSelectionResult
Dim tvs(0) As TypedValue
tvs(0) = New TypedValue(0, "insert")
Dim filt As SelectionFilter = New SelectionFilter(tvs)
res = ed.GetSelection(filt)
'Checks Selection Set (not empty)
If res.Status <> PromptStatus.OK Then
Return
End If
'Creates Datatable to store temporary datas (8072.OD ou P81G+21)
Dim table As New System.Data.DataTable
'Creates Datatable Columns
With table
.Columns.Add("IDVALUE", GetType(String))
.Columns.Add("IDQTY", GetType(Integer))
End With
'Looping Selection Set
For Each sobj As SelectedObject In res.Value
'Declares objects
Dim obj As DBObject = DirectCast(tr.GetObject(sobj.ObjectId, OpenMode.ForRead, False), DBObject)
Dim blkRef As BlockReference = TryCast(obj, BlockReference)
'Checks BlockReference (not empty)
If blkRef IsNot Nothing Then
'Function: Get Effective Name
blkname = EffectiveName(tr, blkRef)
'Checks if its a Dynamic Block
If blkRef.IsDynamicBlock Then
'Declares AttributeCollection
Dim attCol As AttributeCollection = blkRef.AttributeCollection
'Looping AttributeCollection
For Each attId As ObjectId In attCol
'Declares AttributeReference
Dim att As AttributeReference = TryCast(tr.GetObject(attId, OpenMode.ForWrite, False), AttributeReference)
'Declares search variable
Dim booFound As Boolean = False
'Checks Attributes Tag value (must be ID for windows)
If att.Tag = "ID" Then
'Checks Datatable (not empty)
If table.Rows.Count > 0 Then
'Looping rowa in Datatable
For Each row As DataRow In table.Rows
'Checks Windows Type it's not existing in Datatable
If row.Item("IDVALUE") = att.TextString.ToString Then
'If existing: add 1 to quantity
row.Item("IDQTY") = row.Item("IDQTY") + 1
'Set search variable
booFound = True
End If
Next row
'If not existing: add window type and 1 to quantity
If booFound = False Then
table.Rows.Add(att.TextString.ToString, 1)
End If
Else
'If Datatable is empty: add window type and 1 to quantity
table.Rows.Add(att.TextString.ToString, 1)
End If
End If
Next
End If
End If
Next
'Build the table with datas
BuildTable(table.Rows.Count)
'BuildTable()
''Display results in command line
'For Each row As DataRow In table.Rows
'ed.WriteMessage(vbLf + row.Item("IDVALUE").ToString + ": " + row.Item("IDQTY").ToString)
'Next row
'tr.Commit()
'End of a Using block
End Using
'Handle all possible errors...
Catch ex As Autodesk.AutoCAD.Runtime.Exception
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog((ex.ToString() & vbLf) + ex.Message)
Finally
ed.WriteMessage(vbLf + "Command completed...")
End Try
End Sub
End Class
End Namespace
Thanks !