Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 532

Get ItemNumber from a DrawingCurve

$
0
0

By Adam Nagy

If you want to find out which DrawingBOMRow / BOMRow a DrawingCurve belongs to in order to get e.g. the ItemNumber associated with the component that the DrawingCurve represents, the most straightforward way might be to let the Balloon object figure that out for us. 

We can temporarily create a Balloon that would reference that DrawingCurve. If it's done inside a Transaction that is Aborted, then it will look as if the Balloon has never been created at all.

Let's say we have a SketchedSymbol whose first TextBox is a prompted entry we want to set and an instance of it is already attached to the DrawingCurve, then we could update it using this code:

Public Sub SetSketchedSymbolNumber()
  Dim oDwg As DrawingDocument
  Set oDwg = ThisApplication.ActiveDocument' The SketchedSymbol needs to be selected
  Dim oSymbol As SketchedSymbol
  Set oSymbol = oDwg.SelectSet(1)' The symbol's leader needs to be' attached to the Component
  Dim oNode As LeaderNode
  Set oNode = oSymbol.Leader.AllLeafNodes(1)
  Dim oCurve As DrawingCurve
  Set oCurve = oNode.AttachedEntity.Geometry
  Dim oSheet As Sheet
  Set oSheet = oDwg.ActiveSheet
  Dim oTO As TransientObjects
  Set oTO = ThisApplication.TransientObjects
  Dim oTG As TransientGeometry
  Set oTG = ThisApplication.TransientGeometry
  Dim oLeaderPoints As ObjectCollection
  Set oLeaderPoints = oTO.CreateObjectCollection' Does not matter what we add as first point
  Call oLeaderPoints.Add(oTG.CreatePoint2d(0, 0))' Get item number from the temporary balloon
  Dim itemNumber As String
  Dim oTM As TransactionManager
  Set oTM = ThisApplication.TransactionManager
  Dim oTransaction As Transaction
  Set oTransaction = oTM.StartTransaction(oDwg, "TempTransaction")

  Dim oGeometryIntent As GeometryIntent
  Set oGeometryIntent = oSheet.CreateGeometryIntent(oCurve)
  Call oLeaderPoints.Add(oGeometryIntent)
  
  Dim oBalloon As Balloon
  Set oBalloon = oSheet.Balloons.Add(oLeaderPoints, , kStructured)
  
  ' We could also get the DrawingBOMRow and BOMRow' oBalloon.BalloonValueSets(1).ReferencedRow.BOMRow' but this time we just need the ItemNumber
  itemNumber = oBalloon.BalloonValueSets(1).itemNumber' This transaction will not show up in the Undo/Redo stack' and it will look as if the above balloon never existed
  Call oTransaction.Abort' Update the first textbox in the sketched symbol' with the item number
  Dim oBox As TextBox
  Set oBox = oSymbol.Definition.sketch.TextBoxes(1)
  Call oSymbol.SetPromptResultText( _
    oBox, itemNumber)
End Sub

SketchedSymbol

There is a more comprehensive sample on creating a Balloon in the API Help file"C:\Program Files\Autodesk\Inventor 2014\Local Help\admapi_18_0.chm" 


Viewing all articles
Browse latest Browse all 532

Trending Articles