- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Creating a 3D geometric conincident constraint in a 3D Sketch via VBA (testing)
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Doing some digging in the API help document and come to find out that trying to place the a conincident constraint between two points will fail, and it states that we should use the ConnectTo method on the sketchpoint3d object to merge two points.
'SketchPoint3D.ConnectTo( ConstrainingPoint As Object )
Call oLineA.StartPoint.ConnectTo(OriginPoint)
Trying that approach, but now we're getting an error dialog.
Keep, keeping on.
I'll figure it out eventually. ![]()
M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
this works for me. (it assumes that there are 2x 2d sketches with at least 1 line in them)
Dim doc As PartDocument = ThisDoc.Document Dim def = doc.ComponentDefinition Dim sketch1 As Sketch = def.Sketches.Item(1) Dim sketch2 As Sketch = def.Sketches.Item(2) Dim line1 = sketch1.SketchLines.Item(1) Dim line2 = sketch2.SketchLines.Item(1) Dim sketch3d As Sketch3D = def.Sketches3D.Add() Dim p1 = line1.StartSketchPoint Dim p2 = line2.StartSketchPoint sketch3d.SketchLines3D.AddByTwoPoints(p1, p2) ' or the log way Dim p3 = ThisApplication.TransientGeometry.CreatePoint(1, 1, 1) Dim p4 = ThisApplication.TransientGeometry.CreatePoint(2, 2, 2) Dim line As SketchLine3D = sketch3d.SketchLines3D.AddByTwoPoints(p3, p4) line.StartSketchPoint.ConnectTo(line1.EndSketchPoint) line.EndSketchPoint.ConnectTo(line2.EndSketchPoint)
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
No joy.
Works via iLogic, but not via VBA. ![]()
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)
'SketchPoint3D.ConnectTo( ConstrainingPoint As Object )
Call oLineA.StartSketchPoint.ConnectTo(OriginPoint)
Getting the error on the last line above.