iLogic – Question About Multiple User Inputs

iLogic – Question About Multiple User Inputs

Anonymous
Not applicable
349 Views
2 Replies
Message 1 of 3

iLogic – Question About Multiple User Inputs

Anonymous
Not applicable

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

0 Likes
350 Views
2 Replies
Replies (2)
Message 2 of 3

JamieVJohnson2
Collaborator
Collaborator

Well, you can go through the entire select events sample in Interacting with the User in the API help to do things properly.  You can also just pop up a message box that says select everything then press ok.  The message box stops code processing, the user selects items, then when finished they press ok, the code then goes to the selection set in the active document and retrieved the user selected items.  I wrote this once:

    Public Function GetSelected(Optional ByVal checkType As System.Type = Nothing) As List(Of Object)
        GetInventorApplication()
        Dim invEnts As New List(Of Object)
        Dim booChecktype As Boolean = False
        If checkType IsNot Nothing Then booChecktype = True
        Dim invDoc As Inventor.Document = invApp.ActiveDocument
        If invDoc IsNot Nothing AndAlso invDoc.SelectSet.Count > 0 Then
            For Each obj As Object In invDoc.SelectSet()
                If booChecktype AndAlso checkType IsNot Nothing Then
                    If obj.GetType Is checkType Then
                        invEnts.Add(obj)
                    End If
                Else
                    invEnts.Add(obj)
                End If
            Next
        Else
            MsgBox("Select entities first")
        End If
        Return invEnts
    End Function
Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 3 of 3

Anonymous
Not applicable

Thanks for your help. I'll have to try your code and see how it works.

0 Likes