Author Topic: Map 3D Inserting Annotation Template  (Read 1680 times)

0 Members and 1 Guest are viewing this topic.

stevenh0616

  • Guest
Map 3D Inserting Annotation Template
« on: April 20, 2012, 09:00:55 AM »
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:

Code - vb.net: [Select]
  1.         Using trans = AcDoc.TransactionManager.StartTransaction()
  2. SelectObjectToLabel:
  3.             myBT = myDwg.Database.BlockTableId.GetObject(OpenMode.ForWrite)
  4.             MSpaceBTR = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
  5.  
  6.             Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("SelectionPreview", 2)
  7.             Dim ObSel As ObjectId = SelectSoilBoundary()
  8.             Dim ObSelected As ObjectId
  9.  
  10.             If ObSel = Nothing Then
  11.                 trans.Abort()
  12.                 Exit Sub
  13.             Else
  14.                 ObSelected = ObSel
  15.                 Dim SrcEnt As DatabaseServices.Entity = ObSelected.GetObject(OpenMode.ForRead, True, True)
  16.                 GoTo NextLabelPoint
  17.  
  18. NextLabelPoint:
  19.                 Dim TempName As String = AnnTempName.Text
  20.                 Dim annOverride As New Annotation.AnnotationOverrides
  21.                 Dim Annotations As Annotation.Annotations = activeproj.Annotations
  22.                 Dim PickInsPt = PickInsertPt()
  23.  
  24.                 If PickInsPt = Nothing Then
  25.                     trans.Dispose()
  26.                     ObSel = Nothing
  27.                     ObSelected = Nothing
  28.                     SrcEnt = Nothing
  29.                     GoTo SelectObjectToLabel
  30.                 ElseIf PickInsPt > Nothing Then
  31.                     annOverride.Clear()
  32.                     annOverride.PositionExpressionOverride = PickInsPt
  33.  
  34.                     Dim mylbl As AnnotationTemplate
  35.                     mylbl = Annotations.Item(TempName)
  36.                     mylbl.InsertReference(ObSelected, annOverride)
  37.                     trans.Commit()
  38.                     GoTo NextLabelPoint
  39.                 Else
  40.                     trans.Dispose()
  41.                     ObSel = Nothing
  42.                     ObSelected = Nothing
  43.                     SrcEnt = Nothing
  44.                     GoTo SelectObjectToLabel
  45.                 End If
  46.             End If
  47.  
  48.             RestoreSP()
  49.             trans.Dispose()
  50.         End Using
« Last Edit: April 20, 2012, 09:05:58 AM by stevenh0616 »