Message 1 of 23
Not applicable
09-08-2011
06:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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!
Solved! Go to Solution.