Jump to content

Explode a region in VB.NET


IsraelM

Recommended Posts

Hi,

 

do you have an idea how to explode a region and get the acadobject (line, arc ...)

 

In VBA,

Dim explodedObjects As Variant

explodedObjects = regionObj.Explode

But in VB.NET,

Variant is longer exist et replace by Object... Explode returns an array of {System.__ComObject}.

 

Do you know how I can use this to manipulate line, arc ...?

 

Thanks a lot :wink:

Link to comment
Share on other sites

Hi,

 

do you have an idea how to explode a region and get the acadobject (line, arc ...)

 

In VBA,

Dim explodedObjects As Variant

explodedObjects = regionObj.Explode

But in VB.NET,

Variant is longer exist et replace by Object... Explode returns an array of {System.__ComObject}.

 

Do you know how I can use this to manipulate line, arc ...?

 

Thanks a lot :wink:

Try tested on A2008

       <CommandMethod("exploderegion", CommandFlags.UsePickSet And CommandFlags.Redraw)> _
       Sub RegionExplode()
           Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
           Dim ed As Editor = doc.Editor
           Dim db As Database = HostApplicationServices.WorkingDatabase
           Dim tr As Transaction = db.TransactionManager.StartTransaction()
           Using (tr)
               Try
                   Dim peo As New PromptEntityOptions(Environment.NewLine & "Select Region: ")
                   peo.SetRejectMessage(Environment.NewLine & "Select Region only: ")
                   peo.AddAllowedClass(GetType(Region), True)
                   Dim pres As PromptEntityResult = ed.GetEntity(peo)
                   If pres.Status <> PromptStatus.OK Then
                       ed.WriteMessage(vbCr & "PROBLEM")
                       Return
                   End If
                   Dim region As Region = CType(tr.GetObject(pres.ObjectId, OpenMode.ForWrite), Region)
                   Dim expObjects As DBObjectCollection = New DBObjectCollection
                   region.Explode(expObjects)
                   ed.WriteMessage(Environment.NewLine & "Exploded: " & expObjects.Count.ToString() & " objects")
                   Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
                   'exploded objects already open for write
                   For Each obj As DBObject In expObjects
                       If TypeOf obj Is Line Then
                           Dim line As Line = obj
                           If Not line Is Nothing Then
                               line.ColorIndex = 1
                               btr.AppendEntity(line)
                               tr.AddNewlyCreatedDBObject(line, True)
                           End If
                       ElseIf TypeOf obj Is Arc Then
                           Dim arc As Arc = obj
                           If Not arc Is Nothing Then
                               arc.ColorIndex = 2
                               btr.AppendEntity(arc)
                               tr.AddNewlyCreatedDBObject(arc, True)
                           End If
                       End If
                   Next
                   region.Erase()
                   region.Dispose()
                   tr.Commit()
               Catch ex As Autodesk.AutoCAD.Runtime.Exception
                   ed.WriteMessage(Environment.NewLine & ex.Message & Environment.NewLine & ex.StackTrace)
               End Try
           End Using
       End Sub

 

~'J'~

Link to comment
Share on other sites

Thank you Fixo !! 8)

I enjoy your help!

 

I tried your sub but I have an error:

FileNotFoundException -> System.Collection.ListDictionaryInternal

 

Do you know what is my problem?

 

Thanks!

 

Iz

Link to comment
Share on other sites

Thank you Fixo !! 8)

I enjoy your help!

 

I tried your sub but I have an error:

FileNotFoundException -> System.Collection.ListDictionaryInternal

 

Do you know what is my problem?

 

Thanks!

 

Iz

 

Sorry I have no idea about

Seems to me the problem on other part

of your code

If you had used a code block where you

have trying to open file then add something like this:

 

 
Imports System.IO
..........................
If ( Not File.Exist(=your filename here=)) Then
editor.WriteMessage("File not found. Exiting program");
Return
End If

 

~'J'~

Link to comment
Share on other sites

I think I miss an imports or a reference in my project because I have this error at the moment I declare a DBObjectCollection.

 

DbObjectCollection does have any import or need for this object ?

 

thanks a lot !

 

Iz

Link to comment
Share on other sites

I think I miss an imports or a reference in my project because I have this error at the moment I declare a DBObjectCollection.

 

DbObjectCollection does have any import or need for this object ?

 

thanks a lot !

 

Iz

Here are all of libraries I have used in my project

(probably any of those would be extrafluous for you):

Imports System

Imports System.Collections.Generic

Imports System.Text

Imports Autodesk.AutoCAD.ApplicationServices

Imports Autodesk.AutoCAD.Runtime

Imports Autodesk.AutoCAD.Geometry

Imports Autodesk.AutoCAD.DatabaseServices

Imports Autodesk.AutoCAD.EditorInput

Imports acadApp = Autodesk.AutoCAD.ApplicationServices.Application

 

 

~'J'~

Link to comment
Share on other sites

I found my problem, this DBObjectCollection does not run in debug mode... When I install my DLL in autocad, it work perfectly.

 

Is it normal I can't run in debug mode of VB2008?

 

Thanks for your support !! :D

 

Iz!

Link to comment
Share on other sites

I found my problem, this DBObjectCollection does not run in debug mode... When I install my DLL in autocad, it work perfectly.

 

Is it normal I can't run in debug mode of VB2008?

 

Thanks for your support !! :D

 

Iz!

 

Sorry, I don't know that

I have VS2005/A2008 on my machine only

Happy computing :)

 

~'J'~

Link to comment
Share on other sites

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...