Jump to content

Iterate through Regions in model space


Recommended Posts

Posted

Hello All,

Using the following code it iterates through all objects in model space not just region objects (as desired). Can someone take a look and tell me what I'm missing?

 

 
For Each Region In ThisDrawing.ModelSpace
     Region.Highlight True
     'Check to see if Region has xdata if not continue
         Region.getxdata "AppName", xdataType, xdataValue
          If VarType(xdataValue) = vbEmpty Then
            GoTo nextreg:
             Else
              If xdataValue(1) = xdataStr Then
                Region.Boolean acSubtraction, FrameRegion(0) '*************subtract frame footprint from Usable
                 Region.Highlight False
                 Exit For
              End If
          End If
nextreg:
        Region.Highlight False
  Next Region

 

thanks guys, happy friday!

Posted

The word Region is just a variable name and not the object type. You would either need to create a selection set of only Region objects or as you iterate through each Object (what you have named Region), check its object name

ie

 

If Region.objectname = "AcDbRegion" then
   "DO you operation here"
End If

  • 2 months later...
Posted

This is what I ended up with:

 

 
Public Function Regions_Collection() As Collection
Dim ent As AcadEntity
Dim RegionX As AcadRegion
Dim RegionsCollection As New Collection
Set Regions_Collection = RegionsCollection
On Error Resume Next
For Each ent In ThisDrawing.ModelSpace
    If ent.ObjectName = "AcDbRegion" Then
     Set RegionX = ent
     'add the entity(region) to the regions collection
       RegionsCollection.Add ent
       Else
    End If
Next ent
End Function

 

thanks for all the help with everything else!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...