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

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

Anonymous
Not applicable
998 Views
4 Replies
Message 1 of 5

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

Anonymous
Not applicable

Good morning everyone. I have experienced strange issue with inventor. Previously I've prepared code in order to prepare element with length scale in millimeters (to create numbers automatically). Everything was working fine. I've made already two parts in this way. However trying to make a third one I'm experiencing this error message: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)). Please see code below:

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oSketch As PlanarSketch
oSketch = oDoc.ComponentDefinition.Sketches.Item(9)

Dim sText As String
Dim oInsertPoint As Point2d
Dim oTextBox As TextBox

For i=0 To 20
	sText=i * 10
	oInsertPoint=ThisApplication.TransientGeometry.CreatePoint2d(i,1)
	oTextBox = oSketch.TextBoxes.AddFitted(oInsertPoint, sText)
	oTextBox.Style.HorizontalJustification = kAlignTextCenter
Next

Does anyone have idea what's wrong?

 

Thanks in Advance for your help!
 

0 Likes
999 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

My initial thought is that there is a data type mismatch going on.  You defined the variable 'sText' to represent a String data type, then you were setting Integer type data as its Value, then are trying to use it as a String in the AddFitted method.  You can 'include or integrate' Integers & Doubles into a String, when done properly though.  Then since the data type of the variable 'i' had not been defined, it was trying to be used both in a mathematical scenario, and in a String scenario.  Sometimes you just have to be more clear about the intended data type of variables, and try not to mix & match them without using any data type conversion tools.

I slightly tweaked your code in a couple places that should help with this situation.  See if this works better for you.

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oSketch As PlanarSketch = oDoc.ComponentDefinition.Sketches.Item(9)
Dim sText As String
Dim oInsertPoint As Point2d
Dim oTextBox As TextBox
For i As Integer = 0 To 20
	sText = (i * 10).ToString
	oInsertPoint = ThisApplication.TransientGeometry.CreatePoint2d(i,1)
	oTextBox = oSketch.TextBoxes.AddFitted(oInsertPoint, sText)
	oTextBox.Style.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
Next

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡 or you can Explore My CONTRIBUTIONS

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks for your idea, but unfortunately it didn't work ☹️. Definitely I'm not iLogic expert but what is strange for me is the fact that my formula was working with previous parts, but not in this one. Actually when I'm tying to create any new part the same error is coming. 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

If you are trying to use this code on a 'new' part, that new part most likely won't already contain 9 sketches, because this code is trying to get the 9th sketch that was added to this part document.  In a new part, you likely don't have any sketches in it yet, so you may need to create a new sketch, instead of find a specific existing one.  You can also get a sketch by its name, instead of by its Index number, if one already exists with a set name.  Does this make sense to you?  Do you need the code changed to either find a specific sketch by its name, or do you need the code changed to just create a new sketch to work with.  If creating a new sketch, we must specify in the code what work plane or planar part face to create the sketch on.  Or if searching for an existing sketch by name, we would need to specify that name in the code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

Anonymous
Not applicable

Well, of course I was defining new sketches every time I was trying to make it on a new part. In this case it was Sketch 9, in other parts it was 4, 5, etc. I've been already trying to change name of the sketch to "SCALE" and it didn't work either. 

0 Likes