Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error in iLogic Code (The parameter is incorrect...)

0 REPLIES 0
Reply
Message 1 of 1
NMillerJZMK8
365 Views, 0 Replies

Error in iLogic Code (The parameter is incorrect...)

Hi,

 

I have some code that calculates cross-sectional area and area moments of inertia for a part file. Now I am trying to use the same code in an assembly file, and I am getting the following error:

 

     The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

What does this error mean? From what I've read on the forums, it seems there can be several different issues that cause this. What can I do to fix my code? I have posted my code below. I have commented out some of my code, so I can focus on getting the basics first.

 

Thanks.

 

-------------------------------------------------------------------------------------------------------------------------------

 

iLogic 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
MessageBox.Show("For Dies Connected by Thermal Struts: Choose Either of the Dies to Calculate Properties for the Entire Assembly. Ensure Thermal Struts are Deleted or Suppressed.", "iLogic Message", MessageBoxButtons.OK)
jmpFaceSelection : oFace = oCommandMgr.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Select Planar Face to Calculate 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 dividing by 6.452 converts from cm^2 to in^2
' 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 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report