.NET

Reply
New Member
arun.2u
Posts: 2
Registered: ‎02-13-2007
Message 1 of 3 (117 Views)

Code Problem im VB.NET

117 Views, 2 Replies
02-13-2007 03:35 PM
i have been learning AutoCAD VB for a year long and capable of compiling program to some extend and then i came to know about .net so i downloaded Visual Basic 2005 Express edition and i have started with basic labs provided by autodesk and in the VBX i tried to mix the code form lab2 and 3 to get the desired output circle with a pick point and radius while i was capable of solving the get distance but have still problem with get point and are there and books for beginners for AutoCAD vb.net.

Here is the code i tried to Compile
"
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry

Public Class ArunCommands

' Define command 'Aruncmd1'
_
Public Sub Aruncmd1()
Try
' Type your code here
Dim poo As PromptPointOptions = New
PromptPointOptions("Specify
Center: ")
Dim por As PromptPointResult
Dim cir As Circle
Dim tbr As BlockTableRecord
Dim tb As BlockTable
Dim trans As Transaction
trans =
HostApplicationServices.WorkingDatabase().TransactionManager.StartTransa
ction()
Dim ed As Editor =
Application.DocumentManager.MdiActiveDocument.Editor
por = ed.GetPoint(poo)
If por.Status PromptStatus.OK Then
Return
End If
Dim gdis As PromptDistanceOptions = New
PromptDistanceOptions("Specify the rad: ")
Dim rad As PromptDoubleResult
Dim edc As Editor
rad = edc.GetDistance(gdis)
Dim radi As Double
radi = rad.ToString
cir = New Circle(por, Vector3d.ZAxis, radi)
tbr =
trans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId,
OpenMode.ForRead)
Dim tbid As ObjectId = tb.Item(BlockTableRecord.ModelSpace)
tbr = trans.GetObject(tbid, OpenMode.ForWrite)
tbr.AppendEntity(cir)
trans.AddNewlyCreatedDBObject(cir, True)

trans.Commit()
trans.Dispose()
Catch
MsgBox("Error Msg is: ")
End Try
End Sub

End Class
"
with regards
Arun Prasad.H
Active Contributor
deepa
Posts: 37
Registered: ‎01-10-2007
Message 2 of 3 (117 Views)

Re: Code Problem im VB.NET

02-13-2007 09:11 PM in reply to: arun.2u
pls define the command before sub

_
Public Sub Aruncmd1()
Try
' Type your code here
Dim poo As PromptPointOptions = New
PromptPointOptions("Specify

try this i hope
New Member
arun.2u
Posts: 2
Registered: ‎02-13-2007
Message 3 of 3 (117 Views)

Re: Code Problem im VB.NET

02-14-2007 05:37 PM in reply to: arun.2u
Thanks for the reply
I think i have corrected the problem and capable of compiling the output dll but while i run the dll (AutoCAD) i cannot see the circle and here is the code

"
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry

Public Class ArunCommands
"CommandMethod("acir")" _
Public Sub acir()
Dim db As Database = HostApplicationServices.WorkingDatabase()
Dim trans As Transaction = db.TransactionManager.StartTransaction()
Try
Dim poo As PromptPointOptions = New PromptPointOptions("Specify Center: ")
Dim por As PromptPointResult
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
por = ed.GetPoint(poo)
If por.Status PromptStatus.OK Then
Return
End If
Dim ecx As Double
ecx = por.Value.X
Dim ecy As Double
ecy = por.Value.Y
Dim ecz As Double
ecz = por.Value.Z
Dim cen As Point3d
cen = New Point3d(ecx, ecy, ecz)
Dim gdis As PromptDistanceOptions = New PromptDistanceOptions("Specify the rad: ")
Dim rad As PromptDoubleResult
rad = ed.GetDistance(gdis)
Dim radi As Double
radi = rad.ToString
Dim cir As Circle = New Circle(New Point3d(ecx, ecy, ecz), Vector3d.ZAxis, radi)
Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead)
Dim bts As BlockTableRecord = trans.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

bts.AppendEntity(cir)
trans.AddNewlyCreatedDBObject(cir, True)

trans.Commit()
Catch ex As System.Exception
trans.Dispose()
MsgBox("Error Msg is: " + ex.Message)
End Try
End Sub

End Class
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.