iLogic – Question About Multiple User Inputs

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I wrote iLogic code for a part file that takes user input and calculates cross-sectional area, moment of inertia values (Ix and Iy), and calculates the weight per foot.
My question is about the user input. Currently, my code allows the user to select only one surface to calculate the area, moments of inertia, and weight. Is there a way in iLogic to allow the user to select multiple surfaces? And is there a way to ask the user up front if they want to select one or more than one surface?
I've posted my code below. It's somewhat long, but I wanted to give an idea of what my code currently looks like.
Thanks.
My Code:
'Preliminary Setup
App = ThisApplication
doc = ThisDoc.Document
oCD = doc.ComponentDefinition
oBodies = oCD.SurfaceBodies
oCommandMgr = App.CommandManager
Dim oFace As Face
'1: Check for Bodies
If oBodies.Count = 0 Then
MessageBox.Show("Part File Must Contain a Body!", "iLogic Error Alert:", MessageBoxButtons.OK)
Exit Sub
End If
'2: Check for Planar Faces
blnPlanarFaceCheck = False
For Each oSurfaceBody As SurfaceBody In oBodies
For Each oFace In oSurfaceBody.Faces
If oFace.SurfaceType = SurfaceTypeEnum.kPlaneSurface Then
blnPlanarFaceCheck = True
GoTo jmpFaceCheck
End If
Next
Next
jmpFaceCheck : If blnPlanarFaceCheck = False Then
MessageBox.Show("There Must Be a Flat Face for Selection!", "iLogic Error Alert:", MessageBoxButtons.OK)
Exit Sub
End If
'3: Check To See If Sketch Is Defined In XY Plane
Dim oSketch As PlanarSketch
oSketch = ThisDoc.Document.ComponentDefinition.Sketches.Item(1)
If oSketch.PlanarEntity.Name <> "XY Plane" Then
MessageBox.Show("The Sketch Must Be Defined on the XY Plane!", "iLogic Error Alert:", MessageBoxButtons.OK)
Exit Sub
End If
'4: Check To See If Material Is Specified
If ThisDoc.Document.ComponentDefinition.Material.Name = "Generic" Then
MessageBox.Show("The Part Has No Material Assigned!", "iLogic Error Alert:", MessageBoxButtons.OK)
Exit Sub
End If
'5: Select Face and Check
jmpFaceSelection : oFace = oCommandMgr.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select planar face to calculate area, Ix, and Iy properties")
If oFace.Type <> ObjectTypeEnum.kFaceObject Then
MessageBox.Show("A Surface Face Must Be Selected!", "iLogic Error Alert:", MessageBoxButtons.OK)
GoTo jmpFaceSelection
End If
'Calculate Area, Ix, and Iy
oTransaction = App.TransactionManager.StartTransaction(doc, "Inertia Calculation")
App.ScreenUpdating = False
oSK = oCD.Sketches.Add(oFace)
oSK.Edit
oCommandMgr.ControlDefinitions("SketchProjectCutEdgesCmd").Execute
oProfile = oSK.Profiles.AddForSolid
oRegProps = oProfile.RegionProperties
dArea = oRegProps.Area
Dim adPrincipalMoments(2) As Double
oRegProps.PrincipalMomentsofInertia(adPrincipalMoments(0), adPrincipalMoments(1), adPrincipalMoments(2))
oSK.ExitEdit
App.ScreenUpdating = True
oTransaction.Abort
'Copy Values to Custom iProperties
iProperties.Value("Custom", "Area") = Format(dArea / 6.452, ".000") 'dividing by 6.452 converts from cm^2 to in^2
iProperties.Value("Custom", "Ix") = Format(adPrincipalMoments(0) / 41.623, ".000") 'dividing by 41.623 converts from cm^4 to in^4
iProperties.Value("Custom", "Iy") = Format(adPrincipalMoments(1) / 41.623, ".000") 'dividing by 41.623 converts from cm^4 to in^4
iProperties.Value("Custom", "Mass") = Format(iProperties.Mass, ".000")
'Additional Custom iProperties
iProperties.Value("Custom", "Material") = Format(iProperties.Material)
iProperties.Value("Custom", "Drawn By") = Format(UCase(iProperties.Value("Summary","Author")))
'6: Check Length of Part
If Round(iProperties.Volume / (dArea/6.452)) <> 12 Then 'dividing by 6.452 converts from cm^2 to in^2
MessageBox.Show("The Part Has Not Been Extruded To a Depth Of 12 Inches!", "iLogic Error Alert:", MessageBoxButtons.OK)
Exit Sub
End If
'If There Are No Errors, Message Box Appears. Runs Through All Previous Checks Before Displaying Message Box.
If oBodies.Count = 1 And '1
blnPlanarFaceCheck = True And '2
oSketch.PlanarEntity.Name = "XY Plane" And '3
ThisDoc.Document.ComponentDefinition.Material.Name <> "Generic" And '4
oFace.Type = ObjectTypeEnum.kFaceObject And '5
Round(iProperties.Volume / (dArea/6.452)) = 12 Then '6
MessageBox.Show("Calculations Made. No Errors Found.", "iLogic Message", MessageBoxButtons.OK)
Exit Sub
End If
'Update the Document That the Rule Is Running In
InventorVb.DocumentUpdate