Message 1 of 4

Not applicable
06-04-2021
08:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Programming novice here trying to create his second macro. I keep getting a run-time error 91 when I test my code. I've been reading online in every forum I can find to try and figure out what I am doing wrong but can't figure it out. I know it is happening at this line approximately 2/3 of the way down:
Set inputPoints(inputPointCount) = selectedObj
I have debugged everything except for this one line. Can anyone help?
I've attached my part I created specifically to test. For reference I am using Inventor 2022, build 153, release 2022.0.1
Sub ExportWorkPointsV2()
'How to use: create your axes in this order: 1st sraight section, 1st bend, 2nd straight, 2nd bend... until final straight section.
'Create a workpoint for the start point and end point. Select all axes and the 2 points, run the macro. Macro will create points at
'each intersection of axis, place them in order, create a UCS using points 1-3, offset the points by the UCS, measure the distance
'of the bend axis to a straight axis, save that as a radius, export the XYZ and R of each point to an excel sheet.
Dim ready As Long
ready = 1
If ready = 0 Then
MsgBox "This macro is not ready yet"
Exit Sub
End If
Dim partDoc As PartDocument
Dim partCompDef As PartComponentDefinition
If ThisApplication.ActiveDocumentType = kPartDocumentObject Then
Set partDoc = ThisApplication.ActiveDocument
Dim partDef As PartComponentDefinition
Set partDef = partDoc.ComponentDefinition
Else
MsgBox "A part must be active"
Exit Sub
End If
Dim points() As WorkPoint
Dim inputPoints As WorkPoint
Dim axes() As WorkAxis
Dim axisCount As Long
axisCount = 0
Dim inputPointCount As Long
inputPointCount = 0
If partDoc.SelectSet.Count > 0 Then
ReDim axes(partDoc.SelectSet.Count - 1)
' ReDim inputPoints(partDoc.SelectSet.Count - 1)
MsgBox "Number of selected objects: " & Format(partDoc.SelectSet.Count, "0")
Dim selectedObj As Object
For Each selectedObj In partDoc.SelectSet
' MsgBox "Type of object is: " & TypeName(selectedObj)
If TypeOf selectedObj Is WorkAxis Then
Set axes(axisCount) = selectedObj
axisCount = axisCount + 1
'MsgBox "Axis found, axisCount = " & Format(axisCount, "0")
End If
If TypeOf selectedObj Is WorkPoint Then
' MsgBox "Type of object is: " & TypeName(selectedObj)
inputPointCount = inputPointCount + 1
MsgBox "Input point found, inputPointCount = " & Format(inputPointCount, "0")
End If
Next
' ReDim Preserve axes(axisCount - 1)
Else
MsgBox "Nothing selected. Please select all of your axes, your start point, and your end point, then try again"
Exit Sub
End If
MsgBox "Number of axes: " & Format(axisCount, "0") & " number of points: " & Format(inputPointCount, "0")
Dim rad As Double
rad = ThisApplication.MeasureTools.GetMinimumDistance(axes(0), axes(1)) / 2.54
MsgBox "Radius of 1st bend is: " & Format(rad, "0.000") & " in"
' getminimumdistance(axes(0),axes(1))
' Set points(0) = WorkPoint.SetByTwoPoints(axes(0), axes(2))
End Sub
Solved! Go to Solution.