Error in iLogic Code (The parameter is incorrect)

Error in iLogic Code (The parameter is incorrect)

Anonymous
Not applicable
626 Views
5 Replies
Message 1 of 6

Error in iLogic Code (The parameter is incorrect)

Anonymous
Not applicable

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 Likes
627 Views
5 Replies
Replies (5)
Message 2 of 6

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Can you please provide non confidential assembly file to reproduce the error?

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 6

Anonymous
Not applicable

Hi,

 

I attached the assembly file.

 

Thanks.

 

0 Likes
Message 4 of 6

Anonymous
Not applicable

Here are the part files.

0 Likes
Message 5 of 6

Maxim-CADman77
Advisor
Advisor

Not Solved yet?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 6 of 6

J-Camper
Advisor
Advisor

First thing to note, when working in an Assembly all geometry in occurrences needs to be accessed as a Proxy.  Second there are some command limitations in an assembly sketch, so I had to go more directly @ the face edges rather than all cut edges.  This does mean it is just a cross section of the face you pick and not all planar entities.  I'm not sure if that was the goal or not, but this was working for me in the files you attached:

'Preliminary Setup
App = ThisApplication
doc = ThisDoc.Document
oCD = doc.ComponentDefinition
oBodies = oCD.SurfaceBodies
oCommandMgr = App.CommandManager
Dim oFace As FaceProxy

'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
'Can't use this in an assembly:   'oCommandMgr.ControlDefinitions("SketchProjectCutEdgesCmd").Execute
For Each oEdge In oFace.Edges
	oSK.AddByProjectingEntity(oEdge)
Next
For Each oEntity In oSK.SketchEntities
	Try
		oEntity.Construction = False
	Catch
		'Can't be turned into non-construction
	End Try
Next
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(oFace.ContainingOccurrence.Name))'Need material of native face object:   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

The only other thing i changed was i pulled the material from the occurrence of the selected face since assemblies don't have a material.

 

Please let me know if your intentions were different and I can try to help more.

0 Likes