<?xml encoding=”UTF-8″>By Balaji Ramamoorthy
Splitting a HoleTable using API is not possible at present. In this blog post we will look at a workaround that mimics a split HoleTable by creating two HoleTables each of which lists a certain hole information. Please note that this workaround creates two separate HoleTables both of which are unrelated and have Sheet as its parent. In case of splitting a HoleTable using Inventor UI, the split HoleTable is nested under a parent HoleTable. This structure provides the option to un-split the HoleTables at any time, if you need to. Such un-split option would not be available when using the workaround demonstrated in this blog post, as the two HoleTables are unrelated. As the HoleTables are separate and have Sheet as their parent, Inventor would not know that the two tables are related by a split.
Here is a VBA code snippet which should work with the attached drawing. If you are trying it on any other drawing, the index values may need to be modified accordingly.
<span>Dim</span><span> oDoc <span>As</span><span> DrawingDocument</span></span>
<span>Set</span><span> oDoc = ThisDocument</span>
<span>Dim</span><span> oSheet <span>As</span><span> Sheet</span></span>
<span>Set</span><span> oSheet = oDoc.Sheets.Item(1)</span>
<span>Dim</span><span> oDrawingView <span>As</span><span> DrawingView</span></span>
<span>Set</span><span> oDrawingView = oSheet.DrawingViews.Item(2)</span>
<span>'Modify the index to ensure that the right</span>
<span>'drawing curve is used to create the intent</span>
<span>'For the attached drawing, this will locate </span>
<span>'the origin indicator at the lower left corner</span>
<span>Dim</span><span> oCurve <span>As</span><span> DrawingCurve</span></span>
<span>Set</span><span> oCurve = oDrawingView.DrawingCurves.Item(53)</span>
Debug.Print oCurve.CurveType
<span>Dim</span><span> oIntent <span>As</span><span> GeometryIntent</span></span>
<span>Set</span><span> oIntent _</span>
= oSheet.CreateGeometryIntent(oCurve, oCurve.StartPoint)
<span>'Create an origin indicator</span>
<span>If</span><span> <span>Not</span><span> oDrawingView.HasOriginIndicator <span>Then</span><span> </span></span></span>
<span>Call</span><span> oDrawingView.CreateOriginIndicator(oIntent)</span>
<span>End</span><span> <span>If</span><span> </span></span>
<span>'Positions of the hole tables</span>
<span>Dim</span><span> oPt1 <span>As</span><span> Point2d</span></span>
<span>Set</span><span> oPt1 _</span>
= ThisApplication.TransientGeometry.CreatePoint2d(35, 45)
<span>Dim</span><span> oPt2 <span>As</span><span> Point2d</span></span>
<span>Set</span><span> oPt2 _</span>
= ThisApplication.TransientGeometry.CreatePoint2d(55, 45)
<span>'Create a hole table for the drawing view</span>
<span>Dim</span><span> oHoleTable1 <span>As</span><span> HoleTable</span></span>
<span>Set</span><span> oHoleTable1 = oSheet.HoleTables.Add(oDrawingView, oPt1)</span>
<span>Dim</span><span> oCollection1 <span>As</span><span> ObjectCollection</span></span>
<span>Set</span><span> oCollection1 _</span>
= ThisApplication.TransientObjects.CreateObjectCollection()
<span>Dim</span><span> oCollection2 <span>As</span><span> ObjectCollection</span></span>
<span>Set</span><span> oCollection2 _</span>
= ThisApplication.TransientObjects.CreateObjectCollection()
<span>'Identify the row to split</span><span> </span>
<span>Dim</span><span> splitRow <span>As</span><span> <span>Integer</span><span> </span></span></span>
<span>Dim</span><span> rowsCnt <span>As</span><span> <span>Integer</span><span> </span></span></span>
rowsCnt = oHoleTable1.HoleTableRows.Count
<span>If</span><span> rowsCnt <span>Mod</span><span> 2 = 0 <span>Then</span><span> </span></span></span>
splitRow = rowsCnt / 2
<span>Else</span><span> </span>
splitRow = (rowsCnt - 1) / 2
<span>End</span><span> <span>If</span><span> </span></span>
<span>'Get the hole curves for creating the hole tables</span>
<span>Dim</span><span> cnt <span>As</span><span> <span>Integer</span><span> </span></span></span>
cnt = 1
<span>For</span><span> <span>Each</span><span> oRow <span>In</span><span> oHoleTable1.HoleTableRows</span></span></span>
cnt = cnt + 1
<span>If</span><span> cnt < splitRow <span>Then</span><span> </span></span>
oCollection1.Add oRow.ReferencedHole
<span>Else</span><span> </span>
oCollection2.Add oRow.ReferencedHole
<span>End</span><span> <span>If</span><span> </span></span>
<span>Next</span><span> </span>
oHoleTable1.Delete
<span>'Split hole table - 1</span>
<span>Dim</span><span> oSplitHoleTable1 <span>As</span><span> HoleTable</span></span>
<span>Set</span><span> oSplitHoleTable1 _</span>
= oSheet.HoleTables.AddSelected(oCollection1, oPt1)
<span>'Split hole table - 2</span>
<span>Dim</span><span> oSplitHoleTable2 <span>As</span><span> HoleTable</span></span>
<span>Set</span><span> oSplitHoleTable2 _</span>
= oSheet.HoleTables.AddSelected(oCollection2, oPt2)
<span>'Renumber the second hole table to mimic a split table</span>
cnt = oSplitHoleTable1.HoleTableRows.Count + 1
<span>For</span><span> <span>Each</span><span> oRow <span>In</span><span> oSplitHoleTable2.HoleTableRows</span></span></span>
oRow.Item(1).FormattedText = "A" & <span>CStr</span><span> (cnt)</span>
cnt = cnt + 1
<span>Next</span>

Leave a Reply