PDA

View Full Version : How to draw "Donut"?



Robert
11-17-2009, 05:26 PM
The line and circle can be done by "AddLine" and "AddCircle", but how could I get "Donut"? Is it possible?

Andy Pope
11-18-2009, 05:32 AM
Use the AddShape method specifying which shape you want to create



ActiveSheet.Shapes.AddShape msoShapeDonut, 10, 10, 100, 100

Tommy
11-18-2009, 12:36 PM
Hi Robert,

I think you are talking about AutoCad.

Let me know if you need more help or an explaination. I butchered the help file exaple of a light weight polyline. :)


Sub Example_AddLightWeightPolyline()
' This example creates a lightweight polyline in model space.

Dim plineObj As AcadLWPolyline
Dim points(0 To 5) As Double

' Define the 2D polyline points
points(0) = 1: points(1) = 1
points(2) = 2: points(3) = 2
points(4) = 1: points(5) = 1

' Create a lightweight Polyline object in model space
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
'set buldge to make it a semicircle
plineObj.SetBulge 0, 1
plineObj.SetBulge 1, 1
'set the thickness
plineObj.SetWidth 0, 0.5, 0.5
plineObj.SetWidth 1, 0.5, 0.5

ZoomAll

End Sub

Robert
11-18-2009, 10:55 PM
Hi Andy/Tommy,

Thank you! But I don't know how to use Andy's code, only Tommy's works. And I change the last two line for thickness to 0,2,2 and 1,2,2 and I get the solid. It's really nice. But if go on this way, I have to calculate first, to get my real circle central point, it seems more procedure, could we have more easier way? But anyway, it's so nice to know this solution! Thank you both of you!

Andy Pope
11-19-2009, 01:32 AM
Sory Robert I assumed you were refering to Excel. I didn't notice you had posted in the Other Apps forum.

Robert
11-19-2009, 03:26 AM
Andy,

Thank you for your good idea, I'll try to do it at Excel instead of AutoCAD when the work is not so important next time!

Regards,
Robert

Tommy
11-19-2009, 06:21 AM
Hi Robert,

Now that I have a better handle on what you are looking for :)

The below subs/functions will draw a donut. The test sub shows the usage. The only input that is required is the x,y cordinates and the diameter of the donut. It will default to the "closed" donut in other words a solid circle. If you don't need the solid circle enter a thickness that is smaller than the diameter.

Sub test()
Donut 2, 2, 0.5
Donut 5, 2, 0.5
Donut 5, 5, 4
Donut 10, 10, 8
Donut 82, 82, 4
End Sub
Sub Donut(x As Double, y As Double, Dia As Double, Optional Thick As Double = 0)
Dim plineObj As AcadLWPolyline, Rad As Double
Dim points(0 To 5) As Double, TpPt() As Double, BtmPt() As Double, Pt(2) As Double
Rad = Dia / 2
Pt(0) = x
Pt(1) = y
TpPt = ThisDrawing.Utility.PolarPoint(Pt, DtoR(90), Rad)
BtmPt = ThisDrawing.Utility.PolarPoint(TpPt, DtoR(270), Dia)
' Define the 2D polyline points
points(0) = TpPt(0): points(1) = TpPt(1)
points(2) = BtmPt(0): points(3) = BtmPt(1)
points(4) = TpPt(0): points(5) = TpPt(1)

' Create a lightweight Polyline object in model space
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
'set buldge to make it a semicircle
plineObj.SetBulge 0, 1
plineObj.SetBulge 1, 1
If Thick > 0 Then
Rad = Thick
Else
Rad = Dia
End If
'set the thickness
plineObj.SetWidth 0, Rad, Rad
plineObj.SetWidth 1, Rad, Rad
End Sub
Public Function DtoR(iThisAngle As Double) As Double
DtoR = (iThisAngle / 180) * 3.14159265358979
End Function

Robert
11-26-2009, 08:57 PM
Tommy,

With this idea:yes, I don't need extra time at Excel, thank you!

Regards,
Robert