Author Topic: create region  (Read 2377 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
create region
« 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.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: create region
« Reply #1 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
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Fatty

  • Guest
Re: create region
« Reply #2 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

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: create region
« Reply #3 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?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: create region
« Reply #4 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)
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Atook

  • Swamp Rat
  • Posts: 1027
  • AKA Tim
Re: create region
« Reply #5 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.
« Last Edit: May 04, 2007, 05:43:49 PM by Atook »

Matersammichman

  • Guest
Re: create region
« Reply #6 on: May 08, 2007, 08:19:16 AM »
along those same lines...
How can you find the center of a region?

Guest

  • Guest
Re: create region
« Reply #7 on: May 08, 2007, 09:27:13 AM »
Maybe this will help?