VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need help with inserting donut (error too many points)

12 REPLIES 12
Reply
Message 1 of 13
Anonymous
513 Views, 12 Replies

Need help with inserting donut (error too many points)

error :
Too few elements in SafeArray or total number of elements is not a multiple of three.

I would like to 3 pick points and place items there
I need to put a donut or leader with donut and a line to the bubble pointer (Wblock)
1st point; where center of donut.
2nd point; center of bubble pointer (Wblock)
3rd point; end of point of line “nearest” to the edge of the circle (Wblock)
So the line is drawn from the center of the donut to the edge of the circle.
The Wblock is a circle with 2 attributes which is entered by code.
VBA is attached code.
The attached file has the Set donut REMed out.

Thanks
12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: Anonymous

No code attached?
Message 3 of 13
Anonymous
in reply to: Anonymous

Ok, I thougth I did,
Message 4 of 13
Anonymous
in reply to: Anonymous

where does it crash?
Message 5 of 13
Anonymous
in reply to: Anonymous

Set Donut = ThisDrawing.ModelSpace.AddLightWeightPolyline(returnPntDonut)
Error:
Too few elements in SafeArray ot total number of elements is not a multiple of three.
Message 6 of 13
Anonymous
in reply to: Anonymous

The problem is probably in your Polyline Points.

Here is an example of LW Plyline Points:

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

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


Let me know if that worked for you
Message 7 of 13
Anonymous
in reply to: Anonymous

The example above is a Ployline with 5 points!!!!
Message 8 of 13
Anonymous
in reply to: Anonymous

Here'e an example for creating a Donut using the default values for a donut:

Sub DonutTest()
Dim dID As Double
Dim dOD As Double
Dim vPt As Variant
Dim dRadius As Double
Dim dWidth As Double

vPt = ThisDrawing.Utility.GetPoint(, vbCr & "Select point for donut: ")
dID = ThisDrawing.GetVariable("donutid") / 2
dOD = ThisDrawing.GetVariable("donutod") / 2
dRadius = (dID + dOD) / 2#
dWidth = dOD - dID

Dim vPt1 As Variant
Dim vPt2 As Variant
Dim vPts(3) As Double
Dim opoly As AcadLWPolyline

vPt1 = ThisDrawing.Utility.PolarPoint(vPt, 0#, dRadius)
vPt2 = ThisDrawing.Utility.PolarPoint(vPt, 0#, -dRadius)
vPts(0) = vPt1(0)
vPts(1) = vPt1(1)
vPts(2) = vPt2(0)
vPts(3) = vPt2(1)

Set opoly = ThisDrawing.ModelSpace.AddLightWeightPolyline(vPts)
opoly.ConstantWidth = dWidth
opoly.SetBulge 0, 1#
opoly.SetBulge 1, 1#
opoly.Closed = True
End Sub




"dbp428" wrote in message news:6003834@discussion.autodesk.com...
Set Donut = ThisDrawing.ModelSpace.AddLightWeightPolyline(returnPntDonut)
Error:
Too few elements in SafeArray ot total number of elements is not a multiple
of three.
Message 9 of 13
Anonymous
in reply to: Anonymous

Ok; your code makes a donut, my donut needs to be
ID = 0 and OD = .03
I don't understand what this code does.
dID = ThisDrawing.GetVariable("donutid") / 2
dOD = ThisDrawing.GetVariable("donutod") / 2
dRadius = (dID + dOD) / 2#
dWidth = dOD - dID

Is all this required to get the points into something this line can understand? vPts
Set opoly = ThisDrawing.ModelSpace.AddLightWeightPolyline(vPts)
Message 10 of 13
Anonymous
in reply to: Anonymous

change your code to this:

Sub DonutTest()
Dim dID As Double
Dim dOD As Double
Dim vPt As Variant
Dim dRadius As Double
Dim dWidth As Double

vPt = ThisDrawing.Utility.GetPoint(, vbCr & "Select point for donut: ")

dRadius = 0.0075
dWidth = 0.015

Dim vPt1 As Variant
Dim vPt2 As Variant
Dim vPts(3) As Double
Dim opoly As AcadLWPolyline

vPt1 = ThisDrawing.Utility.PolarPoint(vPt, 0#, dRadius)
vPt2 = ThisDrawing.Utility.PolarPoint(vPt, 0#, -dRadius)
vPts(0) = vPt1(0)
vPts(1) = vPt1(1)
vPts(2) = vPt2(0)
vPts(3) = vPt2(1)

Set opoly = ThisDrawing.ModelSpace.AddLightWeightPolyline(vPts)
opoly.ConstantWidth = dWidth
opoly.SetBulge 0, 1#
opoly.SetBulge 1, 1#
opoly.Closed = True
End Sub

-J
Message 11 of 13
Anonymous
in reply to: Anonymous

No, all that is to determine the Radius & width based on the values saved in
the drawing in the Sysvars DONUTID & DONUTOD. If you kniow what values you
want, replace the portion where I get these variables with your values.

What I did was to take the 2 Diameters divided by 2 to get the Iner & Outer
radii, add them together and divide by 2 to get the Radius of the donut.
(half the average of the 2). For the width of the Pline I then subtracted
the inner from the outer radius.

To get the 2 points required for the AddLightWeightPolyline method, I used
the PolarPoint to get the points on an arc having the determined radius, the
first at 0 degrees from the picked point, the other 180 degrees (determined
by going 0 degrees at the negative radius distance). I then combined the XY
of these two points into a 4 elememt array which is what the the LWPolyline
method needs.

Whew!. Make sense?

"dbp428" wrote in message news:6004392@discussion.autodesk.com...
Ok; your code makes a donut, my donut needs to be
ID = 0 and OD = .03
I don't understand what this code does.
dID = ThisDrawing.GetVariable("donutid") / 2
dOD = ThisDrawing.GetVariable("donutod") / 2
dRadius = (dID + dOD) / 2#
dWidth = dOD - dID

Is all this required to get the points into something this line can
understand? vPts
Set opoly = ThisDrawing.ModelSpace.AddLightWeightPolyline(vPts)
Message 12 of 13
Anonymous
in reply to: Anonymous

Yes I got it all fixed.
Thank you!!!! 🙂
see attached file
Message 13 of 13
Anonymous
in reply to: Anonymous

The only thing I would recommend in the future, put all your user input at the start of the code. That way you can isolate and error prove it better.

Just my 2c

-J

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report