Message 1 of 4
Creating a 3D geometric conincident constraint in a 3D Sketch via VBA (testing)

Not applicable
08-26-2020
09:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Created a 3D sketch and would like to constrain the end point of the line to another point which is constrained to 2D sketch. We are able to constrain the 3D sketch to the point via the UI, but when attempting to do via code (VBA for testing) we are getting an error.
To be specific, a Run-time error '13': type mismatch.
Dim oCoinConst As Inventor.CoincidentConstraint3D
Set oCoinConst = oSketch3D.GeometricConstraints3D.AddCoincident(oLineA, OriginPoint)
oLineA is a Sketch3D entity
OriginPoint is a Point
Module code:
Public Sub Create3DSketch(name As String, mp As ObjectCollection) ' mp() As WorkPoint)
Dim oCompDef As PartComponentDefinition
Set oCompDef = myPartDoc.ComponentDefinition
'Dim oSketch3D As Sketch3D (global variable)
Set oSketch3D = oCompDef.Sketches3D.Add
' Name the newly created 3d sketch
oSketch3D.name = UCSSkName
Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry
Dim oOriginSP As SketchPoint3D
''set oOriginSP =
Set oOriginSP = oSketch3D.SketchPoints3D.Add(OriginPoint, False)
''Call oOriginSP.ConnectTo(OriginPoint)
'' https://forums.autodesk.com/t5/inventor-customization/constraining-a-sketch-point-to-the-origin-using-vba/td-p/2387173
Dim oLineA As SketchLine3D
Dim oLineXaxis As SketchLine3D
Dim oLineYaxis As SketchLine3D
Set oLineA = oSketch3D.SketchLines3D.AddByTwoPoints(oOriginSP, mp.Item(2))
Set oLineXaxis = oSketch3D.SketchLines3D.AddByTwoPoints(oLineA.EndSketchPoint, mp.Item(3), False)
Set oLineYaxis = oSketch3D.SketchLines3D.AddByTwoPoints(oLineA.EndSketchPoint, mp.Item(4), False)
' Constrain oLineA to the z-axis
Dim oParallalZ As ParallelToZAxisConstraint3D
Set oParallalZ = oSketch3D.GeometricConstraints3D.AddParallelToZAxis(oLineA)
' Constrain oLineXaxis to the x-axis
Dim oParallelX As ParallelToXAxisConstraint3D
Set oParallelX = oSketch3D.GeometricConstraints3D.AddParallelToXAxis(oLineXaxis)
' Constrain oLineYaxis to the y-axis
Dim oParallelY As ParallelToYAxisConstraint3D
Set oParallelY = oSketch3D.GeometricConstraints3D.AddParallelToYAxis(oLineYaxis)
oLineA.Construction = True
oLineXaxis.Construction = True
oLineYaxis.Construction = True
Dim oLineLenConstr3D As LineLengthDimConstraint3D
Set oLineLenConstr3D = oSketch3D.DimensionConstraints3D.AddLineLength(oLineA)
' oLineLenConstr3D.Driven = False
' Dim oModelParam As UserParameter
' Set oModelParam = oLineLenConstr3D.Parameter
' Constrain mp(0) with OriginPoint
Dim oCoinConst As Inventor.CoincidentConstraint3D
Set oCoinConst = oSketch3D.GeometricConstraints3D.AddCoincident(oLineA, OriginPoint)
End Sub
Will eventually tie the 3D sketch z elevation to a user parameter, but first things first.
Thanks for reading.