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

command reactor - Explode

1 REPLY 1
Reply
Message 1 of 2
Anonymous
292 Views, 1 Reply

command reactor - Explode

When an object is inserted from Design Center I would like it automatically exploded. The code below works for DIMLINEAR but doesn't seem to catch the -INSERT command:

Public Sub cmdEnded(ByVal o As Object, ByVal e As CommandEventArgs)

If bEditCommand = False Then
Return
End If

bEditCommand = False

'Set flag to bypass OpenedForModify handler
bDoRepositioning = True

Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Try
If e.GlobalCommandName = "DIMLINEAR" Then 'this one works fine
Application.DocumentManager.MdiActiveDocument.SendStringToExecute("LAYERP" & vbCr, True, False, True)
End If

If e.GlobalCommandName = "_-INSERT" Then 'doesn't work 😞
Application.DocumentManager.MdiActiveDocument.SendStringToExecute("EXPLODE" & vbCr & "L" & vbCr & vbCr, True, False, True)
End If
Catch ex As System.Exception
ed.WriteMessage("Error in cmdEnded: " + ex.Message)
End Try
End Sub
1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

I have modified the command reactor for the -INSERT command to activate a subroutine. The routine is supposed to explode the last entity added to the drawing but it doesn't work and doesn't throw any errors. What am I doing wrong?

Sub ExplodeLastInsertedObject() 'used after event reactor cmdended for Insert command
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim tm As AcadDb.TransactionManager = db.TransactionManager
Dim trans As Transaction = tm.StartTransaction()

Try
Dim myPSR As EditorInput.PromptSelectionResult = ed.SelectLast 'gets the last added entity
Dim mySS As EditorInput.SelectionSet
Dim myObjIds As ObjectIdCollection
Dim myobjid As ObjectId
Dim bRef As AutoCAD.DatabaseServices.BlockReference

If Not IsNothing(myPSR.Value) Then
mySS = myPSR.Value
myObjIds = New ObjectIdCollection(mySS.GetObjectIds)
For Each myobjid In myObjIds
bRef = myobjid.GetObject(OpenMode.ForRead)
bRef.ExplodeToOwnerSpace()
Next
End If

Catch ex As System.Exception
'I've not used a msgbox as apparently this messes up CmdEnded and CmdStarted routines
ed.WriteMessage(ex.Message, MsgBoxStyle.Information, "Error in LayerCreate")
Finally
trans.Dispose()
End Try
End Sub

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