TheSwamp
Code Red => VB(A) => Topic started 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?
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
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.
-
the item you pass has to be an array of objects ...
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
-
I am late again :(
Anyway
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
-
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?
-
basically .. except the argument for the AddRegion method must be an array of entities ...
i.e.
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)
-
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.
-
along those same lines...
How can you find the center of a region?
-
Maybe this (http://discussion.autodesk.com/thread.jspa?messageID=5552431) will help?