TheSwamp

Code Red => VB(A) => Topic started by: David Hall on May 04, 2007, 04:33:38 PM

Title: create region
Post by: David Hall on May 04, 2007, 04:33:38 PM
Riddle me this, if the help file says a region is created from a LWPolyline, why wont this work?
Code: [Select]
Public Sub wall()
      Dim dblLength As Double, dblWidth As Double, dblHeight As Double
      Dim inspt(2) As Double, endpt(2) As Double
      inspt(0) = 120: inspt(1) = 120: inspt(2) = 0
      Dim oLayer As AcadLayer, oCurrLayeR As AcadLayer, oBlock As AcadBlockReference, _
          oEntity As AcadEntity, newObjs As Variant      ', InsPT As Variant
      Set oCurrLayeR = ThisDrawing.ActiveLayer
      Set oLayer = ThisDrawing.Layers.Add("SITE-WALL")
      oLayer.color = 1
      ThisDrawing.ActiveLayer = oLayer
'      dblLength = CDbl(txtLength.Value)
'      dblWidth = CDbl(txtWidth.Value)
'      dblHeight = CDbl(txtHeight.Value)
      dblLength = 144
      dblWidth = 72
      dblHeight = 60

Dim WallCoords(9) As Double
WallCoords(0) = inspt(0) - (dblLength / 2): WallCoords(1) = inspt(1) + (dblWidth / 2)
WallCoords(2) = inspt(0) + (dblLength / 2): WallCoords(3) = inspt(1) + (dblWidth / 2)
WallCoords(4) = inspt(0) + (dblLength / 2): WallCoords(5) = inspt(1) - (dblWidth / 2)
WallCoords(6) = inspt(0) - (dblLength / 2): WallCoords(7) = inspt(1) - (dblWidth / 2)
WallCoords(8) = inspt(0) - (dblLength / 2): WallCoords(9) = inspt(1) + (dblWidth / 2)

Dim plineObj As AcadLWPolyline
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(WallCoords)
plineObj.Closed = True

Dim regionObj As Variant
  Set regionObj = ThisDrawing.ModelSpace.AddRegion(plineObj)
    ZoomAll


      ThisDrawing.ActiveLayer = oCurrLayeR
End Sub
Quote
RetVal = object.AddRegion(ObjectList)
Object-ModelSpace Collection, PaperSpace Collection, Block
The object or objects this method applies to.

ObjectList-Array of Objects
The array of objects forming the closed coplanar face to be made into a region. This array may contain the following object types: Line, Arc, Circle, Elliptical Arc, LightweightPolyline, Spline.

RetVal-Variant
This method outputs an array of the newly created Region objects.
Title: Re: create region
Post by: Keith™ on May 04, 2007, 04:54:08 PM
the item you pass has to be an array of objects ...

Code: [Select]
Public Sub wall()
      Dim dblLength As Double, dblWidth As Double, dblHeight As Double
      Dim inspt(2) As Double, endpt(2) As Double
      inspt(0) = 120: inspt(1) = 120: inspt(2) = 0
      Dim oLayer As AcadLayer, oCurrLayeR As AcadLayer, oBlock As AcadBlockReference, _
          oEntity As AcadEntity, newObjs As Variant      ', InsPT As Variant
      Set oCurrLayeR = ThisDrawing.ActiveLayer
      Set oLayer = ThisDrawing.layers.Add("SITE-WALL")
      oLayer.Color = 1
      ThisDrawing.ActiveLayer = oLayer
'      dblLength = CDbl(txtLength.Value)
'      dblWidth = CDbl(txtWidth.Value)
'      dblHeight = CDbl(txtHeight.Value)
      dblLength = 144
      dblWidth = 72
      dblHeight = 60

Dim WallCoords(9) As Double
WallCoords(0) = inspt(0) - (dblLength / 2): WallCoords(1) = inspt(1) + (dblWidth / 2)
WallCoords(2) = inspt(0) + (dblLength / 2): WallCoords(3) = inspt(1) + (dblWidth / 2)
WallCoords(4) = inspt(0) + (dblLength / 2): WallCoords(5) = inspt(1) - (dblWidth / 2)
WallCoords(6) = inspt(0) - (dblLength / 2): WallCoords(7) = inspt(1) - (dblWidth / 2)
WallCoords(8) = inspt(0) - (dblLength / 2): WallCoords(9) = inspt(1) + (dblWidth / 2)

