AddNewlyCreatedDBObject to Model Space from Paper Space

AddNewlyCreatedDBObject to Model Space from Paper Space

tristan.jonas8XAAW
Advocate Advocate
500 Views
3 Replies
Message 1 of 4

AddNewlyCreatedDBObject to Model Space from Paper Space

tristan.jonas8XAAW
Advocate
Advocate

Hello, I'm having trouble getting a script to paste the collected lines from the "SS_GRID" layer, but I'm having a devil of a time getting the script to paste the the lines in the Model Space but it's pasting it in the Paper Space. I know I HAVE to be missing something obvious but for some reason after all the looking I'm still having a lot of trouble getting this to work, perhaps because I don't know a better way to word the situation other than 
the description in the title of this post.

    Public Sub ExplodeEntities()
        Dim doc As Document = DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Dim pso As PromptSelectionOptions = New PromptSelectionOptions()
        pso.AllowDuplicates = False
        pso.AllowSubSelections = True
        pso.RejectObjectsFromNonCurrentSpace = True
        pso.RejectObjectsOnLockedLayers = False
        Dim gridEnts As ObjectIdCollection = GetEntitiesOnLayer("SS_GRID")
        Dim psr As PromptSelectionResult = ed.SelectAll()
        Dim tr As Transaction = db.TransactionManager.StartTransaction()
        Using tr
            Dim objs3 As Autodesk.AutoCAD.DatabaseServices.DBObjectCollection = New Autodesk.AutoCAD.DatabaseServices.DBObjectCollection()
            For Each so As SelectedObject In psr.Value
                Dim ent As Entity = CType(tr.GetObject(so.ObjectId, OpenMode.ForRead), Entity)
                If ent.Layer = "SS_GRID" Then
                    ent.Explode(objs3)
                    ent.UpgradeOpen()
                    ent.[Erase]()
                End If
            Next
            Dim btr As BlockTableRecord = TryCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
            For Each obj As DBObject In objs3
                Dim ent As Entity = CType(obj, Entity)
                If ent.Layer = "SS_GRID" Then
                    btr.AppendEntity(ent)
                    tr.AddNewlyCreatedDBObject(ent, True)
                End If
            Next
            tr.Commit()
        End Using
    End Sub



0 Likes
Accepted solutions (1)
501 Views
3 Replies
Replies (3)
Message 2 of 4

hosneyalaa
Advisor
Advisor

 

Hi

Try

 

objs3[0].UpgradeOpen()
objs3[0].Erase()
0 Likes
Message 3 of 4

tristan.jonas8XAAW
Advocate
Advocate

Hello, thank you for your response 🙂

I'm getting two error messages for each of these, "Identifier Expected" and "Expression is not a Method".

0 Likes
Message 4 of 4

hippe013
Advisor
Advisor
Accepted solution

The block table that you are opening and adding to is the "CurrentSpaceId". So, if you launch your command in PaperSpace, then that is the space that you will be working in. For model space use something like this. 

 

Dim blkTbl As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
Dim blkTblRec As BlockTableRecord = tr.GetObject(blkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

 

0 Likes