.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Alternativ e Attribute command
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi, I want write a command for attribute editing. The command check if the block name is equal to a string and if yes make some operation, if no continue with DDEDIT standard command.
The program work well if the block name is not the some of the string. When the name is the some the program make the correct operation but then run also the ddedit command.
there is a way for break the command?
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Colors
Imports System
Imports System.Windows.Forms
Imports System.Math
'Imports System.Web.Mail
Imports Microsoft.Office.Core
Imports Microsoft.Office.Interop
'Imports Microsoft.Office.Interop.Outlook
Imports System.Runtime.InteropServices
Imports Autodesk.AutoCAD.Interop
Public ClassreactorDim bEditCommand AsBooleanDim bDoRepositioning AsBoolean
<CommandMethod("AddEvents")> _
PublicSubplantDbEvents()
Dim doc AsDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db AsDatabase = HostApplicationServices.WorkingDatabase()
'AddHandler db.ObjectOpenedForModify, New ObjectEventHandler(AddressOf objOpenedForMod)AddHandler doc.CommandWillStart, NewCommandEventHandler(AddressOfcmdWillStart)
'AddHandler doc.CommandEnded, New CommandEventHandler(AddressOf cmdEnded)
bEditCommand =
False
bDoRepositioning =
FalseEndSubPublicSub cmdWillStart(ByVal o AsObject, ByVal e AsCommandEventArgs)
Dim ed AsEditor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
TryIf e.GlobalCommandName = "DDEDIT"Or e.GlobalCommandName = "EATTEDIT"Then
Dim fr2 AsNewFerriDim strNomeBlocco AsStringDim myDwg AsDocument'Dim myBT As BlockTable'Dim myBTR As BlockTableRecordDim myDB As DatabaseServices.DatabaseDim myTransMan As DatabaseServices.TransactionManagerDim myTrans As DatabaseServices.TransactionDim myEd As EditorInput.EditorDim myPSR As EditorInput.PromptSelectionResult
Dim TargetBlockRef As DatabaseServices.BlockReference
myDB = ApplicationServices.
Application.DocumentManager.MdiActiveDocument.Database
myDwg = Autodesk.AutoCAD.ApplicationServices.
Application.DocumentManager.MdiActiveDocument
strNomeBlocco =
"FERRI-P"
myTransMan = myDB.TransactionManager
myTrans = myTransMan.StartTransaction
myEd = myDwg.Editor
a2: myPSR = myEd.SelectImplied
SelectCasemyPSR.Status
Case EditorInput.PromptStatus.OK
SelectCasemyPSR.Value.Count
Case1
Dim mySelobj As EditorInput.SelectedObjectDim myAcadEnt As DatabaseServices.Entity
For I = 1 TomyPSR.Value.Count
mySelobj = myPSR.Value.Item(I - 1)
myAcadEnt = mySelobj.ObjectId.GetObject(DatabaseServices.
OpenMode.ForRead)
TargetBlockRef = myAcadEnt
If Microsoft.VisualBasic.Left$(UCase(TargetBlockRef.N
fr2.Show()
GoToA15
EndIf
NextI
CaseIs> 1
MsgBox(
"Seleziona un solo blocco delle Posizioni")
myPSR =
NothingGoToa2
Case ElseEndSelectCase EditorInput.PromptStatus.Error
' GoTo a3
' Case EditorInput.PromptStatus.Cancel
EndSelectEndIfCatch ex As System.Exception
ed.WriteMessage(
"Error in cmdWillStart: "+ ex.Message)
EndTry
A15:
EndSub
End
Class
Re: Alternativ e Attribute command
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Handling CommandWillStart event will not meet your need, as you have already found out, because no matter what you do in the event handler, it is just something you can do before the command starts, after your code runs, the command will still run.
To your need, you can handle DocumentCollection.DocumentLockModeChanged event and DocumentCollection.DocumentLockModeChangeVetoed event. That is, in the DocumentLockModeChanged event handler, if a certain condition is met, you can then veto the command, which will result in the DocumentLockModeChangeVetoed event being fired. Then in DocumentLockModeChangeVetoed event handler, you can start your own process/custom command.
Some psuedo code:
private static bool runAlternativeCmd=false;
public void Initialize()
{
DocumentCollection docs=Application.DocumentManager;
docs.DocumentLockModeChanged+=new DocumentLockModeChangedEventHandler(DocLockChanged
docs.DocumentLockModeChangeVetoed+=new DocumentLockModeChangeVetoedEventHandler(DocLockCh
}
void DocLockChanged(object sender, DocumentLockModeChangedEventArgs e)
{
if (e.GlobalCommandName.ToUpper()=="XXXXXXX")
{
//Test if the entity in the implied selectionset is the targeting block. If it is, veto the command
runAlternativeCmd=true;
}
else
{
runAlternativeCmd=false;
}
}
void DocLockChaneVetoed(object sender, DocumentLockChangeVetoedEventArgs e)
{
If (runAlternativeCmd)
{
Document doc=Application.DocumentManager/MdiDocument;
doc.SendStringToExcute("MyAttrEdit ",true, false, false);
}
}
[CoommandMethod["MyAttrEdit")]
public static void EditMyAttribute()
{
Do my own editing process
}
HTH
Re: Alternativ e Attribute command
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Here are two ADN DevBlog entries:
Get the real name of a block if it is anonymous (necessary for dynamic blocks):
http://adndevblog.typepad.com/autocad/2012/05/iden
Veto a command as described above:
http://adndevblog.typepad.com/autocad/2012/05/veto
Re: Alternativ e Attribute command
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: Alternativ e Attribute command
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thamks
I must use the DLL with AutoCAD 2013 but there is an error
I have convert C code in Vb.net code, this is the result:
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Colors
Imports System
Imports System.Windows.Forms
Imports System.Math
'Imports System.Web.Mail
Imports System.Runtime.InteropServices
Imports Autodesk.AutoCAD.Interop
Imports System.Collections.Specialized
Public ClassClass2
<CommandMethod("AddVetoToQuit")> _
PublicSharedSubAddVetoToQuit()
Dim doc AsDocumentCollection = ApplicationServices.Application.DocumentManager
doc.DocumentLockModeChanged +=NewDocumentLockModeChangedEventHandlerdoc_DocumentLockModeChanged)
EndSub
<CommandMethod("RemoveVetoToQuit")> _
PublicSharedSubRemoveVetoToQuit()
Dim doc AsDocumentCollection = ApplicationServices.Application.DocumentManager
doc.DocumentLockModeChanged -=NewDocumentLockModeChangedEventHandler(doc_DocumentLockModeChanged)
EndSub
PrivateSharedSub doc_DocumentLockModeChanged(sender AsObject, e AsDocumentLockModeChangedEventArgs)
IfString.Compare(e.GlobalCommandName, "QUIT", True) = 0 Then
e.Veto()
EndIf
EndSub
End Class
Re: Alternativ e Attribute command
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I do not think you can use
Object.Event +=EventHandler(...) in VB.NET.
You should look into AddHandler/RemoveHandler statement in VB.NET, like:
AddHandler Object.Event, Address Of EventHandlerName
RemoveHandler Object.Event, Address Of EventHandlerName
Re: Alternativ e Attribute command
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
l
Re: Alternativ e Attribute command
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Like this? But I receive an error on "Autodesk.AutoCAD.ApplicationServices.DocumentCollection.DocumentLockModeChanged"
Public
Classveto
<
CommandMethod("AddDocColEvent")> _
PublicSubAddDocColEvent()
AddHandler Autodesk.AutoCAD.ApplicationServices.DocumentCollection.DocumentLockModeChanged, AddressOfdocColDocAct
EndSub
<
CommandMethod("RemoveDocColEvent")> _
PublicSubRemoveDocColEvent()
RemoveHandler ApplicationServices.Application.DocumentManager.DocumentActivated, _
AddressOfdocColDocAct
EndSubPublicSub docColDocAct(ByVal senderObj AsObject, _
ByVal docColDocActEvtArgs AsDocumentCollectionEventArgs)
ApplicationServices.
Application.ShowAlertDialog(docColDocActEvtArgs.Document.Name & _
" was activated.")
EndSub
End
Class
Re: Alternativ e Attribute command
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Well, carefully looking into the compiling error would reveal something obviously.
1. You added event handler to handle DocumentLockModeChanged event, but you remove a handler on DocumentActivated event, which is never been added in the first place.
2. The event handler docColDocAct() cannot be used to handle DocumentLockModeChanged event, because the handler's signature is wrong. Event handler for DocumentLockModeChanged requires the second argumnet of the handler to be type of DocumentLockModeChangedEventArgs, not DocumentCollectionEventArgs.
Re: Alternativ e Attribute command
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Have you a VB.NET example?


