VBA not returning object that was just created?

VBA not returning object that was just created?

Anonymous
Not applicable
343 Views
5 Replies
Message 1 of 6

VBA not returning object that was just created?

Anonymous
Not applicable
SendCommand "-boundary" ...
Set myObject = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count-1)

is not returning the polyline that was just created.
0 Likes
344 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Hi,

You are almost certainly going to have problems establishing the string to
make the Boundary command to work inside VBA.

Once you have that, then the rest of your VBA code will probably continue to
run before the results of the boundary command are available.

The following code will return some information about the last item in the
database.

Sub fred()
Dim i As Long
Dim x As Object
i = ThisDrawing.ModelSpace.Count
Set x = ThisDrawing.ModelSpace.Item(i - 1)
If TypeOf x Is AcadPolyline Or TypeOf x Is AcadLWPolyline Then
With x
MsgBox "Handle is " & .Handle & vbCrLf & "Area is " & Format(.Area,
"#.0"), vbInformation
End With
Else
MsgBox "Object is not a polyline'"
End If

End Sub

wrote in message news:4862748@discussion.autodesk.com...
SendCommand "-boundary" ...
Set myObject = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count-1)

is not returning the polyline that was just created.
0 Likes
Message 3 of 6

Anonymous
Not applicable
I have the boundary command working. If I step through my application via debug, everything works perfectly. If I just run the program VBA is not returning the new polyline as the last object. It appears that the line of code to grab the last object is excuting before the database recognizes the addition of the new object.
0 Likes
Message 4 of 6

Anonymous
Not applicable
Could you show us the whole SendCommand line?

If you are trying to create boundary by user interaction (picking a point), it won't work.
VBA doesn't wait after SendCommand, so the last entity is not the boundary.
0 Likes
Message 5 of 6

Anonymous
Not applicable
ThisDrawing.SendCommand "-boundary" & vbCr & pntBoundary(0) & "," & pntBoundary(1) & vbCr & vbCr

Set oPoly = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1)
0 Likes
Message 6 of 6

Anonymous
Not applicable
Your code should work. Haven't tried it though.

Try to do it like this:
ThisDrawing.SendCommand "(command ""-boundary"" """ & pntBoundary(0) & "," & pntBoundary(1) & """)"

Hope I got all " right 🙂
0 Likes