Converting Circles on a layer into REGIONS???

Converting Circles on a layer into REGIONS???

Anonymous
Not applicable
538 Views
9 Replies
Message 1 of 10

Converting Circles on a layer into REGIONS???

Anonymous
Not applicable
I have plenty of circles on a layer. I want to convert them into REGIONS. I am using following code. [[[[[[[[Public Sub CreateRegion(ByVal sLayName As String) On Error Resume Next Dim currLayer As AcadLayer Set currLayer = ThisDrawing.Layers.Item("Optimal region") ThisDrawing.ActiveLayer = currLayer Set CrtRegion = ThisDrawing.SelectionSets.Item(sLayName) If Err Then Err.Clear Set CrtRegion = ThisDrawing.SelectionSets.Add(sLayName) 'Else 'gsset.Clear 'gsset.Delete End If 'define type of selection set (crossing, window, etc, in this case, all) Dim mode As Integer mode = acSelectionSetAll 'this is a selection set filter Dim gpCode(0) As Integer Dim dataValue(0) As Variant gpCode(0) = 8 dataValue(0) = sLayName 'this is selection set filter data Dim groupCode As Variant, dataCode As Variant groupCode = gpCode dataCode = dataValue 'this collects all objects on 'sLayName' layer into the seletion set CrtRegion.Select mode, , , groupCode, dataCode Dim Arr As Variant Dim NumOfCircles As Integer NumOfCircles = CrtRegion.Count ReDim Arr(0 To CrtRegion.Count - 1, 1) Dim index As Integer Dim Obj As AcadCircle Dim regionObj As Variant For index = 0 To NumOfCircles - 1 Set Obj = CrtRegion.Item(index) regionObj = ThisDrawing.ModelSpace.AddRegion(Obj) Next index CrtRegion.Clear CrtRegion.Delete End Sub]]]]]]]]]]]]]]] Thanks Mniaz
0 Likes
539 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
I have plenty of circles on a layer. I want to convert them into REGIONS. I am using following code.

[[[[[[[[Public Sub CreateRegion(ByVal sLayName As String)

On Error Resume Next

    Dim currLayer As AcadLayer

    Set currLayer = ThisDrawing.Layers.Item("Optimal region")

    ThisDrawing.ActiveLayer = currLayer

    Set CrtRegion = ThisDrawing.SelectionSets.Item(sLayName)

    If Err Then

        Err.Clear

        Set CrtRegion = ThisDrawing.SelectionSets.Add(sLayName)

        'Else

        'gsset.Clear

        'gsset.Delete

    End If

'define type of selection set (crossing, window, etc, in this case, all)

    Dim mode As Integer

    mode = acSelectionSetAll

'this is a selection set filter

    Dim gpCode(0) As Integer

    Dim dataValue(0) As Variant

    gpCode(0) = 8

    dataValue(0) = sLayName

'this is selection set filter data

    Dim groupCode As Variant, dataCode As Variant

    groupCode = gpCode

    dataCode = dataValue

    'this collects all objects on 'sLayName' layer into the seletion set

    CrtRegion.Select mode, , , groupCode, dataCode

    Dim Arr As Variant

    Dim NumOfCircles As Integer

    NumOfCircles = CrtRegion.Count

    ReDim Arr(0 To CrtRegion.Count - 1, 1)

    Dim index As Integer

    Dim Obj As AcadCircle

    Dim regionObj As Variant

    For index = 0 To NumOfCircles - 1

    Set Obj = CrtRegion.Item(index)

    regionObj = ThisDrawing.ModelSpace.AddRegion(Obj)

    Next index

CrtRegion.Clear

CrtRegion.Delete

End Sub]]]]]]]]]]]]]]]

Thanks

Mniaz

0 Likes
Message 3 of 10

Anonymous
Not applicable
my example to you was just on how to select items on a certain layer.
that selects all items, not just circles. If you only wanted circles on
that layer you need to make your filter more specific
Dim gpCode(1) As Integer
Dim dataValue(1) As Variant
gpCode(0) = 8
dataValue(0) = sLayName
gpCode(1) = 0
dataValue(1) = "CIRCLE"

also re-read the help file on AddRegion,
it expects an array of objects, not an object as it's input parameter

"mniaz" wrote in message
news:f19b1a9.-1@WebX.maYIadrTaRb...

dim arObj(0) as AcadCircle
if you want a separate region for every circle
For index = 0 To NumOfCircles - 1
Set arObj(0) = CrtRegion.Item(index)
regionObj = ThisDrawing.ModelSpace.AddRegion(arObj)
Next index
0 Likes
Message 4 of 10

Anonymous
Not applicable
Actually on one layer i have only circles, so i used the above code. I am done with converting circles into regions, your tip helped me a lot.
No my only problem is "INTERSECT Regions". Kindly see new post.
Thanks
Mniaz
0 Likes
Message 5 of 10

Anonymous
Not applicable
Mniaz,
I figured that was the case.
I only mentioned the more general method because it may not always be the
case
and if you're writing functions you may want to use in the future, it's good
to consider various conditions and try to write in such a way that code can
be reused with only supplying varying inputs, not having to rewrite the code
itself to match each specific need.
If i were you, I'd be separating the code parts into reusable functions,
even though it's not necessary this time, it may come in handy in the future
eg:
sub SelectObjects(objectType, objectLayer) ... etc
then this time you'd call
SelectObjects acadCircle, strLayer
next time you might need
SelectObjects acadLine, strOtherLayer

does that make sense?

"mniaz" wrote in message
news:f19b1a9.2@WebX.maYIadrTaRb...
> Actually on one layer i have only circles, so i used the above code. I am
done with converting circles into regions, your tip helped me a lot.
> No my only problem is "INTERSECT Regions". Kindly see new post.
> Thanks
> Mniaz
0 Likes
Message 6 of 10

Anonymous
Not applicable
"mniaz" wrote in message
news:f19b1a9.2@WebX.maYIadrTaRb...

> No my only problem is "INTERSECT Regions". Kindly see new post.

did you read the last part of my previous answer? re object arrays?
0 Likes
Message 7 of 10

Anonymous
Not applicable
I got your point which weighs more than what i was thinking. I am trying to make it general.
Thanks for your guidance.
Mniaz
0 Likes
Message 8 of 10

Anonymous
Not applicable
Hi Mark,
I checked the last part of your previous response. I am too dumb to understand. Can that be used to INTERSECT existing Regions, but how...Sorry for bothering..
Mniaz
0 Likes
Message 9 of 10

Anonymous
Not applicable
sorry I can't help more. I have no idea what you're trying to do.
I only showed what looked like a problem in your code to add regions.
my post showed how to add a region for each circle.
If you have certain circles you want the "intersection region" for, put
those circles in the array and pass that to AddRegion.
Is that what you are trying to do?
maybe if you post an overview description of what your'e doing it would be
easier for someone to come up with a solution?

"mniaz" wrote in message
news:f19b1a9.6@WebX.maYIadrTaRb...
> Hi Mark,
> I checked the last part of your previous response. I am too dumb to
understand. Can that be used to INTERSECT existing Regions,

I don't understand. Your previous post asked how to create regions from
circles. It didn't mention existing regions. I've never used regions so
don't know anything about them. Maybe someone else can understand better.


but how...Sorry for bothering..
> Mniaz
0 Likes
Message 10 of 10

Anonymous
Not applicable
Hi Mark,
First of all thanks for bearing my questions. I am done with "Coverting circles into Regions." [[[[[[I am attaching a picture. Kindly look at it. This picture says, if user has some overlaping regions, he can get an intersection of those regions. I am trying to do the same but in VBA.
I think this explains the problem.]]]]]]]
Thanks,
Mniaz
0 Likes