Dim objArray(0) As AcadEntity

Set objArray(0) = ThisDrawing.ModelSpace.AddLightWeightPolyline(WallCoords)
    objArray(0).Closed = True

  ThisDrawing.ModelSpace.AddRegion objArray
  ZoomAll

  ThisDrawing.ActiveLayer = oCurrLayeR
End Sub
Title: Re: create region
Post by: Fatty on May 04, 2007, 04:55:27 PM
I am late again :(
Anyway

Code: [Select]
Public Sub wall()
      Dim dblLength As Double, dblWidth As Double, dblHeight As Double
      Dim inspt(2) As Double, endpt(2) As Double
      inspt(0) = 120: inspt(1) = 120: inspt(2) = 0
      Dim oLayer As AcadLayer, oCurrLayeR As AcadLayer, oBlock As AcadBlockReference, _
          oEntity As AcadEntity, newObjs As Variant      ', InsPT As Variant
      Set oCurrLayeR = ThisDrawing.ActiveLayer
      Set oLayer = ThisDrawing.Layers.Add("SITE-WALL")
      oLayer.color = 1
      ThisDrawing.ActiveLayer = oLayer
'      dblLength = CDbl(txtLength.Value)
'      dblWidth = CDbl(txtWidth.Value)
'      dblHeight = CDbl(txtHeight.Value)
      dblLength = 144
      dblWidth = 72
      dblHeight = 60

Dim WallCoords(9) As Double
WallCoords(0) = inspt(0) - (dblLength / 2): WallCoords(1) = inspt(1) + (dblWidth / 2)
WallCoords(2) = inspt(0) + (dblLength / 2): WallCoords(3) = inspt(1) + (dblWidth / 2)
WallCoords(4) = inspt(0) + (dblLength / 2): WallCoords(5) = inspt(1) - (dblWidth / 2)
WallCoords(6) = inspt(0) - (dblLength / 2): WallCoords(7) = inspt(1) - (dblWidth / 2)
WallCoords(8) = inspt(0) - (dblLength / 2): WallCoords(9) = inspt(1) + (dblWidth / 2)

Dim plineObj As AcadLWPolyline
Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(WallCoords)
plineObj.Closed = True
Dim bound(0) As AcadEntity
Set bound(0) = plineObj
Dim regionObj As Variant
  regionObj = ThisDrawing.ModelSpace.AddRegion(bound)
plineObj.Delete
    ZoomAll

      ThisDrawing.ActiveLayer = oCurrLayeR
End Sub
Title: Re: create region
Post by: David Hall on May 04, 2007, 05:25:34 PM
So let me see if I understand, we are using a generic AcadEntity, creating a LWP as said entity, and passing that to the region command?
Title: Re: create region
Post by: Keith™ on May 04, 2007, 05:38:58 PM
basically .. except the argument for the AddRegion method must be an array of entities ...

i.e.
Code: [Select]
Dim NumberOfEntities, X As Integer
NumberOfEntities = 10
Dim EntityArray(0 to NumberOfEntities) As AcadEntity

For X = 0 to NumberOfEntities
 Set EntityArray(X) = MakePline() <--- dummy function returning a LWpolyline
Next X

ThisDrawing.ModelSpace.AddRegion(EntityArray)
Title: Re: create region
Post by: Atook on May 04, 2007, 05:41:22 PM
No, you create your LWP, and put that into an array. Pass the array to the .addregion command. It's kinda silly if you're only passing one object, but would make sense if you were using 3 objects to define the region.

Summing it up:

LWP=addlwpoly(blah)
dim arrRegionBound(0) as variant
arrRegionBound(0)=LWP
regionObj = ThisDrawing.ModelSpace.AddRegion(arrRegionBound)

Edit: Just what quickfingersKeith said.
Title: Re: create region
Post by: Matersammichman on May 08, 2007, 08:19:16 AM
along those same lines...
How can you find the center of a region?
Title: Re: create region
Post by: Guest on May 08, 2007, 09:27:13 AM
Maybe this (http://discussion.autodesk.com/thread.jspa?messageID=5552431) will help?