OffsetInXref

OffsetInXref

Civil3DReminders_com
Mentor Mentor
363 Views
2 Replies
Message 1 of 3

OffsetInXref

Civil3DReminders_com
Mentor
Mentor
I'm failing at converting the Labs Plugin of the month OffsetInXref code to vb.net (http://labs.autodesk.com/utilities/ADN_plugins/updates/). I'm using one of the websites that converts c# to vb.net. Its/I'm having a problem converting the delagate from c# to vb.net. There is three locations where similar commands occur, but this code snippet is typical.

{code}
// When a document is created, make sure we handle the
// important events it fires

dm.DocumentCreated += delegate(object sender, DocumentCollectionEventArgs e)
{
e.Document.CommandWillStart +=
new CommandEventHandler(OnCommandWillStart);
e.Document.CommandEnded +=
new CommandEventHandler(OnCommandFinished);
e.Document.CommandCancelled +=
new CommandEventHandler(OnCommandFinished);
e.Document.CommandFailed +=
new CommandEventHandler(OnCommandFinished);
};
{code}
Here's the converted vb.net code which gives the errors in the first line.
{code}
' When a document is created, make sure we handle the
' important events it fires

dm.DocumentCreated += Function(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs) Do
AddHandler e.Document.CommandWillStart, AddressOf OnCommandWillStart
AddHandler e.Document.CommandEnded, AddressOf OnCommandFinished
AddHandler e.Document.CommandCancelled, AddressOf OnCommandFinished
AddHandler e.Document.CommandFailed, AddressOf OnCommandFinished
End Function
{code}

Thanks

Christopher
Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
0 Likes
364 Views
2 Replies
Replies (2)
Message 2 of 3

chiefbraincloud
Collaborator
Collaborator
I've encountered this before (and incidentally again yesterday, while I was converting portions of the screenshot tool to VB)

I don't think VB will let you do an inline function like this, so you take the function part:
{code}
Function(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
AddHandler e.Document.CommandWillStart, AddressOf OnCommandWillStart
AddHandler e.Document.CommandEnded, AddressOf OnCommandFinished
AddHandler e.Document.CommandCancelled, AddressOf OnCommandFinished
AddHandler e.Document.CommandFailed, AddressOf OnCommandFinished
End Function
{code}

And seperate it out into it's own function with a name like MyDocCreated or something.

then replace the whole inline function with an AddHandler call

AddHandler dm.DocumentCreated, AddressOf MyDocCreated
Dave O.                                                                  Sig-Logos32.png
0 Likes
Message 3 of 3

Civil3DReminders_com
Mentor
Mentor
Thanks that pointed me in the correct direction. Here's what I changed it to.
{code}
Public Sub Initialize() Implements IExtensionApplication.Initialize
Dim dm As DocumentCollection = Application.DocumentManager

AddHandler dm.DocumentLockModeWillChange, AddressOf OnLockModeWillChange
AddHandler dm.DocumentCreated, AddressOf OnDocumentCreated

' Do the same for any documents existing on application
' initialization
For Each doc As Document In dm
AddHandler doc.CommandWillStart, AddressOf OnCommandWillStart
AddHandler doc.CommandEnded, AddressOf OnCommandFinished
AddHandler doc.CommandCancelled, AddressOf OnCommandFinished
AddHandler doc.CommandFailed, AddressOf OnCommandFinished
Next

Try
RegistryUpdate.RegisterForDemandLoading()
Catch
End Try

End Sub

' Remove any temporary objects at the end of the command
Private Sub OnLockModeWillChange(ByVal sender As Object, ByVal e As DocumentLockModeWillChangeEventArgs)
If _ids.Count > 0 Then
Dim tr As Transaction = e.Document.TransactionManager.StartTransaction()
Using tr
For Each id As ObjectId In _ids
Dim obj As DBObject = tr.GetObject(id, OpenMode.ForWrite, True)
obj.[Erase]()
Next
tr.Commit()
End Using
_ids.Clear()

' Launch a command to bring across our layers

If Not _placeOnCurrentLayer Then
e.Document.SendStringToExecute("_.XOFFSETCPLAYS ", False, False, False)
End If
End If
End Sub

' When a document is created, make sure we handle the
' important events it fires
Private Sub OnDocumentCreated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
AddHandler e.Document.CommandWillStart, AddressOf OnCommandWillStart
AddHandler e.Document.CommandEnded, AddressOf OnCommandFinished
AddHandler e.Document.CommandCancelled, AddressOf OnCommandFinished
AddHandler e.Document.CommandFailed, AddressOf OnCommandFinished
End Sub

{code}
Civil Reminders
http://blog.civil3dreminders.com/
http://www.CivilReminders.com/
Alumni
0 Likes