Copy paste with new block definition

Copy paste with new block definition

Anonymous
Not applicable
4,960 Views
22 Replies
Message 1 of 23

Copy paste with new block definition

Anonymous
Not applicable
I'm trying to develop one tool with that objective:
  • Let the user select Blocks into the current drawing
  • For each block selected, create a new Block definition and copy all objects inside. " new block definition and objects inside may not be referenced with our selected block". 
  • Paste all objects created where user wants 

 

Problems :

 

I was trying copy objects using .clone or .copyfrom but i don't know how to copy objects without references between new and selected block.

 

 My Code :

 

    Dim acdoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acdoc.Database
        Dim acBt As BlockTable
        Dim acBtr As BlockTableRecord
        Dim E As Integer
        Dim newBtrId As ObjectId

        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction
            acBt = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForWrite)
            acBtr = acTrans.GetObject(acBt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)

            'Let the user select Objects from drawing
            Dim acSSPrompt As PromptSelectionResult = acdoc.Editor.GetSelection()
            If acSSPrompt.Status = PromptStatus.OK Then
                Dim acSSet As SelectionSet = acSSPrompt.Value

                'Paste position
                Dim myPoint As PromptPointResult = acdoc.Editor.GetPoint("Paste point: ")

                'Read Selection Set
                For Each acSSObj As SelectedObject In acSSet

                    'Look for ObjectId of my Selected Object
                    For Each acObjId As ObjectId In acBtr
                        If acObjId = acSSObj.ObjectId Then

                            'Take selected object as Blockreference
                            Dim Et As Entity = acTrans.GetObject(acObjId, OpenMode.ForWrite)
                            If TypeOf Et Is BlockReference Then

                                'Current Block Selected
                                Dim Br As BlockReference = Et

                               'Here I should Paste all objects from Br to BlkRef ...

                                'Create a new BlockTableRecord
                                Dim blkRef As BlockTableRecord = New BlockTableRecord()
                                blkRef.Name = "beta" & E + 1

                                'Add BlockTableRecord
                                newBtrId = acBt.Add(blkRef)
                                acTrans.AddNewlyCreatedDBObject(blkRef, True)

                                'Paint BlockReference
                                Dim bob As New BlockReference(myPoint, newBtrId)
                                acBtr.AppendEntity(bob)
                                acTrans.AddNewlyCreatedDBObject(bob, True)
                                E = E + 1

                            End If

                        End If
                    Next
                Next
                acTrans.Commit()
            End If
        End Using

    End Sub

 

 Any idea will be apreciated ! 

 

Thank's a lot!

 

 

 

0 Likes
Accepted solutions (1)
4,961 Views
22 Replies
Replies (22)
Message 21 of 23

jeff
Collaborator
Collaborator

Hey Cheif and Paul,

 

Something I noticed and was having problems with  was using DeepClone.

 

It seems DeepClone was just making a copy and the entities in the new BlockTableRecord and are pointing to same objects as the original,

so updating the entities the new BlockTableRecord or original will change both.

 

It looks like DeepCloneObjects is the correct way for cloning the entities.

 

Little more info in Link

 

http://www.theswamp.org/index.php?topic=39516.0 

You can also find your answers @ TheSwamp
0 Likes
Message 22 of 23

chiefbraincloud
Collaborator
Collaborator

While dealing with ExplodeToOwnerSpace on a newer thread today, I did see in the ObjectARX help files that ExplodeToOwnerSpace does require the block to be uniformly scaled.

Dave O.                                                                  Sig-Logos32.png
0 Likes
Message 23 of 23

E3DE
Enthusiast
Enthusiast

Hi,

this work fine for me.

I would like to redefine first level nested blocks without exploding main block.

I tried to use this code with the first level nested blocks object ids but it did not work.

Is this possible?

Thank you very much

0 Likes