I'm new to VB.net attempting to automate a soils boundary labeler with Map3D. I almost have it working but am having an issue.
I want the labeler to prompt for the object to label, then prompt for lable insertion point, then insert the label, then keep the same object selected and prompt for a new insertion point and insert a label there and repeat until the user doesn't select a point, then go back to select a new boundary and repeat... if that makes sense.
So if you know much about the annotation label process, you have to use an override to pick an insertion point by coordinates as a string, so I have a function called 'PickInsertPt()' that does just that. I also setup a function called 'SelectSoilBoundary()' that prompts for the selection. This process all works fine.
Upon running the command, it prompts for select object, then pick insertion point and inserts the label, then prompts for the next point --- but then it will either FATAL ERROR or it will say null object, object not set to instance of an object. If it does the second and I hit continue, it inserts the second label and ends the command... so it's working, but errors on the trans.commit() after the insertion.
Please help if you can... here is the code:
Using trans = AcDoc.TransactionManager.StartTransaction()
SelectObjectToLabel:
myBT = myDwg.Database.BlockTableId.GetObject(OpenMode.ForWrite)
MSpaceBTR = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("SelectionPreview", 2)
Dim ObSel As ObjectId = SelectSoilBoundary()
Dim ObSelected As ObjectId
If ObSel = Nothing Then
trans.Abort()
Exit Sub
Else
ObSelected = ObSel
Dim SrcEnt As DatabaseServices.Entity = ObSelected.GetObject(OpenMode.ForRead, True, True)
GoTo NextLabelPoint
NextLabelPoint:
Dim TempName As String = AnnTempName.Text
Dim annOverride As New Annotation.AnnotationOverrides
Dim Annotations As Annotation.Annotations = activeproj.Annotations
Dim PickInsPt = PickInsertPt()
If PickInsPt = Nothing Then
trans.Dispose()
ObSel = Nothing
ObSelected = Nothing
SrcEnt = Nothing
GoTo SelectObjectToLabel
ElseIf PickInsPt > Nothing Then
annOverride.Clear()
annOverride.PositionExpressionOverride = PickInsPt
Dim mylbl As AnnotationTemplate
mylbl = Annotations.Item(TempName)
mylbl.InsertReference(ObSelected, annOverride)
trans.Commit()
GoTo NextLabelPoint
Else
trans.Dispose()
ObSel = Nothing
ObSelected = Nothing
SrcEnt = Nothing
GoTo SelectObjectToLabel
End If
End If
RestoreSP()
trans.Dispose()
End Using