The error message is correct in the ilogic editor you can use ilogic or vb.net code. Any code that has a sub or function will likely be vb.net and will need sub main and end sub to start and finish the rule. ThisApplication was also missing as _invapplication refers to an addin or missing section of code. There is also a file path that needs to be changed to suit the part being worked on. “C:\Users\t_makaf\OneDrive - Autodesk\Desktop\sheet.ipt"
@randy.redekop Your code supplied has no sub/function routine so can be used as is.
Sub Main()
‘Insert code here
End Sub
I have corrected what I could see in the below code but have not tested this.
Sub Main()
'Sets inventor application
_InvApplication = ThisApplication
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = _InvApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,
_InvApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject))
' Create a new B size sheet.
Dim oSheet As Sheet
oSheet = oDrawingDoc.Sheets.Add(DrawingSheetSizeEnum.kBDrawingSheetSize)
' Add the default border.
oSheet.AddDefaultBorder()
' Open the block document, invisibly.
Dim oPartDoc As PartDocument
oPartDoc = _InvApplication.Documents.Open("C:\Users\t_makaf\OneDrive - Autodesk\Desktop\sheet.ipt", False)
Dim oTG As TransientGeometry
oTG = _InvApplication.TransientGeometry
' Create the base view.
Dim oBaseView As DrawingView
oBaseView = oDrawingDoc.ActiveSheet.DrawingViews.AddBaseView(oPartDoc, oTG.CreatePoint2d(35, 20), 1,
ViewOrientationTypeEnum.kFrontViewOrientation,
DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)
Dim oDrawing As DrawingDocument
oDrawing = _InvApplication.ActiveDocument
Dim oView As DrawingView
oView = oDrawing.ActiveSheet.DrawingViews(1)
Dim oDimColl As GeneralDimensionsEnumerator
oDimColl = oDrawing.ActiveSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView)
''dimensioning
Dim oSelectedCurve As DrawingCurve = Nothing
For Each oCurve As DrawingCurve In oBaseView.DrawingCurves
' Skip Circles
If Not oCurve.StartPoint Is Nothing And Not oCurve.EndPoint Is Nothing Then
If (WithinTol(oCurve.StartPoint.X, oCurve.EndPoint.X, 0.001)) Then
If oSelectedCurve Is Nothing Then
' This is the first horizontal curve found.
oSelectedCurve = oCurve
Else
' Check to see if this curve is higher (smaller x value) than the current selected
If oCurve.MidPoint.X < oSelectedCurve.MidPoint.X Then
oSelectedCurve = oCurve
End If
End If
End If
End If
Next
If oSelectedCurve Is Nothing Then
MessageBox.Show("no curve selected!")
Exit Sub
End If
' Create geometry intents point for the curve.
Dim oGeomIntent1 As GeometryIntent = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kStartPointIntent)
Dim oGeomIntent2 As GeometryIntent = oSheet.CreateGeometryIntent(oSelectedCurve, PointIntentEnum.kEndPointIntent)
Dim oGeneralDimensions = oSheet.DrawingDimensions.GeneralDimensions
Dim oDimPos As Point2d = oTG.CreatePoint2d(oSelectedCurve.MidPoint.X - 2, oSelectedCurve.MidPoint.Y)
' Create the dimension.
Dim oLinearDim As LinearGeneralDimension
oLinearDim = oGeneralDimensions.AddLinear(oDimPos, oGeomIntent1, oGeomIntent2, DimensionTypeEnum.kAlignedDimensionType)
Private Function WithinTol(ByVal Value1 As Double, ByVal Value2 As Double, ByVal tol As Double) As Boolean
Return (Math.Abs(Value1 - Value2) < tol)
End Function
End Sub
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan