.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Reply
Message 1 of 7
richard.harris
560 Views, 6 Replies

donut

i'm trying to draw a simle donut could someone give me sme insight please.
6 REPLIES 6
Message 2 of 7
fixo
in reply to: richard.harris

Try this one


Imports System
Imports System.Collections
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports AcadRT = Autodesk.AutoCAD.Runtime
Imports AcadED = Autodesk.AutoCAD.EditorInput
Imports AcDB = Autodesk.AutoCAD.DatabaseServices
Imports AcadApp = Autodesk.AutoCAD.ApplicationServices.Application
Imports Autodesk.AutoCAD.Windows
............................................................


Shared Function getreal(ByVal msg As String, ByRef d As Double) As Boolean
Dim ed As Editor = AcadApp.DocumentManager.MdiActiveDocument.Editor
Dim res As PromptDoubleResult = ed.GetDouble(msg)
If res.Status PromptStatus.OK Then
Return False
End If
d = res.Value
Return True
End Function


Shared Function getpoint(ByVal msg As String, ByRef P As Point3d) As Boolean
Dim ed As Editor = AcadApp.DocumentManager.MdiActiveDocument.Editor
Dim res As PromptPointResult = ed.GetPoint(msg)
If res.Status PromptStatus.OK Then
Return False
End If
P = res.Value
Return True
End Function


Public Shared Sub CreateDonut()
Dim ed As Editor = AcadApp.DocumentManager.MdiActiveDocument.Editor
Dim db As AcDB.Database = HostApplicationServices.WorkingDatabase
Dim ptArr As Point3dCollection = New Point3dCollection
Dim eRad As Double
Dim iRad As Double
Dim p As Point3d = New Point3d
Try
Using tr As AcDB.Transaction = db.TransactionManager.StartTransaction()
Using bt As BlockTable = CType(tr.GetObject(db.BlockTableId, OpenMode.ForRead, False), BlockTable)
Using btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
If Not getreal(ControlChars.CrLf & "Enter outer radius: ", eRad) Then
Return
End If

If Not getreal(ControlChars.CrLf & "Enter inner radius: ", iRad) Then
Return
End If

If Not getpoint(ControlChars.CrLf & "Pick point: ", p) Then
Return
End If

Dim spt As Point2d = New Point2d(p.X - eRad + (eRad - iRad) / 2, p.Y)
Dim ept As Point2d = New Point2d(p.X + eRad - (eRad - iRad) / 2, p.Y)
ptArr.Add(New Point3d(spt.X, spt.Y, p.Z))
ptArr.Add(New Point3d(ept.X, ept.Y, p.Z))
Dim blgArr As DoubleCollection = New DoubleCollection()
blgArr.Add(1.0)
blgArr.Add(1.0)
Dim oPline As Polyline2d = New Polyline2d(Poly2dType.SimplePoly, ptArr, 0.0, True, eRad - iRad, eRad - iRad, blgArr)
oPline.Closed = True

btr.AppendEntity(oPline)
tr.AddNewlyCreatedDBObject(oPline, True)
tr.Commit()

End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message & ControlChars.CrLf & ex.StackTrace, MsgBoxStyle.Critical, "Exception")
End Try

End Sub

~'J'~
Message 3 of 7
Anonymous
in reply to: richard.harris

GetDistance() is for getting distances, not GetDouble().

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

wrote in message news:5987675@discussion.autodesk.com...
Try this one
Message 4 of 7
fixo
in reply to: richard.harris

Thanks again, I've forgot about

~'J'~
Message 5 of 7
fixo
in reply to: richard.harris

As Tony said:

Shared Function getdistance(ByVal msg As String, ByRef d As Double) As Boolean
Dim ed As Editor = AcadApp.DocumentManager.MdiActiveDocument.Editor
Dim res As PromptDoubleResult = ed.GetDistance(msg)
If res.Status <> PromptStatus.OK Then
Return False
End If
d = res.Value
Return True
End Function
Shared Function getpoint(ByVal msg As String, ByRef P As Point3d) As Boolean
Dim ed As Editor = AcadApp.DocumentManager.MdiActiveDocument.Editor
Dim res As PromptPointResult = ed.GetPoint(msg)
If res.Status <> PromptStatus.OK Then
Return False
End If
P = res.Value
Return True
End Function
Public Shared Sub CreateDonut()

Dim ed As Editor = AcadApp.DocumentManager.MdiActiveDocument.Editor
Dim db As AcDB.Database = HostApplicationServices.WorkingDatabase
Dim ptArr As Point3dCollection = New Point3dCollection
Dim eRad As Double
Dim iRad As Double
Dim p As Point3d = New Point3d
Try
Using tr As AcDB.Transaction = db.TransactionManager.StartTransaction()
Using bt As BlockTable = CType(tr.GetObject(db.BlockTableId, OpenMode.ForRead, False), BlockTable)
Using btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
If Not getdistance(ControlChars.CrLf & "Enter outer radius: ", eRad) Then
Return
End If

If Not getdistance(ControlChars.CrLf & "Enter inner radius: ", iRad) Then
Return
End If

If Not getpoint(ControlChars.CrLf & "Pick point: ", p) Then
Return
End If

Dim spt As Point2d = New Point2d(p.X - eRad + (eRad - iRad) / 2, p.Y)
Dim ept As Point2d = New Point2d(p.X + eRad - (eRad - iRad) / 2, p.Y)
ptArr.Add(New Point3d(spt.X, spt.Y, p.Z))
ptArr.Add(New Point3d(ept.X, ept.Y, p.Z))
Dim blgArr As DoubleCollection = New DoubleCollection()
blgArr.Add(1.0)
blgArr.Add(1.0)
Dim oPline As Polyline2d = New Polyline2d(Poly2dType.SimplePoly, ptArr, 0.0, True, eRad - iRad, eRad - iRad, blgArr)
oPline.Closed = True

btr.AppendEntity(oPline)
tr.AddNewlyCreatedDBObject(oPline, True)
tr.Commit()

End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message & ControlChars.CrLf & ex.StackTrace, MsgBoxStyle.Critical, "Exception")
End Try

End Sub

~'J'~
Message 6 of 7

thank you both so much this is a great help.... 🙂


wrote in message news:5987719@discussion.autodesk.com...
As Tony said:

Shared Function getdistance(ByVal msg As String, ByRef d As Double) As
Boolean
Dim ed As Editor =
AcadApp.DocumentManager.MdiActiveDocument.Editor
Dim res As PromptDoubleResult = ed.GetDistance(msg)
If res.Status <> PromptStatus.OK Then
Return False
End If
d = res.Value
Return True
End Function
Shared Function getpoint(ByVal msg As String, ByRef P As Point3d) As
Boolean
Dim ed As Editor =
AcadApp.DocumentManager.MdiActiveDocument.Editor
Dim res As PromptPointResult = ed.GetPoint(msg)
If res.Status <> PromptStatus.OK Then
Return False
End If
P = res.Value
Return True
End Function
Public Shared Sub CreateDonut()

