I'm in the process of writing VBA/iLogic for creating a custom inspection dimension table to be placed on a drawing. I've been able to get the inspection dimensions data and fill in the table, but want to limit the table rows to the number of inspection dimensions. Right now the code counts the number of general dimenions and the custom table uses the number of general dimensions to create the number of table rows. (The Count property only appears to be included for DrawingDimensions, General Dimensions, and other dimension collections, but not inspection dimensions, because there is no collection for them.) So this count results in empty table rows if the general dimension is not an inspection dimension. I've also tried to delete rows that are empty without success. And I've also looked into creating an InspectionDimensions class or collection to include a Count property, but I have limited knowledge of how this is done. So, what is the best way to limit the table rows to only the number of inspection dimensions in the drawing and that I'm listing in the table? Thank you!
Public Sub CreateInspectionDimsTable() ' Set a reference to the drawing document. oDocType = ThisApplication.ActiveDocumentType If oDocType <> kDrawingDocumentObject Then MsgBox "This is not a drawing document." + vbCrLf + "Please open a drawing document.", vbOKOnly, "Drawing Document Error" Exit Sub End If Dim oDrawDoc As DrawingDocument Set oDrawDoc = ThisApplication.ActiveDocument ' Set a reference to the active sheet. Dim oSheet As Sheet Set oSheet = oDrawDoc.ActiveSheet If oSheet.CustomTables.Count > 0 Then oSheet.CustomTables.Item(1).Delete End If 'Set the column titles & Create the custom table Dim oInspTblTitle As String oInspTblTitle = "INSPECTION DIMENSIONS" Dim oTitles(1 To 3) As String oTitles(1) = "DIMENSION NUMBER" oTitles(2) = "DESIGN" oTitles(3) = "ACTUAL" oDrawDoc.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.TableStyle.HeadingGap = 0.125 oDrawDoc.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.TableStyle.ColumnValueHorizontalJustification = kAlignTextCenter oGenDimCount = oSheet.DrawingDimensions.GeneralDimensions.Count Debug.Print "General Dims Count = " + CStr(oGenDimCount) Debug.Print "Drawing Dims Count = " + CStr(oSheet.DrawingDimensions.Count) Debug.Print "Inspection Dims Count = " + "?" Dim oInspDimTable As CustomTable Set oInspDimTable = oSheet.CustomTables.Add(oInspTblTitle, ThisApplication.TransientGeometry.CreatePoint2d(1.5, 27), 3, oGenDimCount, oTitles) 'Get Inspection Dimension Data Dim oInspDim As DrawingDimension Dim oInspDimShape As InspectionDimensionShapeEnum Dim oInspDimText As DimensionText Dim oInspDimText2 As Variant Dim oInspDimNumber As String Dim oInspDimRate As String Dim i As Integer Dim oCellInspDimNum As Cell Dim oCellInspDim As Cell i = 1 For Each oSheet In oDrawDoc.Sheets For Each oInspDim In oSheet.DrawingDimensions If oInspDim.IsInspectionDimension Then oInspDim.GetInspectionDimensionData oInspDimShape, oInspDimNumber, oInspDimRate Set oInspDimText = oInspDim.Text oInspDimText2 = ThisApplication.UnitsOfMeasure.GetPreciseStringFromValue(oInspDim.ModelValue, kInchLengthUnits) Debug.Print oInspDimNumber Debug.Print oInspDimText.Text Debug.Print oInspDimText2 Debug.Print "" Set oCellInspDimNum = oInspDimTable.Rows.Item(i).Item("DIMENSION NUMBER") oCellInspDimNum.Value = oInspDimNumber Set oCellInspDim = oInspDimTable.Rows.Item(i).Item("DESIGN") oCellInspDim.Value = oInspDimText2 i = i + 1 End If Next Next oInspDimTable.Sort "DIMENSION NUMBER", True Dim oRow As Row For Each oRow In oInspDimTable.Rows If oCellInspDimNum.Value <> oInspDimNumber Then oRow.Delete End If Next End Sub
Solved! Go to Solution.
Solved by rjay75. Go to Solution.
Replace
oGenDimCount = oSheet.DrawingDimensions.GeneralDimensions.Count
with
oGenDimCount = 0 Dim oDim As DrawingDimension For Each oDim In oSheet.DrawingDimensions If oInspDim.IsInspectionDimension Then oGenDimCount = oGenDimCount + 1 End If Next
This will go through the list Dimensions counting the Inspection Dimensions.
I've been looking around for something like this, but upon using it, there were several coding errors. Most I have been able to fix, but i'm getting six errors for "'Let' and 'Set' assignment statements are no longer supported."
Anybody know what I need to change these to? Been looking around, cannot find anything on Let and Set.
FYI, I am using Inventor 2015
'Let' and 'Set' are used in VBA but not iLogic. The code above is VBA. Check the 'Straight VBA code' in the iLogic Rule Editor and it may work with some help. Otherwise, drop it in your inventor.ivb.
If you want to try to get this to operate, I was able to run the following and get it to work for my needs. I cobbled this together from several other threads on the board, and as you can see, it lacks a little efficiency.
Dim oDrawingDocument As DrawingDocument oDrawingDocument = ThisApplication.ActiveDocument Dim oSheet As Sheet oSheet = oDrawingDocument.ActiveSheet Dim oCustomTable As CustomTable Dim oCustomTables As CustomTables oCustomTables = oSheet.CustomTables For Each oCustomTable In oCustomTables If oCustomTable.Title = "FIELD VERIFICATION DIMENSIONS" Then oCustomTable.Delete() End If Next Dim oInspectionDimension As DrawingDimension Dim oInspectionDimensionShape As InspectionDimensionShapeEnum Dim oInspectionDimensionText As DimensionText Dim oInspectionDimensionString As String Dim oCellInspectionDimensionItem As Cell Dim oCellInspectionDimension As Cell Dim oInspectionDimensionCount As Integer oInspectionDimensionCount = 0 For Each oInspectionDimension In oSheet.DrawingDimensions If oInspectionDimension.IsInspectionDimension Then oInspectionDimensionCount = oInspectionDimensionCount + 1 End If Next Dim oColumnTitle(0 To 3) As String oColumnTitle(0) = "Column1" oColumnTitle(1) = "Column2" oColumnTitle(2) = "Column3" oColumnTitle(3) = "Column4" Dim oActiveTableStyle As TableStyle Dim oTableTitle As String oActiveTableStyle = oDrawingDocument.StylesManager.TableStyles("**THE NAME OF YOUR TABLE STYLE**") oTableTitle = oActiveTableStyle.Title Dim oFieldVerificationTable As CustomTable oFieldVerificationTable = oSheet.CustomTables.Add(oTableTitle, ThisApplication.TransientGeometry.CreatePoint2d(.635, oSheet.Height-.635), 4, oInspectionDimensionCount, oColumnTitle) Dim oInspectionDimensionCount2 As Integer oInspectionDimensionCount2 = 0 For Each oInspectionDimension In oSheet.DrawingDimensions If oInspectionDimension.IsInspectionDimension Then oInspectionDimensionCount2 = oInspectionDimensionCount2 + 1 oInspectionDimensionText = oInspectionDimension.Text oInspectionDimensionString = oInspectionDimensionText.Text oCellInspectionDimensionItem = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("Column1") oCellInspectionDimensionItem.Value = oInspectionDimensionCount2 oCellInspectionDimension = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("Column2") oCellInspectionDimension.Value = oInspectionDimensionString + "''" End If Next oFieldVerificationTable.Style = oActiveTableStyle iLogicVb.UpdateWhenDone = True
BrandonBG
Inventor 2015
Thanks, but for some reason I still get an error with your suggestion: "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"
Make sure you change the code to match your Table Styles:
Dim oActiveTableStyle As TableStyle Dim oTableTitle As String oActiveTableStyle = oDrawingDocument.StylesManager.TableStyles("!!!***HERE****!!!") oTableTitle = oActiveTableStyle.Title
If the rule can't find it, it will spit out an error. Working with Table Styles is not the most straightforward process. I had to declare the Active TableStyle, then make a table, and then apply the Style to the new table.
BrandonBG
Hello,
I have been searching for this code from past couple of days.
Finally, got it.
Thanks to you for posting a code.
As mentioned, we need to mention table style to run the code, otherwise it will show error message.
I had tried it, but still I am getting error message.
Please let me know, how to fix this.
Hello,
Now I am able to run the code successfully.
I am able to see inspection dimensions in tabular column.
I would like to tabulate dimensions other than inspection dimensions.
Is it possible, please let me know.
Hello guys
i have a special update wish to this theme
Automatically create check size table from existing part dimensioning.
Create a table that automatically retrieves and lists all inspection dimensions from the respective model file (.ipt and .iam).
Suggestion for possible columns:
Designation, dimension with tolerance, nominal dimension, tolerance, maximum dimension, minimum dimension, tolerance field, inspection rate in %.
I appreciate a lot your work!!!!
thx in advance
Tom
Hello, maybe you all can help me (i'm not so practice of ilogic).
I'd like to modify this Ilogic code in a way to obtain the following fields in the table.
-Columm1: the Label of the inspection dimension
-Columm2: the Value of the inspection dimension (as it already is)
-Columm3: the upper tolerance of the inspection dimension
-Columm4: the lower tolerance of the inspection dimension
-Columm5: the inspection rate of the inspection dimension
The result should be as in the followig sample.
An additional request: is there any way to make this table automatically updated each time I will insert a new or delete an inspection dimension?
Thank you so much, everybody
Can't find what you're looking for? Ask the community or share your knowledge.