- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
iLogic Rule to create description based on dimensions, bounding box, stock number
This is my way of giving back to the forum.
Thanks for all the help!
I made an iLogic rule to automatically create descriptions for parts.
Here's how it works:
1. Run the rule.
2. You are prompted to select a line of a part in a drawing view.
3. An input pox is diplayed with an overridable default description.
4. Click "OK" and you're done!
The code distinguishes between all of the content center parts in the above list,
and creates a description based on dimensions/bounding box/stock number
If you have any comments on the code, be sure to let me know ![]()
I've tried to add helpful annotations, but know that I'm really not a coder.
some of this code is just stitched together from other sources.
Here ya go:
'Code to modify a part's description iPorperty based on shape, created by Jonathan Fowler 'Works by selecting a line segment from a part in a drawing view. 'Document declaration Dim oDoc As Inventor.Document oDoc = ThisApplication.ActiveDocument 'Prompt user to pick a line segment Dim oDrawCurveSeg As DrawingCurveSegment oDrawCurveSeg = ThisApplication.CommandManager.Pick _ (Inventor.SelectionFilterEnum. kDrawingCurveSegmentFilter, "Select a Drawing Curve") 'Get the parent DrawingCurve Dim oDrawCurve As DrawingCurve Try oDrawCurve = oDrawCurveSeg.Parent Catch ex As Exception Exit Sub End Try 'Get the model geometry this curve represents. Dim oModelGeom As Object oModelGeom = oDrawCurve.ModelGeometry 'Check to see if the returned object supports 'the ContainingOccurrence property. Dim oOcc As ComponentOccurrence Try oOcc = oModelGeom.ContainingOccurrence Catch ex As Exception 'MessageBox.Show("Problem getting occurrence for: " & partName, "iLogic") End Try 'Define model geometry Dim oModelGeometry = oDrawCurveSeg.Parent.ModelGeometry 'Define component definition Dim oCompDef As ComponentDefinition oCompDef = oModelGeometry.parent.componentdefinition 'Get part name partName = oCompDef.Document.DisplayName 'Get the drawing view Dim oDrwView As DrawingView oDrwView = oDrawCurve.Parent 'Define oPart As String oPart = oCompDef.Document.DisplayName & ".ipt" 'Declare AutoType, the part shape type to be calculated. Dim AutoType As String 'Define Units of Measure Dim uom as UnitsOfMeasure = oDoc.UnitsOfMeasure 'Declare the range box. Dim oRB As Box Try 'Get the range box, aligned to part UCS, excluding work geometry. For Each sb In oCompDef.SurfaceBodies If oRB Is Nothing Then oRB = sb.RangeBox.Copy Else oRB.Extend(sb.RangeBox.MinPoint) oRB.Extend(sb.RangeBox.MaxPoint) End If Next Catch ex As Exception MessageBox.Show("Error finding extensions for part: " & partName, "iLogic") End Try Dim minp As point = oRB.minPoint Dim maxp As point = oRB.maxPoint Dim AutoName As String AutoName = "-" InventorVb.DocumentUpdate() Try oCheckFile = iProperties.Value(oPart, "Project", "Part Number") Catch MessageBox.Show("Error finding file for part: " & partName, "iLogic") Exit Sub End Try 'Get part dimensions dp=0 X = Round(uom.ConvertUnits ((maxP.X - minP.X), "cm", uom.LengthUnits), dp) Y = Round(uom.ConvertUnits ((maxP.Y - minP.Y), "cm", uom.LengthUnits), dp) Z = Round(uom.ConvertUnits ((maxP.Z - minP.Z), "cm", uom.LengthUnits), dp) 'MessageBox.Show("Extents: " & X & " : " & Y & " : " & Z, "iLogic") 'Sort dimensions largest to smallest Thickness = MinOfMany(X, Y, Z) Length = MaxOfMany(X, Y, Z) Width = X If Thickness = X Or Length = X Then Width = Y If Thickness = Y Or Length = Y Then Width = Z End If End If 'Get stock number properties (which are sometimes different to actual dimensions) Dim stockprops() As String Try stockprops = Split(iProperties.Value(oPart, "Project", "Stock Number"), "x") Catch End Try Try 'Use part parameter named "Type", if it exists. 'This can be used as an override for a part which is being wrongly assessed. AutoType = Parameter(oPart, "Type") Catch ex As Exception 'Test for parameters Try parametro = Parameter(oPart, "G_NG") G_NG = 1 Catch G_NG = 0 End Try Try parametro = Parameter(oPart, "G_T") G_T = 1 Catch G_T = 0 End Try Try parametro = Parameter(oPart, "G_W") G_W = 1 Catch G_W = 0 End Try Try parametro = Parameter(oPart, "G_ER") G_ER = 1 Catch G_ER = 0 End Try Try parametro = Parameter(oPart, "G_T1") G_T1 = 1 Catch G_T1 = 0 End Try 'Compare to expected parameters If G_NG = 1 Then AutoType = "PFC" ElseIf G_T1 = 0 And G_W = 1 And G_ER = 0 And G_T = 1 Then AutoType = "RHS" ElseIf G_T = 1 And G_W = 0 Then AutoType = "CHS" ElseIf G_T = 0 And G_W = 0 Then AutoType = "RD BAR" ElseIf G_T1 = 1 And G_NG = 0 Then AutoType = "UC" ElseIf G_ER = 1 Then AutoType = "RSA" ElseIf G_W = 1 And G_T = 0 Then AutoType = "F BAR" Else AutoType = "" End If End Try 'Set Shape Type If AutoType = "" Then 'Prompt for manual input - in format "PFC", "F BAR", "RD BAR", "UC", etc. oType = InputBox("Treat as:", "Part Type", AutoType) Else 'Use automatically calculated type oType = AutoType End If 'Create a default description Select Case UCase(oType) Case "PLATE" AutoName = "PLT " & Thickness & " THK " & Length & " x " & Width Case "F BAR" AutoName = "F/BAR " & Width & " x " & Thickness Case "CHS" Try AutoName = "CHS " & Parameter(oPart, "G_H") & " OD x " & Parameter(oPart, "G_T") & " WT" Catch MessageBox.Show("Error getting parameters", "iLogic") AutoName = "" End Try Case "SHS", "RHS" Try 'Distinguish between square and rectangular section If Parameter(oPart, "G_W") = Parameter(oPart, "G_H") Then AutoName = "SHS " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T") Else AutoName = "RHS " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T") End If Catch MessageBox.Show("Error getting parameters", "iLogic") AutoName = "" End Try Case "RD BAR" Try AutoName = "RD BAR DIA. " & Parameter(oPart, "G_H") Catch MessageBox.Show("Error getting parameters", "iLogic") AutoName = "" End Try Case "RSA" Try AutoName = "RSA " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T") Catch MessageBox.Show("Error getting parameters", "iLogic") AutoName = "" End Try Case "PFC" Try AutoName = "PFC " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2) Catch MessageBox.Show("Error getting parameters", "iLogic") AutoName = "" End Try Case "UC", "UB" Try 'Distinguish between collumn and beam If Val(stockprops(0)) <= Val(stockprops(1)) Then AutoName = "UC " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2) Else AutoName = "UB " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2) End If Catch MessageBox.Show("Error getting parameters", "iLogic") AutoName = "" End Try Case Else AutoName = "" End Select 'Show input box with default description oNewDescription = InputBox("Description for '" & partName & "':", "Description Editor", AutoName) If oNewDescription = "" Then 'Cancel if no description is entered. MessageBox.Show("Description change cancelled.", "iLogic") Else 'Change part description iProperties.Value(oPart, "Project", "Description") = oNewDescription InventorVb.DocumentUpdate() 'Restart to choose next part iLogicVb.RunRule("Dimensions - Individual") End If
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
An update to make it better at recognizing plate.
'Code to modify a part's description iPorperty based on shape. 'Works by selecting a line segment from a part in a drawing view. 'Document declaration Dim oDoc As Inventor.Document oDoc = ThisApplication.ActiveDocument 'Prompt user to pick a line segment Dim oDrawCurveSeg As DrawingCurveSegment oDrawCurveSeg = ThisApplication.CommandManager.Pick _ (Inventor.SelectionFilterEnum. kDrawingCurveSegmentFilter, "Select a Drawing Curve") 'Get the parent DrawingCurve Dim oDrawCurve As DrawingCurve Try oDrawCurve = oDrawCurveSeg.Parent Catch ex As Exception Exit Sub End Try 'Get the model geometry this curve represents. Dim oModelGeom As Object oModelGeom = oDrawCurve.ModelGeometry 'Check to see if the returned object supports 'the ContainingOccurrence property. Dim oOcc As ComponentOccurrence oModelGeom = oDrawCurve.ModelGeometry Try oOcc = oModelGeom.ContainingOccurrence Catch ex As Exception 'MessageBox.Show("Problem getting occurrence for: " & partName, "iLogic") End Try 'Define model geometry Dim oModelGeometry = oDrawCurveSeg.Parent.ModelGeometry 'Define component definition Dim oCompDef As ComponentDefinition oCompDef = oModelGeometry.parent.componentdefinition 'Get part name partName = oCompDef.Document.DisplayName 'Get the drawing view Dim oDrwView As DrawingView oDrwView = oDrawCurve.Parent 'Define oPart As String oPart = oCompDef.Document.DisplayName & ".ipt" 'Declare AutoType, the part shape type to be calculated. Dim AutoType As String 'Define Units of Measure Dim uom as UnitsOfMeasure = oDoc.UnitsOfMeasure Dim minp As point Dim maxp As point 'Declare the range box. Dim oRB As Box Try 'Get the range box, aligned to part UCS, excluding work geometry. For Each sb In oCompDef.SurfaceBodies If oRB Is Nothing Then oRB = sb.RangeBox.Copy Else oRB.Extend(sb.RangeBox.MinPoint) oRB.Extend(sb.RangeBox.MaxPoint) End If Next minp = oRB.minPoint maxp = oRB.maxPoint Catch ex As Exception MessageBox.Show("Error finding extensions for part: " & partName, "iLogic") Exit Sub End Try Dim AutoName As String AutoName = "-" InventorVb.DocumentUpdate() Try oCheckFile = iProperties.Value(oPart, "Project", "Part Number") Catch MessageBox.Show("Error finding file for part: " & partName, "iLogic") Exit Sub End Try 'Get part dimensions dp=0 X = Round(uom.ConvertUnits ((maxP.X - minP.X), "cm", uom.LengthUnits), dp) Y = Round(uom.ConvertUnits ((maxP.Y - minP.Y), "cm", uom.LengthUnits), dp) Z = Round(uom.ConvertUnits ((maxP.Z - minP.Z), "cm", uom.LengthUnits), dp) 'MessageBox.Show("Extents: " & X & " : " & Y & " : " & Z, "iLogic") 'Sort dimensions largest to smallest Thickness = MinOfMany(X, Y, Z) Length = MaxOfMany(X, Y, Z) Width = X If Thickness = X Or Length = X Then Width = Y If Thickness = Y Or Length = Y Then Width = Z End If End If 'Get stock number properties (which are sometimes different to actual dimensions) Dim stockprops() As String Try stockprops = Split(iProperties.Value(oPart, "Project", "Stock Number"), "x") Catch End Try Try 'Use part parameter named "Type", if it exists. 'This can be used as an override for a part which is being wrongly assessed. AutoType = Parameter(oPart, "Type") Catch ex As Exception 'Test for parameters Try parametro = Parameter(oPart, "G_NG") G_NG = 1 Catch G_NG = 0 End Try Try parametro = Parameter(oPart, "G_T") G_T = 1 Catch G_T = 0 End Try Try parametro = Parameter(oPart, "G_W") G_W = 1 Catch G_W = 0 End Try Try parametro = Parameter(oPart, "G_ER") G_ER = 1 Catch G_ER = 0 End Try Try parametro = Parameter(oPart, "G_T1") G_T1 = 1 Catch G_T1 = 0 End Try Try parametro = Parameter(oPart, "G_H") G_H = 1 Catch G_H = 0 End Try 'Compare to expected parameters If G_NG = 1 Then AutoType = "PFC" ElseIf G_T1 = 0 And G_W = 1 And G_ER = 0 And G_T = 1 Then AutoType = "RHS" ElseIf G_T = 1 And G_W = 0 Then AutoType = "CHS" ElseIf G_T = 0 And G_W = 0 And G_H = 1 Then AutoType = "RD BAR" ElseIf G_T1 = 1 And G_NG = 0 Then AutoType = "UC" ElseIf G_ER = 1 Then AutoType = "RSA" ElseIf G_W = 1 And G_T = 0 Then AutoType = "F BAR" ElseIf G_H = 0 Then AutoType = "PLATE" Else 'leave blank if no match is found. AutoType = "" End If End Try 'Set Shape Type If AutoType = "" Then 'Prompt for manual input - in format "PFC", "F BAR", "RD BAR", "UC", etc. oType = InputBox("Treat as:", "Part Type", AutoType) Else 'Use automatically calculated type oType = AutoType End If 'Create a default description Select Case UCase(oType) Case "PLATE" AutoName = "PLT " & Thickness & " THK " & Length & " x " & Width Case "F BAR" AutoName = "F/BAR " & Width & " x " & Thickness Case "CHS" Try AutoName = "CHS " & Parameter(oPart, "G_H") & " OD x " & Parameter(oPart, "G_T") & " WT" Catch MessageBox.Show("Error getting parameters", "iLogic") AutoName = "" End Try Case "SHS", "RHS" Try 'Distinguish between square and rectangular section If Parameter(oPart, "G_W") = Parameter(oPart, "G_H") Then AutoName = "SHS " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T") Else AutoName = "RHS " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T") End If Catch MessageBox.Show("Error getting parameters as " & oType, "iLogic") AutoName = "" End Try Case "RD BAR" Try AutoName = "RD BAR DIA. " & Parameter(oPart, "G_H") Catch MessageBox.Show("Error getting parameters as " & oType, "iLogic") AutoName = "" End Try Case "RSA" Try AutoName = "RSA " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T") Catch MessageBox.Show("Error getting parameters as " & oType, "iLogic") AutoName = "" End Try Case "PFC" Try AutoName = "PFC " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2) Catch MessageBox.Show("Error getting parameters as " & oType, "iLogic") AutoName = "" End Try Case "UC", "UB" Try 'Distinguish between collumn and beam If Val(stockprops(0)) <= Val(stockprops(1)) Then AutoName = "UC " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2) Else AutoName = "UB " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2) End If Catch MessageBox.Show("Error getting parameters as " & oType, "iLogic") AutoName = "" End Try Case Else AutoName = "" End Select 'Show input box with default description oNewDescription = InputBox("Description for '" & partName & "':", "Description Editor", AutoName) If oNewDescription = "" Then 'Cancel if no description is entered. MessageBox.Show("Description change cancelled.", "iLogic") Else 'Change part description iProperties.Value(oPart, "Project", "Description") = oNewDescription InventorVb.DocumentUpdate() 'Restart to choose next part iLogicVb.RunRule("Dimensions - Individual") End If
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Another update.
I wish I could just edit my original post, but I don't seem to be able to, so here's the update:
'Code to modify a part's description iPorperty based on shape. Created by Jonathan Fowler.
'Works by selecting a line segment from a part in a drawing view.
'Document declaration
Dim oDoc As Inventor.Document
oDoc = ThisApplication.ActiveDocument
'Prompt user to pick a line segment
'Dim oDrawCurveSeg As DrawingCurveSegment
oDrawCurveSeg = ThisApplication.CommandManager.Pick _
(Inventor.SelectionFilterEnum.
kDrawingCurveSegmentFilter,
"Select a Drawing Curve")
'Get the parent DrawingCurve
Dim oDrawCurve As DrawingCurve
Try
oDrawCurve = oDrawCurveSeg.Parent
Catch ex As Exception
'MessageBox.Show("No drawing curve found.", "iLogic")
Exit Sub
End Try
'Get the model geometry this curve represents.
Dim oModelGeom As Object
oModelGeom = oDrawCurve.ModelGeometry
'Check to see if the returned object supports
'the ContainingOccurrence property.
Dim oOcc As ComponentOccurrence
Try
oOcc = oModelGeom.ContainingOccurrence
Catch ex As Exception
'MessageBox.Show("Problem getting occurrence for: " & partName, "iLogic")
End Try
'Define model geometry
Dim oModelGeometry = oDrawCurveSeg.Parent.ModelGeometry
'Define component definition
Dim oCompDef As ComponentDefinition
oCompDef = oModelGeometry.parent.componentdefinition
'Get part name
partName = oCompDef.Document.DisplayName
'MessageBox.Show(partName & " selected.", "iLogic")
'Get the drawing view
Dim oDrwView As DrawingView
oDrwView = oDrawCurve.Parent
'Define oPart As String
oPart = oCompDef.Document.DisplayName & ".ipt"
'Declare AutoType, the part shape type to be calculated.
Dim AutoType As String
'Define Units of Measure
Dim uom as UnitsOfMeasure = oDoc.UnitsOfMeasure
Dim minp As point
Dim maxp As point
'Declare the range box.
Dim oRB As Box
Try
'Get the range box, aligned to part UCS, excluding work geometry.
For Each sb In oCompDef.SurfaceBodies
If oRB Is Nothing Then
oRB = sb.RangeBox.Copy
Else
oRB.Extend(sb.RangeBox.MinPoint)
oRB.Extend(sb.RangeBox.MaxPoint)
End If
Next
minp = oRB.minPoint
maxp = oRB.maxPoint
Catch ex As Exception
MessageBox.Show("Error finding extensions for part: " & partName, "iLogic")
Exit Sub
End Try
Dim AutoName As String
AutoName = "-"
InventorVb.DocumentUpdate()
Try
oCheckFile = iProperties.Value(oPart, "Project", "Part Number")
Catch
MessageBox.Show("Error finding file for part: " & partName, "iLogic")
Exit Sub
End Try
'Get part dimensions
dp=0
X = Round(uom.ConvertUnits ((maxP.X - minP.X), "cm", uom.LengthUnits), dp)
Y = Round(uom.ConvertUnits ((maxP.Y - minP.Y), "cm", uom.LengthUnits), dp)
Z = Round(uom.ConvertUnits ((maxP.Z - minP.Z), "cm", uom.LengthUnits), dp)
'MessageBox.Show("Extents: " & X & " : " & Y & " : " & Z, "iLogic")
'Sort dimensions from smallest to largest
Dim extents As New ArrayList()
extents.add(X)
extents.add(Y)
extents.add(Z)
extents.Sort()
'MessageBox.Show("Extents: " & extents(0) & " : " & extents(1) & " : " & extents(2), "iLogic")
'Assign dimensions
Thickness = extents(0)
Width = extents(1)
Length = extents(2)
'Get stock number properties (which are sometimes different to actual dimensions)
Dim stockprops() As String
Try
stockprops = Split(iProperties.Value(oPart, "Project", "Stock Number"), "x")
Catch
End Try
'Get classification for fasteners
Dim stockclass() As String
Try
stockclass = Split(iProperties.Value(oPart, "Project", "Part Number"), "-")
oClass = stockclass(1)
oClass = Right(oClass, Len(oClass)-1)
If InStr(oClass, " ") > 0 Then
oClass = Left(oClass, InStr(oClass, " ")-1)
End If
If Not UCase(Left(oClass, 1)) = "M" Then
oClass = oClass & """"
If Not InStr(iProperties.Value(oPart, "Project", "Part Number"), "UNC") = 0 Then
stand = " UNC"
End If
If Not InStr(iProperties.Value(oPart, "Project", "Part Number"), "UNF") = 0 Then
stand = " UNF"
End If
Else
stand = ""
End If
Catch
End Try
Try
'Use part parameter named "Type", if it exists.
'This can be used as an override for a part which is being wrongly assessed.
AutoType = Parameter(oPart, "Type")
Catch ex As Exception
'Create a list of parameters to check for.
Dim paramstocheck As New ArrayList()
paramstocheck.add("G_NG")
paramstocheck.add("G_T")
paramstocheck.add("G_W")
paramstocheck.add("G_ER")
paramstocheck.add("G_T1")
paramstocheck.add("G_H")
paramstocheck.add("b")
paramstocheck.add("NLG")
paramstocheck.add("SW")
paramstocheck.add("SD2")
paramstocheck.add("SEWI")
paramstocheck.add("KOD")
paramstocheck.add("FAWI")
paramstocheck.add("SD2")
'paramstocheck.add("[NEW PARAMETER TO CHECK]")
'Create a list of parameters found out of those checked.
Dim params As New ArrayList()
For Each param in paramstocheck
'MessageBox.Show("Checking for: " & param, "iLogic")
Try
parametro = Parameter(oPart, param)
params.Add(param)
'MessageBox.Show(param & " = " & parametro, "iLogic")
Catch
'MessageBox.Show(param & " doesn't exist.", "iLogic")
End Try
Next
If params.Contains("G_NG") Then
AutoType = "PFC"
ElseIf (Not params.Contains("G_T1")) And params.Contains("G_W") And (Not params.Contains("G_ER")) And params.Contains("G_T") Then
AutoType = "RHS"
ElseIf params.Contains("G_T") And (Not params.Contains("G_W")) Then
AutoType = "CHS"
ElseIf (Not params.Contains("G_T")) And (Not params.Contains("G_W")) And params.Contains("G_H") Then
AutoType = "RD BAR"
ElseIf params.Contains("G_T1") And (Not params.Contains("G_NG")) Then
AutoType = "UC"
ElseIf params.Contains("G_ER") Or params.Contains("b") Then
AutoType = "RSA"
ElseIf params.Contains("G_W") And (Not params.Contains("G_T")) Then
AutoType = "F BAR"
ElseIf params.Contains("NLG") And params.Contains("SW")And params.Contains("SD2") Then
AutoType = "BOLT"
ElseIf params.Contains("SW") And (Not params.Contains("NLG")) Then
AutoType = "NUT"
ElseIf params.Contains("SD2") And (Not params.Contains("NLG")) Then
AutoType = "WASHER"
ElseIf params.Contains("SEWI") Then
AutoType = "C SINK"
ElseIf params.Contains("KOD") And (Not params.Contains("SEWI")) Then
AutoType = "SOCKET SCREW"
ElseIf params.Contains("FAWI") Then
AutoType = "GRUB"
ElseIf (Not params.Contains("B_L")) Then
AutoType = "PLATE"
Else
'leave blank if no match is found.
AutoType = ""
End If
End Try
'Set Shape Type
If AutoType = "" Then
'Prompt for manual input - in format "PFC", "F BAR", "RD BAR", "UC", etc.
oType = InputBox("Treat as:", "Part Type", AutoType)
Else
'Use automatically calculated type
oType = AutoType
End If
'Create a default description
Select Case UCase(oType)
Case "PLATE"
AutoName = "PLT " & Thickness & " THK " & Length & " x " & Width
Case "F BAR"
AutoName = "F/BAR " & Width & " x " & Thickness
Case "CHS"
Try
AutoName = "CHS " & Parameter(oPart, "G_H") & " OD x " & Parameter(oPart, "G_T") & " WT"
Catch
MessageBox.Show("Error getting parameters", "iLogic")
AutoName = ""
End Try
Case "SHS", "RHS"
Try
'Distinguish between square and rectangular section
If Parameter(oPart, "G_W") = Parameter(oPart, "G_H") Then
AutoName = "SHS " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T")
Else
AutoName = "RHS " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T")
End If
Catch
MessageBox.Show("Error getting parameters as " & oType, "iLogic")
AutoName = ""
End Try
Case "RD BAR"
Try
AutoName = "RD BAR DIA. " & Parameter(oPart, "G_H")
Catch
MessageBox.Show("Error getting parameters as " & oType, "iLogic")
AutoName = ""
End Try
Case "RSA"
Try
AutoName = "RSA " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T")
Catch
Try
AutoName = "RSA " & Parameter(oPart, "b") & " x " & Parameter(oPart, "b") & " x " & Parameter(oPart, "ParT")
Catch
MessageBox.Show("Error getting parameters as " & oType, "iLogic")
AutoName = ""
End Try
End Try
Case "PFC"
Try
AutoName = "PFC " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2)
Catch
MessageBox.Show("Error getting parameters as " & oType, "iLogic")
AutoName = ""
End Try
Case "UC", "UB"
Try
'Distinguish between collumn and beam
If Val(stockprops(0)) <= Val(stockprops(1)) Then
AutoName = "UC " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2)
Else
AutoName = "UB " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2)
End If
Catch
MessageBox.Show("Error getting parameters as " & oType, "iLogic")
AutoName = ""
End Try
Case "BOLT"
Try
AutoName = oClass & stand & " HEX BOLT"
Catch
MessageBox.Show("Error getting parameters as " & oType, "iLogic")
AutoName = ""
End Try
Case "NUT"
Try
AutoName = oClass & stand & " HEX NUT"
Catch
MessageBox.Show("Error getting parameters as " & oType, "iLogic")
AutoName = ""
End Try
Case "WASHER"
Try
AutoName = oClass & " FLAT WASHER, FORM A"
Catch
MessageBox.Show("Error getting parameters as " & oType, "iLogic")
AutoName = ""
End Try
Case "C SINK"
Try
AutoName = oClass & stand & " COUNTERSINK SCREW"
Catch
MessageBox.Show("Error getting parameters as " & oType, "iLogic")
AutoName = ""
End Try
Case "SOCKET SCREW"
Try
AutoName = oClass & stand & " SOCKET SCREW"
Catch
MessageBox.Show("Error getting parameters as " & oType, "iLogic")
AutoName = ""
End Try
Case "GRUB"
Try
AutoName = oClass & stand & " GRUB SCREW"
Catch
MessageBox.Show("Error getting parameters as " & oType, "iLogic")
AutoName = ""
End Try
Case Else
AutoName = ""
End Select
'Show input box with default description
oNewDescription = InputBox("Description for '" & partName & "':", "Description Editor", AutoName)
If oNewDescription = "" Then
'Cancel if no description is entered.
MessageBox.Show("Description change cancelled.", "iLogic")
Else
'Change part description
iProperties.Value(oPart, "Project", "Description") = oNewDescription
InventorVb.DocumentUpdate()
'Restart to choose next part
iLogicVb.RunRule("Dimensions - Individual")
End If
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
ProTip:
Code is generally much, much easier to write, edit and refactor if it is laid out for proper encapsulation, instead of all put under one function..
Seeing that many lines of code put into one function makes my head spin. Especially when trying to figure out what it actually does/how.
Ex:/// When setting autoname fails to set because it has issues finding the parameters, instead of putting the try/catch in EVERY case statement, rewrite it as a function that does the error checking and returns the proper results. Be mindful of whether you want to accomplish this via
1) A Sub (or occasionally a function) using a input/return variable by reference
2) A Sub using global variables
3) A function.
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Haha.
Yeah, it's honestly a miracle that the code isn't in even worse format than it is. I was never taught to code. I just saw other people's iLogic rules and learnt bits and pieces from them.
Also, I didn't really make this rule for others to use. It was actually just for me. I shared it because it's incredibly handy for me and I know other people might benefit from it. I would like for people to be able to easily mould it to their needs, but I really don't have the experience coding. I find a method that works, and stick with it.
I'll definitely keep your tips in mind for future though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Annnnnd here's what it looks like refactored into a slightly more logical layout.
A ton of redundancy and unused lines were also removed.
There might be some bugs to fix yet/some extra error checking to add, but at least it should be much, much easier to follow.
Sub Main()
Dim oDoc As Inventor.Document
oDoc = ThisDoc.Document
oDrawCurveSeg = ThisApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a Drawing Curve")
'Input validation
Dim oDrawCurve As DrawingCurve
Try
oDrawCurve = oDrawCurveSeg.Parent
Catch ex As Exception
MessageBox.Show("No drawing curve found.", "iLogic")
Exit Sub
End Try
Dim oSelectedModelDoc As Document
Try
oSelectedModelDoc = oDrawCurve.ModelGeometry.Parent.ComponentDefinition.Document
Catch
MsgBox("No model assosciated with selected curve found!")
End Try
'End of input validation
'Create a default description
AutoName = AutoDescriptionBasedonType(oSelectedModelDoc)
oPart = System.IO.Path.GetFileName(oSelectedModelDoc.FullFileName)
'Provide final user input to verify name
oNewDescription = InputBox("Description for '" & oPart & "':", "Description Editor", AutoName)
If oNewDescription = "" Then
'Cancel if no description is entered.
MessageBox.Show("Description change cancelled.", "iLogic")
Else
'Change part description
iProperties.Value(oPart, "Project", "Description") = oNewDescription
InventorVb.DocumentUpdate()
'Restart to choose next part
iLogicVb.RunRule("Dimensions - Individual")
End If
End Sub
Sub GetDocDims(oDoc As Document, ByRef Length As String, ByRef Width As String, ByRef Thickness As String)
'Grab range box of each surface body and combine to get the max range box
'Get the overall dims using the rangebox max/min points
'Sort these overall dims from smallest to largest and assign as length width and thickness
Dim oCompDef As ComponentDefinition
oCompDef = oDoc.ComponentDefinition
Dim uom as UnitsOfMeasure = oDoc.UnitsOfMeasure
Dim minp As point
Dim maxp As point
Dim oRB As Box
Try
For Each sb In oCompDef.SurfaceBodies
If oRB Is Nothing Then
oRB = sb.RangeBox.Copy
Else
oRB.Extend(sb.RangeBox.MinPoint)
oRB.Extend(sb.RangeBox.MaxPoint)
End If
Next
minp = oRB.minPoint
maxp = oRB.maxPoint
Catch ex As Exception
MessageBox.Show("Error finding extensions for part: " & partName, "iLogic")
Exit Sub
End Try
'Get part dimensions
dp=0
X = Round(uom.ConvertUnits ((maxP.X - minP.X), "cm", uom.LengthUnits), dp)
Y = Round(uom.ConvertUnits ((maxP.Y - minP.Y), "cm", uom.LengthUnits), dp)
Z = Round(uom.ConvertUnits ((maxP.Z - minP.Z), "cm", uom.LengthUnits), dp)
Dim extents As New ArrayList()
extents.add(X)
extents.add(Y)
extents.add(Z)
extents.Sort()
Thickness = extents(0)
Width = extents(1)
Length = extents(2)
End Sub
Sub GetClassAndStandFromProperty(oPN As String, ByRef oClass as String, ByRef stand As String)
'Get classification for fasteners
Dim stockclass() As String
Try
stockclass = Split(oPN, "-")
oClass = stockclass(1)
oClass = Right(oClass, Len(oClass)-1)
If InStr(oClass, " ") > 0 Then
oClass = Left(oClass, InStr(oClass, " ")-1)
End If
If Not UCase(Left(oClass, 1)) = "M" Then
oClass = oClass & """"
If Not InStr(oPN, "UNC") = 0 Then
stand = " UNC"
End If
If Not InStr(oPN, "UNF") = 0 Then
stand = " UNF"
End If
Else
stand = ""
End If
Catch
End Try
End Sub
Function GetParamTypeFromList() As String
Dim paramstocheck As New ArrayList()
paramstocheck.add("G_NG")
paramstocheck.add("G_T")
paramstocheck.add("G_W")
paramstocheck.add("G_ER")
paramstocheck.add("G_T1")
paramstocheck.add("G_H")
paramstocheck.add("b")
paramstocheck.add("NLG")
paramstocheck.add("SW")
paramstocheck.add("SD2")
paramstocheck.add("SEWI")
paramstocheck.add("KOD")
paramstocheck.add("FAWI")
paramstocheck.add("SD2")
'paramstocheck.add("[NEW PARAMETER TO CHECK]")
'Create a list of parameters found out of those checked.
Dim params As New ArrayList()
For Each param in paramstocheck
'MessageBox.Show("Checking for: " & param, "iLogic")
Try
params.Add(param)
Catch
End Try
Next
If params.Contains("G_NG") Then
AutoType = "PFC"
ElseIf (Not params.Contains("G_T1")) And params.Contains("G_W") And (Not params.Contains("G_ER")) And params.Contains("G_T") Then
AutoType = "RHS"
ElseIf params.Contains("G_T") And (Not params.Contains("G_W")) Then
AutoType = "CHS"
ElseIf (Not params.Contains("G_T")) And (Not params.Contains("G_W")) And params.Contains("G_H") Then
AutoType = "RD BAR"
ElseIf params.Contains("G_T1") And (Not params.Contains("G_NG")) Then
AutoType = "UC"
ElseIf params.Contains("G_ER") Or params.Contains("b") Then
AutoType = "RSA"
ElseIf params.Contains("G_W") And (Not params.Contains("G_T")) Then
AutoType = "F BAR"
ElseIf params.Contains("NLG") And params.Contains("SW")And params.Contains("SD2") Then
AutoType = "BOLT"
ElseIf params.Contains("SW") And (Not params.Contains("NLG")) Then
AutoType = "NUT"
ElseIf params.Contains("SD2") And (Not params.Contains("NLG")) Then
AutoType = "WASHER"
ElseIf params.Contains("SEWI") Then
AutoType = "C SINK"
ElseIf params.Contains("KOD") And (Not params.Contains("SEWI")) Then
AutoType = "SOCKET SCREW"
ElseIf params.Contains("FAWI") Then
AutoType = "GRUB"
ElseIf (Not params.Contains("B_L")) Then
AutoType = "PLATE"
Else
AutoType = ""
End If
Return AutoType
End Function
Function AutoDescriptionBasedonType(oDoc As Document) As String
'To Auto description, we need dims, classification, standard, and stock number values to check against.
'We also need to establish a type (which may or may not already be in the part) to establish what we want
'the Default description To be
'Value Prep
'[
Dim Length, Width, Thickness As String
Call GetDocDims(oDoc, Length, Width, Thickness)
Dim oClass, stand As String
Dim oPN As String
oPN = iProperties.Value(oPart, "Project", "Part Number")
Call GetClassAndStandFromProperty(oPN, oClass, stand)
Dim stockprops() As String
Try
stockprops = Split(iProperties.Value(oPart, "Project", "Stock Number"), "x")
Catch
End Try
']
'Get Type
'[
Try
oType = Parameter(oPart, "Type")
Catch ex As Exception
oType = GetParamTypeFromList()
End Try
'Set Shape Type
If oType = "" Then
'Prompt for manual input - in format "PFC", "F BAR", "RD BAR", "UC", etc.
oType = InputBox("Treat as:", "Part Type", AutoType)
End If
']
AutoName = ""
Try
Select Case UCase(oType)
Case "PLATE"
AutoName = "PLT " & Thickness & " THK " & Length & " x " & Width
Case "F BAR"
AutoName = "F/BAR " & Width & " x " & Thickness
Case "CHS"
AutoName = "CHS " & Parameter(oPart, "G_H") & " OD x " & Parameter(oPart, "G_T") & " WT"
Case "SHS", "RHS"
If Parameter(oPart, "G_W") = Parameter(oPart, "G_H") Then
AutoName = "SHS " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T")
Else
AutoName = "RHS " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T")
End If
Case "RD BAR"
AutoName = "RD BAR DIA. " & Parameter(oPart, "G_H")
Case "RSA"
Try
AutoName = "RSA " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T")
Catch
AutoName = "RSA " & Parameter(oPart, "b") & " x " & Parameter(oPart, "b") & " x " & Parameter(oPart, "ParT")
End Try
Case "PFC"
AutoName = "PFC " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2)
Case "UC", "UB"
'Distinguish between collumn and beam
If Val(stockprops(0)) <= Val(stockprops(1)) Then
AutoName = "UC " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2)
Else
AutoName = "UB " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2)
End If
Case "BOLT"
AutoName = oClass & stand & " HEX BOLT"
Case "NUT"
AutoName = oClass & stand & " HEX NUT"
Case "WASHER"
AutoName = oClass & " FLAT WASHER, FORM A"
Case "C SINK"
AutoName = oClass & stand & " COUNTERSINK SCREW"
Case "SOCKET SCREW"
AutoName = oClass & stand & " SOCKET SCREW"
Case "GRUB"
AutoName = oClass & stand & " GRUB SCREW"
Case Else
AutoName = ""
End Select
Catch
AutoName = ""
End Try
Return AutoName
End Function
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
With how it was written, I definitely had difficulty in understanding why you would go through the trouble of making the whole param array only to check it against itself and apparently establish a type based off of that.
The confusing part is why you didn't just write a simple case/if structure to check the existence of parameters in a part and make a type based off of that.
ie;
Sub Main()
If ParamsExist(oDoc, "G_L", "A_F") = True Then
Type = "Plastic"
Else if ParamsExist(oDoc, "b", "t", "k") = True Then
Type = some custom type
End if
End SUb
Function ParamsExist(oDoc, ByVal ParamArray paramstocheck As String()) As Boolean
For each oParam in paramstocheck
Try
oDoc.Parameters(oParam)
Catch
'Accessing prop failed; it doesn't exist
Return False
Exit Sub
End Try
Next
Return True
End Function
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization
iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread
Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects
Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help
Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Why would you torture yourself sorting my code? XD
Thanks, though. I'll have a thorough look at this hopefully tomorrow. I'm sure I can also learn a lot from seeing what you changed and why.
Regarding the param array, I didn't even know how to use functions as you showed. As I say, I only know what I've observed from other rules I've seen.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
*There must be a better way than re-posting updates in full below all of the other versions. This is getting ridiculous.
Unfortunately, your code did not work.
I fixed the rule, and created a function to check if parameters exist as you suggested. It works great now and, thanks to your changes, even works for changing the description of standard content centre parts, which wasn't possible before.
Module mod1
Public oPart As String
End Module
Sub Main()
Dim oDoc As Inventor.Document
oDoc = ThisDoc.Document
oDrawCurveSeg = ThisApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kDrawingCurveSegmentFilter, "Select a Drawing Curve")
'Input validation
Dim oDrawCurve As DrawingCurve
Try
oDrawCurve = oDrawCurveSeg.Parent
Catch ex As Exception
'leave empty so that esc key cancels rule without pop-up.
'MessageBox.Show("No drawing curve found.", "iLogic")
Exit Sub
End Try
Dim oSelectedModelDoc As Document
Try
oSelectedModelDoc = oDrawCurve.ModelGeometry.Parent.ComponentDefinition.Document
Catch
MsgBox("No model assosciated with selected curve found!")
End Try
'End of input validation
oPart = System.IO.Path.GetFileName(oSelectedModelDoc.FullFileName)
'Create a default description
AutoName = AutoDescriptionBasedonType(oSelectedModelDoc)
'Provide final user input to verify name
oNewDescription = InputBox("Description for '" & oPart & "':", "Description Editor", AutoName)
If oNewDescription = "" Then
'Cancel if no description is entered.
MessageBox.Show("Description change cancelled.", "iLogic")
Else
'Change part description
iProperties.Value(oPart, "Project", "Description") = oNewDescription
InventorVb.DocumentUpdate()
'Restart to choose next part
iLogicVb.RunRule("Auto-Description")
End If
End Sub
Sub GetDocDims(oDoc As Document, ByRef Length As String, ByRef Width As String, ByRef Thickness As String)
'Grab range box of each surface body and combine to get the max range box
'Get the overall dims using the rangebox max/min points
'Sort these overall dims from smallest to largest and assign as length width and thickness
Dim oCompDef As ComponentDefinition
oCompDef = oDoc.ComponentDefinition
Dim uom as UnitsOfMeasure = oDoc.UnitsOfMeasure
Dim minp As point
Dim maxp As point
Dim oRB As Box
Try
For Each sb In oCompDef.SurfaceBodies
If oRB Is Nothing Then
oRB = sb.RangeBox.Copy
Else
oRB.Extend(sb.RangeBox.MinPoint)
oRB.Extend(sb.RangeBox.MaxPoint)
End If
Next
minp = oRB.minPoint
maxp = oRB.maxPoint
Catch ex As Exception
MessageBox.Show("Error finding extensions for part: " & partName, "iLogic")
Exit Sub
End Try
'Get part dimensions
dp=0
X = Round(uom.ConvertUnits ((maxP.X - minP.X), "cm", uom.LengthUnits), dp)
Y = Round(uom.ConvertUnits ((maxP.Y - minP.Y), "cm", uom.LengthUnits), dp)
Z = Round(uom.ConvertUnits ((maxP.Z - minP.Z), "cm", uom.LengthUnits), dp)
Dim extents As New ArrayList()
extents.add(X)
extents.add(Y)
extents.add(Z)
extents.Sort()
Thickness = extents(0)
Width = extents(1)
Length = extents(2)
End Sub
Sub GetClassAndStandFromProperty(oPN As String, ByRef oClass as String, ByRef stand As String)
'Get classification for fasteners
Dim stockclass() As String
Try
stockclass = Split(oPN, "-")
oClass = stockclass(1)
oClass = Right(oClass, Len(oClass)-1)
If InStr(oClass, " ") > 0 Then
oClass = Left(oClass, InStr(oClass, " ")-1)
End If
If Not UCase(Left(oClass, 1)) = "M" Then
oClass = oClass & """"
If Not InStr(oPN, "UNC") = 0 Then
stand = " UNC"
End If
If Not InStr(oPN, "UNF") = 0 Then
stand = " UNF"
End If
Else
stand = ""
End If
Catch
End Try
End Sub
Function GetParamTypeFromList() As String
If ParamsExist(1, "G_NG") Then
AutoType = "PFC"
ElseIf ParamsExist(1, "G_W", "G_T") And ParamsExist(0, "G_T1", "G_ER") Then
AutoType = "RHS"
ElseIf ParamsExist(1, "G_T") And ParamsExist(0, "G_W") Then
AutoType = "CHS"
ElseIf ParamsExist(1, "G_H") And ParamsExist(0, "G_T", "G_W") Then
AutoType = "RD BAR"
ElseIf ParamsExist(1, "G_T1") And ParamsExist(0, "G_NG") Then
AutoType = "UC"
ElseIf ParamsExist(1, "G_ER") Or ParamsExist(1, "b") Then
AutoType = "RSA"
ElseIf ParamsExist(1, "G_W") And ParamsExist(0, "G_T") Then
AutoType = "F BAR"
ElseIf ParamsExist(1, "NLG", "SW", "SD2") Then
AutoType = "BOLT"
ElseIf ParamsExist(1, "SW") And ParamsExist(0, "NLG") Then
AutoType = "NUT"
ElseIf ParamsExist(1, "SD2") And ParamsExist(0, "NLG") Then
AutoType = "WASHER"
ElseIf ParamsExist(1, "SEWI") Then
AutoType = "C SINK"
ElseIf ParamsExist(1, "KOD") And ParamsExist(0, "SEWI") Then
AutoType = "SOCKET SCREW"
ElseIf ParamsExist(1, "FAWI") Then
AutoType = "GRUB"
ElseIf ParamsExist(0, "B_L") Then
AutoType = "PLATE"
Else
AutoType = ""
End If
Return AutoType
End Function
Function ParamsExist(checkType As Integer, ByVal ParamArray paramstocheck As String()) As Boolean
For Each oParam in paramstocheck
'MessageBox.Show("Checking for: " & oParam, "iLogic")
Try
testparamexists = Parameter(oPart, oParam)
If checkType = 0 Then
Return False
End If
Catch
If checkType = 1 Then
Return False
End If
End Try
Next
Return True
End Function
Function AutoDescriptionBasedonType(oDoc As Document) As String
'To Auto description, we need dims, classification, standard, and stock number values to check against.
'We also need to establish a type (which may or may not already be in the part) to establish what we want
'the Default description To be
'Value Prep
'[
Dim Length, Width, Thickness As String
Call GetDocDims(oDoc, Length, Width, Thickness)
Dim oClass, stand As String
Dim oPN As String
oPN = iProperties.Value(oPart, "Project", "Part Number")
Call GetClassAndStandFromProperty(oPN, oClass, stand)
Dim stockprops() As String
Try
stockprops = Split(iProperties.Value(oPart, "Project", "Stock Number"), "x")
Catch
End Try
']
'Get Type
'[
Try
oType = Parameter(oPart, "Type")
Catch ex As Exception
oType = GetParamTypeFromList()
End Try
'Set Shape Type
If oType = "" Then
'Prompt for manual input - in format "PFC", "F BAR", "RD BAR", "UC", etc.
oType = InputBox("Treat as:", "Part Type", AutoType)
End If
']
AutoName = ""
Try
Select Case UCase(oType)
Case "PLATE"
AutoName = "PLT " & Thickness & " THK " & Length & " x " & Width
Case "F BAR"
AutoName = "F/BAR " & Width & " x " & Thickness
Case "CHS"
AutoName = "CHS " & Parameter(oPart, "G_H") & " OD x " & Parameter(oPart, "G_T") & " WT"
Case "SHS", "RHS"
If Parameter(oPart, "G_W") = Parameter(oPart, "G_H") Then
AutoName = "SHS " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T")
Else
AutoName = "RHS " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T")
End If
Case "RD BAR"
AutoName = "RD BAR DIA. " & Parameter(oPart, "G_H")
Case "RSA"
Try
AutoName = "RSA " & Parameter(oPart, "G_H") & " x " & Parameter(oPart, "G_W") & " x " & Parameter(oPart, "G_T")
Catch
AutoName = "RSA " & Parameter(oPart, "b") & " x " & Parameter(oPart, "b") & " x " & Parameter(oPart, "ParT")
End Try
Case "PFC"
AutoName = "PFC " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2)
Case "UC", "UB"
'Distinguish between collumn and beam
If Val(stockprops(0)) <= Val(stockprops(1)) Then
AutoName = "UC " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2)
Else
AutoName = "UB " & stockprops(0) & " x " & stockprops(1) & " x " & stockprops(2)
End If
Case "BOLT"
AutoName = oClass & stand & " HEX BOLT"
Case "NUT"
AutoName = oClass & stand & " HEX NUT"
Case "WASHER"
AutoName = oClass & " FLAT WASHER, FORM A"
Case "C SINK"
AutoName = oClass & stand & " COUNTERSINK SCREW"
Case "SOCKET SCREW"
AutoName = oClass & stand & " SHCS"
Case "GRUB"
AutoName = oClass & stand & " GRUB SCREW"
Case Else
AutoName = ""
End Select
Catch
AutoName = ""
End Try
Return AutoName
End Function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
@jmfowler1996 wrote:
... how to use functions ...
Hi jmfowler1996,
Just as an FYI for the future as well, have a look at this AU class:
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks!
I didn't even know that type of thing existed.
I'll have a look into it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear Jonathan,
Thank you for your Ilogic code. we used part templates for normal parts in that way we always have good dimensions which we can export to an idw. In skeleton models its not helpfull though. I was wondering though if there is a way to reset the value's ? when I adjust a length in my skeleton model and rerun the rule the old dimension value's will not change to accommodate the new value's
Do you know an idea to reset your rule?
Kind regards,
Mitchel Stottelaar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi.
Can you please attach an example part which the rule isn't working for? It will give me a better idea of what you are meaning, and I can have a look into why it isn't working.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you for your quick reply!
Below you find the wetransfer link for the assembly.
Kind regards,
Mitchel Stottelaar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello again Mitchel.
Thank you for making the issue very clear in your drawing. It was very useful.
I will address the issues individually:
1:
issue: round bar is called out as plate.
Cause: the iLogic code recognises different types of part by checking a part's parameter names. The parameter names in standard round bar taken from the content centre are very different from the names of the parameters in your custom part.
Solution: instead of extruding round bar, use round bar directly from inventor's content centre. In your case, maybe create a frame sketch part with the sketch lines of the frame members (round bars), and insert it into the assembly. You can then use frame generator to create round bars from the content centre.
Alternative Solution: You could technically also create a list of parameters which are the same as those in a content centre round bar, and the code will then recognize it as such.
2/3:
issue: plates are called out with incorrect dimensions
cause: this happens when the part's User Coordinate System (UCS) is not aligned with the part.
Workaround: there currently isn't a good way around this. You could create parts from scratch for diagonally placed parts. If you need them to be linked to the master assembly, you could link the parameters to the original sketch.
Solution: I have an idea about how to create a better workaround for this, based on the user adding a custom user coordinate system and the rule recognising that the latest UCS is the one to be used. I will add it to my long list of things to do!
*:
issue: when part dimensions are changed and the rule is re-run, the dimensions given by the rule are outdated.
my comments: I couldn't reproduce this issue. Please see the screencast below where I change the sketch and the rule runs with the correct updated dimensions.
ee1abc63-2fe2-4eb7-a442-cb5cc3341721
If you mean that you want the sizes in the BoM to update without running the rule again, I will look into it, but I don't think it will be easy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Okay, it looks like that screencast link didn't work.
The screencast is here:
https://knowledge.autodesk.com/community/screencast/ee1abc63-2fe2-4eb7-a442-cb5cc3341721
And I will try one last time to embed it in the comment...