Author Topic: Viewing a bounding box in VBA  (Read 3357 times)

0 Members and 1 Guest are viewing this topic.

CadRover

  • Guest
Viewing a bounding box in VBA
« on: July 06, 2008, 04:08:26 PM »

Does anyone know if it is possible to actually see the bounding box of an entity in ACAD?
If so, does anyone have any VBA code examples of this?

Thanks

CAD

fixo

  • Guest
Re: Viewing a bounding box in VBA
« Reply #1 on: July 06, 2008, 04:26:03 PM »
Here is what you want

Code: [Select]
Option Explicit

Public Sub BoundingBoxTest()
Dim oEnt As AcadEntity
Dim varPt As Variant
Dim MaxPoint As Variant
Dim MinPoint As Variant
Dim Vertices(0 To 9) As Double
Dim oPline As AcadLWPolyline

ThisDrawing.Utility.GetEntity oEnt, varPt, vbCrLf & "Select object"

oEnt.GetBoundingBox MinPoint, MaxPoint

Vertices(0) = MinPoint(0)
Vertices(1) = MinPoint(1)
Vertices(2) = MaxPoint(0)
Vertices(3) = MinPoint(1)
Vertices(4) = MaxPoint(0)
Vertices(5) = MaxPoint(1)
Vertices(6) = MinPoint(0)
Vertices(7) = MaxPoint(1)
Vertices(8) = MinPoint(0)
Vertices(9) = MinPoint(1)

Set oPline = ThisDrawing.ModelSpace.AddLightWeightPolyline(Vertices)
oPline.color = acYellow

End Sub

~'J'~

CadRover

  • Guest
Re: Viewing a bounding box in VBA
« Reply #2 on: July 06, 2008, 05:23:46 PM »

Fix,

That seems to be working very well, thank you.

Hey, just thought of something; you could add this bit of code to the end
if you'd like to retreive the actual points in the immediate window

Code: [Select]
Dim i As Integer
 For i = 0 To 9
  Debug.Print "Vertice Pnt"; (i); Vertices(i)
 Next i

That should work

CAD

fixo

  • Guest
Re: Viewing a bounding box in VBA
« Reply #3 on: July 07, 2008, 02:19:32 AM »
Nice shot
Glad you solved it by yourself
Happy computing :-)

~'J'~

CadRover

  • Guest
Re: Viewing a bounding box in VBA
« Reply #4 on: July 08, 2008, 02:14:11 AM »

Yes, thanks

Having the points are always good if you want to do something further with the entity, like calc the midpnt, move it etc