Dim ed As Editor =
AcadApp.DocumentManager.MdiActiveDocument.Editor
Dim db As AcDB.Database =
HostApplicationServices.WorkingDatabase
Dim ptArr As Point3dCollection = New Point3dCollection
Dim eRad As Double
Dim iRad As Double
Dim p As Point3d = New Point3d
Try
Using tr As AcDB.Transaction =
db.TransactionManager.StartTransaction()
Using bt As BlockTable =
CType(tr.GetObject(db.BlockTableId, OpenMode.ForRead, False), BlockTable)
Using btr As BlockTableRecord =
CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
If Not getdistance(ControlChars.CrLf & "Enter
outer radius: ", eRad) Then
Return
End If

If Not getdistance(ControlChars.CrLf & "Enter
inner radius: ", iRad) Then
Return
End If

If Not getpoint(ControlChars.CrLf & "Pick point:
", p) Then
Return
End If

Dim spt As Point2d = New Point2d(p.X - eRad +
(eRad - iRad) / 2, p.Y)
Dim ept As Point2d = New Point2d(p.X + eRad -
(eRad - iRad) / 2, p.Y)
ptArr.Add(New Point3d(spt.X, spt.Y, p.Z))
ptArr.Add(New Point3d(ept.X, ept.Y, p.Z))
Dim blgArr As DoubleCollection = New
DoubleCollection()
blgArr.Add(1.0)
blgArr.Add(1.0)
Dim oPline As Polyline2d = New
Polyline2d(Poly2dType.SimplePoly, ptArr, 0.0, True, eRad - iRad, eRad -
iRad, blgArr)
oPline.Closed = True

btr.AppendEntity(oPline)
tr.AddNewlyCreatedDBObject(oPline, True)
tr.Commit()

End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message & ControlChars.CrLf & ex.StackTrace,
MsgBoxStyle.Critical, "Exception")
End Try

End Sub

~'J'~
Message 7 of 7

i'm using C# i'll try to use your example and translate to C#
wrote in message news:5989864@discussion.autodesk.com...
thank you both so much this is a great help.... 🙂


wrote in message news:5987719@discussion.autodesk.com...
As Tony said:

Shared Function getdistance(ByVal msg As String, ByRef d As Double) As
Boolean
Dim ed As Editor =
AcadApp.DocumentManager.MdiActiveDocument.Editor
Dim res As PromptDoubleResult = ed.GetDistance(msg)
If res.Status <> PromptStatus.OK Then
Return False
End If
d = res.Value
Return True
End Function
Shared Function getpoint(ByVal msg As String, ByRef P As Point3d) As
Boolean
Dim ed As Editor =
AcadApp.DocumentManager.MdiActiveDocument.Editor
Dim res As PromptPointResult = ed.GetPoint(msg)
If res.Status <> PromptStatus.OK Then
Return False
End If
P = res.Value
Return True
End Function
Public Shared Sub CreateDonut()

Dim ed As Editor =
AcadApp.DocumentManager.MdiActiveDocument.Editor
Dim db As AcDB.Database =
HostApplicationServices.WorkingDatabase
Dim ptArr As Point3dCollection = New Point3dCollection
Dim eRad As Double
Dim iRad As Double
Dim p As Point3d = New Point3d
Try
Using tr As AcDB.Transaction =
db.TransactionManager.StartTransaction()
Using bt As BlockTable =
CType(tr.GetObject(db.BlockTableId, OpenMode.ForRead, False), BlockTable)
Using btr As BlockTableRecord =
CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
If Not getdistance(ControlChars.CrLf & "Enter
outer radius: ", eRad) Then
Return
End If

If Not getdistance(ControlChars.CrLf & "Enter
inner radius: ", iRad) Then
Return
End If

If Not getpoint(ControlChars.CrLf & "Pick point:
", p) Then
Return
End If

Dim spt As Point2d = New Point2d(p.X - eRad +
(eRad - iRad) / 2, p.Y)
Dim ept As Point2d = New Point2d(p.X + eRad -
(eRad - iRad) / 2, p.Y)
ptArr.Add(New Point3d(spt.X, spt.Y, p.Z))
ptArr.Add(New Point3d(ept.X, ept.Y, p.Z))
Dim blgArr As DoubleCollection = New
DoubleCollection()
blgArr.Add(1.0)
blgArr.Add(1.0)
Dim oPline As Polyline2d = New
Polyline2d(Poly2dType.SimplePoly, ptArr, 0.0, True, eRad - iRad, eRad -
iRad, blgArr)
oPline.Closed = True

btr.AppendEntity(oPline)
tr.AddNewlyCreatedDBObject(oPline, True)
tr.Commit()

End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.Message & ControlChars.CrLf & ex.StackTrace,
MsgBoxStyle.Critical, "Exception")
End Try

End Sub

~'J'~

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