the conversion of string to type integer is not valid

the conversion of string to type integer is not valid

Anonymous
Not applicable
2,675 Views
6 Replies
Message 1 of 7

the conversion of string to type integer is not valid

Anonymous
Not applicable

Dear everyone,

 

I  am trying to run a code to make a drawing of a model.

when I add a string which contains the template I want to use it gives me this error that it can not convert the string to a type integer.
since I  am a beginner in ilogic an the api, I do not understand what this error means and how to resolve it.

this is the information the error comes with: 

System.InvalidCastException: De conversie van tekenreeks P:\2_ENGINEERING\PROJ-2020\P20-0 naar type Integer is ongeldig. ---> System.FormatException: Input string was not in a correct format.
at Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat)
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
--- End of inner exception stack trace ---
at Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value)
at ThisRule.CreateDrawing(Application& m_inventorApp)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

this is the code I am trying to run:

 	Sub Main
	CreateDrawing(ThisApplication)
End Sub


Public Sub CreateDrawing(ByRef m_inventorApp As Inventor.Application)



	' Create a new drawing document using the default template.

	Dim oDrawDoc As DrawingDocument 

	oDrawDoc = m_inventorApp.Documents.Add("P:\2_ENGINEERING\PROJ-2020\P20-050-SFTOM\02_Support frame Lennart\2-ENG\2-DWG\1-INV\3-LEARNING\API leren\Template\PPV Standaart Template 2019.idw", DocumentTypeEnum.kDrawingDocumentObject, m_inventorApp.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject))



	Dim oSheet As Sheet

	oSheet = oDrawDoc.ActiveSheet



	' Open the part to be inserted into the drawing.

	Dim oPartDoc As PartDocument
	
	oPartDoc = m_inventorApp.Documents.Open("P:\2_ENGINEERING\PROJ-2020\P20-050-SFTOM\02_Support frame Lennart\2-ENG\2-DWG\1-INV\3-LEARNING\API leren\intro naar api\IntroCube.ipt", False) 
	
	Dim oTG As TransientGeometry

	oTG = m_inventorApp.TransientGeometry

 

	MsgBox("Create base and orthographic views.")



	' Place the base front view.

	Dim oFrontView As DrawingView

	oFrontView = oSheet.DrawingViews.AddBaseView( _
	oPartDoc, _
	oTG.CreatePoint2d(30, 15), _
	3, _
	ViewOrientationTypeEnum.kFrontViewOrientation, _
	DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)



	' Create the top, right and iso views.

	Dim oTopView As DrawingView
	oTopView = oSheet.DrawingViews.AddProjectedView( _
	oFrontView, _
	oTG.CreatePoint2d(30, 40), _
	DrawingViewStyleEnum.kFromBaseDrawingViewStyle)



	Dim oIsoView As DrawingView

	oIsoView = oSheet.DrawingViews.AddProjectedView( _
	oFrontView, _
	oTG.CreatePoint2d(75, 40), _
	DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle)



	MsgBox("Create detail view.")



	' Create the detail view.
	'De eerste  x-y coördinaat plaatst het aanzicht van de detail view.
	'De twee coördinaten daarna plaatsen het venster over de baseview waar een detail van getekend wordt. 

	Dim oDetailView As DetailDrawingView

	oDetailView = oSheet.DrawingViews.AddDetailView( _
	oFrontView, _
	oTG.CreatePoint2d(20, 20), _
	DrawingViewStyleEnum.kFromBaseDrawingViewStyle, _
	False, _
	oTG.CreatePoint2d(33, 17.5), _
	oTG.CreatePoint2d(38, 22.5), , 4, , "A")
	
MsgBox("Create dimensions to the curves in the view.")

' Get the various edges of the model.

	Dim aoEdges(0 To 😎 As Edge

	Dim i As Integer

	For i = 0 To 8

		oObjs = oPartDoc.AttributeManager.FindObjects( _
		"Name", "Name", "Edge" & i)

		aoEdges(i) = oObjs.Item(1)

	Next



	' Get the equivalent drawing curves in the base view.
	
	Dim aoDrawCurves(0 To 😎 As DrawingCurve

	For i = 0 To 4

		oDrawViewCurves = oFrontView.DrawingCurves(aoEdges(i))

		aoDrawCurves(i) = oDrawViewCurves.Item(1)

	Next

	' Create some dimensions in the base view

	Dim oGeneralDims As GeneralDimensions

	oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions



	Dim oDim As GeneralDimension



	oDim = oGeneralDims.AddLinear( _
	oTG.CreatePoint2d(32, 15), _
	oSheet.CreateGeometryIntent(aoDrawCurves(1)), _
	oSheet.CreateGeometryIntent(aoDrawCurves(3)), _
	DimensionTypeEnum.kVerticalDimensionType)


	oDim = oGeneralDims.AddRadius( _
	oTG.CreatePoint2d(38, 30), _
	oSheet.CreateGeometryIntent(aoDrawCurves(4)))



	oDim = oGeneralDims.AddDiameter( _
	oTG.CreatePoint2d(27, 18), _
	oSheet.CreateGeometryIntent(aoDrawCurves(2)), _
	True, False)
	
	

'get the equivalent edges for the top view
	For i = 5 To 8

		oDrawViewCurves = oTopView.DrawingCurves(aoEdges(i))

		aoDrawCurves(i) = oDrawViewCurves.Item(1)

	Next
	
' Create the dimensions



	oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions




	oDim = oGeneralDims.AddLinear( _
	oTG.CreatePoint2d(38, 38), _
	oSheet.CreateGeometryIntent(aoDrawCurves(5)), _
	oSheet.CreateGeometryIntent(aoDrawCurves(6)), _
	DimensionTypeEnum.kVerticalDimensionType)
	
	oDim = oGeneralDims.AddLinear( _
	oTG.CreatePoint2d(32, 45), _
	oSheet.CreateGeometryIntent(aoDrawCurves(7)), _
	oSheet.CreateGeometryIntent(aoDrawCurves(8)), _
	DimensionTypeEnum.kHorizontalDimensionType)



	MsgBox("Create a text box with a leader.")




	' Place a text box with a leader.

	Dim oObjColl As ObjectCollection

	oObjColl = m_inventorApp.TransientObjects.CreateObjectCollection

	Call oObjColl.Add(oTG.CreatePoint2d(17.5, 11))

	Dim oEval As Curve2dEvaluator

	oEval = aoDrawCurves(0).Evaluator2D

	Dim adParams(0) As Double

	adParams(0) = 0.6

	Dim adPoints(0 To 1) As Double

	Call oEval.GetPointAtParam(adParams, adPoints)



	Call oObjColl.Add(oTG.CreatePoint2d(adPoints(0), adPoints(1)))

	Dim oLeaderNote As LeaderNote

	oLeaderNote = oSheet.DrawingNotes.LeaderNotes.Add( _
	oObjColl, "Text with a leader")

	oLeaderNote.DimensionStyle = oLeaderNote.DimensionStyle

	

End Sub

Can someone please explain to me what is happening and how i can resolve it?
Thank you in Advance,

 

Lennart

 

0 Likes
Accepted solutions (1)
2,676 Views
6 Replies
Replies (6)
Message 2 of 7

JhoelForshav
Mentor
Mentor
Accepted solution

@Anonymous 

The arguments for Documents.Add are:

Documents.Add(DocumentType As DocumentTypeEnum, Optional TemplateFileName As String, Optional CreateVisible As Boolean)

 

You have these mixed up in your code, with a string value as the first argument that should be DocumentTypeEnum (=Integer). Try changing the line for creating the document to this:

oDrawDoc = m_inventorApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, _
"P:\2_ENGINEERING\PROJ-2020\P20-050-SFTOM\02_Support frame Lennart\2-ENG\2-DWG\1-INV\3-LEARNING\API leren\Template\PPV Standaart Template 2019.idw", _
True)
0 Likes
Message 3 of 7

Anonymous
Not applicable

Thank you once again @JhoelForshav,

 

I keep running into these basic issues. 
Do you have a recommendation were I can learn this type of stuff?

 

Kind regards,

 

Lennart

0 Likes
Message 4 of 7

JhoelForshav
Mentor
Mentor

@Anonymous 

The API reference manual is a good place to find information:

https://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-66A32241-D9C0-4E9D-B6D1-F4A9DA1F69F9

Also, if you write the functions in iLogic the intellisense should kick in:

intellisense.PNG

Message 5 of 7

WCrihfield
Mentor
Mentor

I saw a couple of other issues within that code too.

There were a couple of places where you were initializing a specific sized array.  And in those definitions you specified a start Integer for the array, but not the second (end) Integer for the array's size, before specifying its object type.

Here are the two snippets I have corrected within your first posted code:

 

 

 

'<<<<<<<<<<<   !!!   I ADDED THE 8 AND THE CLOSING ")" SYMBOL   !!!   >>>>>>>>>>>>>
	Dim aoEdges(0 To 8 ) As Edge
	Dim i As Integer
	For i = 0 To 8
		oObjs = oPartDoc.AttributeManager.FindObjects("Name", "Name", "Edge" & i)
		aoEdges(i) = oObjs.Item(1)
	Next

 

 

 

Then there was this instance:

 

 

 

	'<<<<<<<<<<<   !!!   I ADDED THE 4 AND THE CLOSING ")" SYMBOL   !!!   >>>>>>>>>>>>>
	Dim aoDrawCurves(0 To 4) As DrawingCurve
	For i = 0 To 4
		oDrawViewCurves = oFrontView.DrawingCurves(aoEdges(i))
		aoDrawCurves(i) = oDrawViewCurves.Item(1)
	Next

 

 

 

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

Something weird is happening.  I tried correcting my last post twice, and both times, it was correct when I posted, but after it posted, it changed the character "8" into either Nothing or the Imoji (smiling face with sunglasses) character.  Very annoying.  I had to put a space between the "8" and the ")" characters to keep it from being transformed into the Imoji.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 7

Anonymous
Not applicable

thank you @WCrihfield !
it seems that some things went missing after i copied my code. Its in there

0 Likes