I'm trying to make sure my wipeouts are set behind everything in my blocks. I'm going to eventually work this into happening on insert but for now I'd just like to get it to happen at all by selecting the block.
I've figured out how to use the AcDbSortentsTable to move objects behind in modelspace, I cant get it to work in a block. This code is a combination of updateing a block and moving objects behind from the help files look up "sortentstable example" for that example.
I want to try to avoid having to explode the block and put it back together if I can, not sure if that will work anyway.
Just for reference, this first code is the basic editing a block that works(got it from autodesk's ng):
*********************
Public Sub UpdateBlockDefinition()
Dim Entity As AcadEntity
Dim BlockEntity As AcadEntity
Dim BlockDefinition As AcadBlock
Dim BlockReference As AcadBlockReference
Dim SelectionSet As AcadSelectionSet
On Error Resume Next
ThisDrawing.SelectionSets.
Item("Bloc
kToUpdate"
).Delete
On Error GoTo 0
Set SelectionSet = ThisDrawing.SelectionSets.
Add("Block
ToUpdate")
SelectionSet.SelectOnScree
n
For Each Entity In SelectionSet
If TypeOf Entity Is AcadBlockReference Then
Set BlockReference = Entity
For Each BlockDefinition In ThisDrawing.Blocks
If BlockDefinition.Name = BlockReference.Name Then
For Each BlockEntity In BlockDefinition
' Do your modifications here...
BlockEntity.color = acRed
BlockEntity.Layer = "0"
BlockEntity.Update
Next BlockEntity
End If
Next BlockDefinition
End If
Next Entity
End Sub
*****************
This is the code I pieced together with the above and the sortentstable from the help files.
*******************
Public Sub UpdateBlockDefinition()
Dim Entity As AcadEntity
Dim BlockEntity As AcadEntity
Dim BlockDefinition As AcadBlock
Dim BlockReference As AcadBlockReference
Dim SelectionSet As AcadSelectionSet
'Get an extension dictionary and, if necessary, add a SortentsTable object
Dim eDictionary As Object
Set eDictionary = ThisDrawing.ModelSpace.Get
ExtensionD
ictionary
' Prevent failed GetObject calls from throwing an exception
On Error Resume Next
Dim sentityObj As Object
Set sentityObj = eDictionary.GetObject("ACA
D_SORTENTS
")
On Error GoTo 0
If sentityObj Is Nothing Then
' No SortentsTable object, so add one
Set sentityObj = eDictionary.AddObject("ACA
D_SORTENTS
", "AcDbSortentsTable")
End If
On Error Resume Next
ThisDrawing.SelectionSets.
Item("Bloc
kToUpdate"
).Delete
On Error GoTo 0
Set SelectionSet = ThisDrawing.SelectionSets.
Add("Block
ToUpdate")
SelectionSet.SelectOnScree
n
For Each Entity In SelectionSet
If TypeOf Entity Is AcadBlockReference Then
Set BlockReference = Entity
For Each BlockDefinition In ThisDrawing.Blocks
If BlockDefinition.NAME = BlockReference.NAME Then
For Each BlockEntity In BlockDefinition
' Do your modifications here...
'MsgBox BlockEntity.ObjectName
If BlockEntity.ObjectName = "AcDbWipeout" Then
'MsgBox "wipeout"
Dim ObjIds(0) As Long
ObjIds(0) = BlockEntity.ObjectID
'ObjIds(1) = leaderObj.ObjectID
Dim varObject As ACADObject
Set varObject = ThisDrawing.ObjectIdToObje
ct(ObjIds(
0))
Dim arr(0) As ACADObject
Set arr(0) = varObject
'MsgBox arr(0).ObjectName
'Move the object to the bottom
sentityObj.MoveToBottom arr '**** I get an invalid input error here.
AcadApplication.Update
End If
Next BlockEntity
End If
Next BlockDefinition
End If
Next Entity
End Sub
*******************
Any help/suggestions would be appreciated.
dragontooth, you did see that DT(bat) signal in the sky last night didnt ya? ;)
http://upload.wikimedia.org/wikipedia/en/a/ad/Bat-signalBatman_1989.jpgStart Free Trial