IsraelM Posted March 4, 2010 Posted March 4, 2010 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: Quote
fixo Posted March 4, 2010 Posted March 4, 2010 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'~ Quote
IsraelM Posted March 5, 2010 Author Posted March 5, 2010 Thank you Fixo !! 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 Quote
fixo Posted March 6, 2010 Posted March 6, 2010 Thank you Fixo !! 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'~ Quote
IsraelM Posted March 8, 2010 Author Posted March 8, 2010 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 Quote
fixo Posted March 8, 2010 Posted March 8, 2010 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'~ Quote
IsraelM Posted March 8, 2010 Author Posted March 8, 2010 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 !! Iz! Quote
fixo Posted March 8, 2010 Posted March 8, 2010 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 !! Iz! Sorry, I don't know that I have VS2005/A2008 on my machine only Happy computing ~'J'~ Quote
Recommended Posts
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.