Null Object Id

Null Object Id

Anonymous
Not applicable
2,334 Views
3 Replies
Message 1 of 4

Null Object Id

Anonymous
Not applicable
I get an run-time error : -2145386481, Null Object Id while looping
throug the vertices of a polyline and getting the point x and y values.
It seems to be failing on the .GetBulge(index) method.

Another note is that it seems to be somewhere in the middle of the
vertices array not at the begining or end.

Any ideas on what could be causing this?
0 Likes
2,335 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
The problem seems to be because the pline being queried is a "Polyline" not
an "LWPolyline". I changed it to a "LWPolyline" and it worked ok.

This brings up a new question. How do I control how the user draws the
polyline? Is there a way to change a "Polyline" to an "LWPolyline" through
vb without deleteing and creating a new one with and .Addxxx method?

Bill Wright wrote:

> I get an run-time error : -2145386481, Null Object Id while looping
> throug the vertices of a polyline and getting the point x and y values.
> It seems to be failing on the .GetBulge(index) method.
>
> Another note is that it seems to be somewhere in the middle of the
> vertices array not at the begining or end.
>
> Any ideas on what could be causing this?
0 Likes
Message 3 of 4

Anonymous
Not applicable
The system variable PLineType controls what type of pline a new one will be.
The Convert command converts existing plines.


--
R. Robert Bell, MCSE
www.AcadX.com


"Bill Wright" wrote in message
news:3EAF7420.270E2920@archsky.com...
| The problem seems to be because the pline being queried is a "Polyline"
not
| an "LWPolyline". I changed it to a "LWPolyline" and it worked ok.
|
| This brings up a new question. How do I control how the user draws the
| polyline? Is there a way to change a "Polyline" to an "LWPolyline" through
| vb without deleteing and creating a new one with and .Addxxx method?
|
| Bill Wright wrote:
|
| > I get an run-time error : -2145386481, Null Object Id while looping
| > throug the vertices of a polyline and getting the point x and y values.
| > It seems to be failing on the .GetBulge(index) method.
| >
| > Another note is that it seems to be somewhere in the middle of the
| > vertices array not at the begining or end.
| >
| > Any ideas on what could be causing this?
|
0 Likes
Message 4 of 4

Anonymous
Not applicable
Hi Bill,

Here's ya a little something that should help.

Joe
--

Option Explicit

'Autodesk example of creating a polyline
Sub Example_AddPolyline()
' This example creates a polyline in model space.

Dim plineObj As AcadPolyline
Dim Points(0 To 14) As Double

' Define the 2D polyline points
Points(0) = 1: Points(1) = 1: Points(2) = 0
Points(3) = 1: Points(4) = 2: Points(5) = 0
Points(6) = 2: Points(7) = 2: Points(8) = 0
Points(9) = 3: Points(10) = 2: Points(11) = 0
Points(12) = 4: Points(13) = 4: Points(14) = 0

' Create a light weight Polyline object in model space
Set plineObj = ThisDrawing.ModelSpace.AddPolyline(Points)
ZoomAll
End Sub

'Autodesk example of creating a LWPolyline
Sub Example_AddLightWeightPolyline()
' This example creates a light weight polyline in model space.

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

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

' Create a light weight Polyline object in model space
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(Points)
ZoomAll
End Sub

'Joe Sutphin routine to change a polyline to a LWPolyline
Public Sub ConvertPolylineToLWPolyline()
Dim oEntity As AcadEntity
Dim Point As Variant
Dim oLWPolyline As AcadLWPolyline
Dim oSS As AcadSelectionSet
Dim iFilterCode(0) As Integer
Dim vFilterValue(0) As Variant
Dim oPolyline As AcadPolyline
'handle errors inline with code
On Error Resume Next
'delete any selection sets hanging around
Application.ActiveDocument.SelectionSets("Polys").Delete
'reset error handling
On Error GoTo 0
'create our new selection set
Set oSS = Application.ActiveDocument.SelectionSets.Add("Polys")
'construct a selection set filter for polylines only
iFilterCode(0) = 0: vFilterValue(0) = "Polyline"
'get user to select a PViewport
oSS.SelectOnScreen iFilterCode, vFilterValue
'construct new LWPolylines for each polyline in the selection set
If oSS.Count Then
For Each oPolyline In oSS
Dim Points() As Double
Dim i As Long
Dim j As Long
ReDim Points((((UBound(oPolyline.Coordinates) + 1) / 3) * 2) - 1)
For i = 0 To UBound(oPolyline.Coordinates)
Points(j) = oPolyline.Coordinates(i): i = i + 1: j = j + 1
Points(j) = oPolyline.Coordinates(i): i = i + 1: j = j + 1
Next i

Set oLWPolyline = ThisDrawing.ModelSpace.AddLightWeightPolyline(Points)

j = 0

'iterate through setting the bulge factor
For i = 0 To ((UBound(oPolyline.Coordinates) + 1) / 3) - 1
oLWPolyline.SetBulge j, oPolyline.GetBulge(i)
j = j + 1
Next i

'delete the old polyline
oPolyline.Delete
Next oPolyline
End If
End Sub

'change the polyline to have a bulge
Public Sub SetBulgeOfPolyline()
Dim oEntity As AcadPolyline
Dim Point As Variant
'there is no error checking in this routine, it's for test purposes
ThisDrawing.Utility.GetEntity oEntity, Point
'change the bulge factor
oEntity.SetBulge 2, 0.5
End Sub
0 Likes