- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm working on a program that needs to attach bubbles to dimensions on the drawing. I want to have the bubble (sketch symbol) attach to one of the "green dots" via the API. I can do this manually, but when I try programatically, the positions are off. In the screencast I edit out one line of code. This inserts the endpoint of the leader (which is the same location as the start point) but for some reason this changes the symbol position.
I'd like to be able to replicate via API what happens in the first part of the screencast.
I've used some of the code found here. But it gets more difficult when dealing with the rangebox function of the dimension.
Here is the setup code:
Private Sub btnDim_Click(sender As Object, e As EventArgs) Handles btnDim.Click
Dim oDoc As DrawingDocument = _invApp.ActiveDocument
Dim SelectedFeature = _invApp.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Select something")
Select Case SelectedFeature.type
Case 117474560
LinearDim(SelectedFeature)
Case 117475328
DiametralDim(SelectedFeature)
Case 117475072
RadialDim(SelectedFeature)
Case 117483008
FCF(SelectedFeature)
Case 117471488
HoleTableTag(SelectedFeature)
Case 117491712
HoleTag(SelectedFeature)
Case 117473024
Note(SelectedFeature)
Case 117484032
Surface(SelectedFeature)
Case 117488384
Chamfer(SelectedFeature)
Case 117469952
HoleTable(SelectedFeature)
Case Else
MsgBox("Unknown")
End Select
End Sub
Private Sub LinearDim(oDim As LinearGeneralDimension)
dgvDimValues.Rows.Add(dgvDimValues.Rows.Count, oDim.GetHashCode, oDim.Text.Text, "TBD", oDim.Type, oDim.Tolerance.Upper, oDim.Tolerance.Lower)
InsertSketchedSymboSample(oDim, oDim.Text.RangeBox.MaxPoint, oDim.Text.RangeBox.MinPoint)
End Sub
Private Sub DiametralDim(oDim As DiameterGeneralDimension)
dgvDimValues.Rows.Add(dgvDimValues.Rows.Count, oDim.GetHashCode, oDim.Text.Text, "TBD", oDim.Type, oDim.Tolerance.Upper, oDim.Tolerance.Lower)
InsertSketchedSymboSample(oDim, oDim.Text.RangeBox.MaxPoint, oDim.Text.RangeBox.MinPoint)
End Sub
Private Sub RadialDim(oDim As RadiusGeneralDimension)
dgvDimValues.Rows.Add(dgvDimValues.Rows.Count, oDim.GetHashCode, oDim.Text.Text, "TBD", oDim.Type, oDim.Tolerance.Upper, oDim.Tolerance.Lower)
InsertSketchedSymboSample(oDim, oDim.Text.RangeBox.MaxPoint, oDim.Text.RangeBox.MinPoint)
End Sub
Private Sub Note(oDim As DrawingNote)
dgvDimValues.Rows.Add(dgvDimValues.Rows.Count, oDim.GetHashCode, oDim.Text, "TBD", oDim.Type)
InsertSketchedSymboSample(oDim, oDim.RangeBox.MaxPoint, oDim.RangeBox.MinPoint)
End Sub
Private Sub HoleTableTag(oDim As HoleTag)
dgvDimValues.Rows.Add(dgvDimValues.Rows.Count, oDim.GetHashCode, oDim.Text, "TBD", oDim.Type)
InsertSketchedSymboSample(oDim, oDim.RangeBox.MaxPoint, oDim.RangeBox.MinPoint)
End Sub
Private Sub Surface(oDim As SurfaceTextureSymbol)
dgvDimValues.Rows.Add(dgvDimValues.Rows.Count, oDim.GetHashCode, "Value", "TBD", oDim.Type, oDim.MaximumRoughness, oDim.MinimumRoughness)
InsertSketchedSymboSample(oDim, oDim.Position, oDim.Position)
End Sub
Private Sub HoleTag(oDim As HoleThreadNote)
dgvDimValues.Rows.Add(dgvDimValues.Rows.Count, oDim.GetHashCode, oDim.Text, "TBD", oDim.Type, oDim.Tolerance.Upper, oDim.Tolerance.Lower)
InsertSketchedSymboSample(oDim, oDim.Text.RangeBox.MaxPoint, oDim.Text.RangeBox.MinPoint)
End Sub
Private Sub Chamfer(oDim As ChamferNote)
dgvDimValues.Rows.Add(dgvDimValues.Rows.Count, oDim.GetHashCode, oDim.Text, "TBD", oDim.Type, "NA", "NA")
InsertSketchedSymboSample(oDim, oDim.RangeBox.MaxPoint, oDim.RangeBox.MinPoint)
End Sub
Private Sub HoleTable(oDim As HoleTable)
Dim Text As String = ""
For Each Row As HoleTableRow In oDim.HoleTableRows
For Each Col In oDim.HoleTableColumns
Debug.Print(Row.Item(Col).Text)
Next
'Text = Text & item.HoleTag & " " & item. & " " & item.DatumTwo & " " & item.DatumThree & vbNewLine
'dgvDimValues.Rows.Add(dgvDimValues.Rows.Count, oDim.GetHashCode, Text, "TBD", oDim.Type, item.Tolerance, item.LowerTolerance)
Next
InsertSketchedSymboSample(oDim, oDim.RangeBox.MaxPoint, oDim.RangeBox.MinPoint)
End Sub
Private Sub FCF(oDim As FeatureControlFrame)
Dim Text As String = ""
For Each item As FeatureControlFrameRow In oDim.FeatureControlFrameRows
Text = Text & item.GeometricCharacteristic & " " & item.DatumOne & " " & item.DatumTwo & " " & item.DatumThree & vbNewLine
dgvDimValues.Rows.Add(dgvDimValues.Rows.Count, oDim.GetHashCode, Text, "TBD", oDim.Type, item.Tolerance, item.LowerTolerance)
Next
InsertSketchedSymboSample(oDim, oDim.Position, oDim.Position)
End Sub
Sub HoleTable()
Dim oDoc As DrawingDocument
oDoc = _invApp.ActiveDocument
Dim oHoleTable As HoleTable
oHoleTable = oDoc.ActiveSheet.HoleTables.Item(1)
Dim oRow As HoleTableRow
For Each oRow In oHoleTable.HoleTableRows
Dim subItem As HoleTableCell
For Each subItem In oRow
Debug.Print(subItem.Text)
Next
Next
End SubHere is the insertion code:
Public Sub CreateSketchedSymbolDefinition()
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = _invApp.ActiveDocument
' Create the new sketched symbol definition.
Dim oSketchedSymbolDef As SketchedSymbolDefinition
oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Add("mySymbol")
' Open the sketched symbol definition's sketch for edit. This is done by calling the Edit
' method of the SketchedSymbolDefinition to obtain a DrawingSketch. This actually creates
' a copy of the sketched symbol definition's and opens it for edit.
Dim oSketch As DrawingSketch = Nothing
Call oSketchedSymbolDef.Edit(oSketch)
Dim oTG As TransientGeometry
oTG = _invApp.TransientGeometry
Dim oInsertionPoint As Point2d = (oTG.CreatePoint2d(0, 0))
Dim oSketchCircle As SketchCircle
oSketchCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(-0.1, 0.1), 0.1)
' Add a prompted text field at the center of the sketch circle.
Dim sText As String
sText = "<Prompt>1</Prompt>"
Dim oTextBox As TextBox
oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(-0.1, 0.1), sText)
oTextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
Call oSketchedSymbolDef.ExitEdit(True)
End Sub
Public Sub InsertSketchedSymboSample(oDim As Object, ByRef MaxP As Point2d, ByRef MinP As Point2d) 'ByRef Text As Box2d)
Dim oDrawDoc As DrawingDocument
oDrawDoc = _invApp.ActiveDocument
' Obtain a sketched symbol definition.
Dim oSketchedSymbolDef As SketchedSymbolDefinition = Nothing
For i = 1 To oDrawDoc.SketchedSymbolDefinitions.Count
If oDrawDoc.SketchedSymbolDefinitions.Item(i).Name = "mySymbol" Then
oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item(i)
Exit For
End If
Next
If oSketchedSymbolDef Is Nothing Then
CreateSketchedSymbolDefinition()
For i = 1 To oDrawDoc.SketchedSymbolDefinitions.Count
If oDrawDoc.SketchedSymbolDefinitions.Item(i).Name = "mySymbol" Then
oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item(i)
Exit For
End If
Next
End If
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet
Dim sPromptStrings(0) As String
sPromptStrings(0) = dgvDimValues.RowCount - 1
' Create sketched symbol
Dim oTG As TransientGeometry
oTG = _invApp.TransientGeometry
Dim oPoint As Point2d = Nothing
For x = 0 To 315 Step 45
Select Case x 'My.Settings.BalloonPos
Case 0
oPoint = oTG.CreatePoint2d(MinP.X + (MaxP.X - MinP.X) / 2, MaxP.Y)
Case 45
oPoint = oTG.CreatePoint2d(MaxP.X, MaxP.Y)
Case 90
oPoint = oTG.CreatePoint2d(MaxP.X, MinP.Y + (MaxP.Y - MinP.Y) / 2)
Case 135
oPoint = oTG.CreatePoint2d(MaxP.X, MinP.Y)
Case 180
oPoint = oTG.CreatePoint2d(MinP.X + (MaxP.X - MinP.X) / 2, MinP.Y)
Case 225
oPoint = oTG.CreatePoint2d(MinP.X, MinP.Y)
Case 270
oPoint = oTG.CreatePoint2d(MinP.X, MinP.Y + (MaxP.Y - MinP.Y) / 2)
Case 315
oPoint = oTG.CreatePoint2d(MinP.X, MaxP.Y)
End Select
Dim oSketchedSymbol As SketchedSymbol
Dim oGI As GeometryIntent
oGI = oSheet.CreateGeometryIntent(oDim, oPoint)
Dim oCol As ObjectCollection
oCol = _invApp.TransientObjects.CreateObjectCollection oCol.Add(_invApp.TransientGeometry.CreatePoint2d(oGI.Intent.X, oGI.Intent.Y))
oCol.Add(oGI) ''' This is the line I edited out'''
oSketchedSymbol = oSheet.SketchedSymbols.AddWithLeader(oSketchedSymbolDef, oCol,,, sPromptStrings)
oSketchedSymbol.LeaderVisible = True
Next
End Sub
7d2deba2-2ad0-474a-87cd-d8919966121e
Solved! Go to Solution.