.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy paste with new block definition

22 REPLIES 22
SOLVED
Reply
Message 1 of 23
PaulPotts
2069 Views, 22 Replies

Copy paste with new block definition

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!

 

 

 

22 REPLIES 22
Message 21 of 23
jeff
in reply to: chiefbraincloud

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
Message 22 of 23
chiefbraincloud
in reply to: jeff

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
Message 23 of 23
E3DE
in reply to: jeff

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost