
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.