You can group sketch geometry together by creating a SketchBlockDefinition out of them using the “Create Block” command:
If you have SketchBlock‘s (instances of SketchBlockDefinition) in your Sketch then through the UI you can constrain them together without creating any additional geometry in the SketchBlock‘s definition (SketchBlockDefinition) – e.g. using the midpoint of one of the lines of the SketchBlock:

If you try to do the same through the API, Inventor will crash! 😱
You can work around that by creating the constrained SketchPoint inside the SketchBlockDefinition, and use the representation of that point in the Sketch to add further constraints. Each object in the definition will be represented by a sketch object inside the sketch where you placed the SketchBlock. You can find out which object in the sketch is representing a given object from the SketchBlockDefinition by using the SketchBlock.GetObject() function.
FYI: the first SketchPoint in the SketchBlockDefinition is always the insertion point:

If you wanted to constrain two instances of the same SketchBlockDefinition together by the midpoint of their 3rd and 1st line, then this is how you could do it:
Sub ConstrainBlockLine()
Dim oPartDoc As PartDocument
Dim oSketchLine As SketchLine
Dim oMiddlePoint1 As SketchPoint
Dim oMiddlePoint2 As SketchPoint
Dim oTG As TransientGeometry
Dim oSketch As PlanarSketch
Dim oSketchBlock1 As SketchBlock
Dim oSketchBlock2 As SketchBlock
Dim oSketchBlockDef As SketchBlockDefinition
Set oPartDoc = ThisApplication.ActiveDocument
Set oTG = ThisApplication.TransientGeometry
Set oSketch = oPartDoc.ComponentDefinition.Sketches(1)
Set oSketchBlock1 = oSketch.SketchBlocks.Item(1)
Set oSketchBlock2 = oSketch.SketchBlocks.Item(2)
Set oSketchBlockDef = oSketchBlock1.Definition
'edit Sketch
Call oSketch.Edit
'edit SketchBlock
Call oSketchBlock1.Edit
Dim oMiddlePointNative1 As SketchPoint
Set oMiddlePointNative1 = oSketchBlockDef.SketchPoints.Add(oTG.CreatePoint2d(0, 0), False)
Set oSketchLine = oSketchBlockDef.SketchLines(1)
Call oSketchBlockDef.GeometricConstraints.AddMidpoint(oMiddlePointNative1, oSketchLine)
Dim oMiddlePointNative2 As SketchPoint
Set oMiddlePointNative2 = oSketchBlockDef.SketchPoints.Add(oTG.CreatePoint2d(0, 0), False)
Set oSketchLine = oSketchBlockDef.SketchLines(3)
Call oSketchBlockDef.GeometricConstraints.AddMidpoint(oMiddlePointNative2, oSketchLine)
Call oSketchBlock1.ExitEdit(kExitToPrevious)
Set oMiddlePoint1 = oSketchBlock1.GetObject(oMiddlePointNative1)
Set oMiddlePoint2 = oSketchBlock2.GetObject(oMiddlePointNative2)
Call oSketch.GeometricConstraints.AddCoincident(oMiddlePoint1, oMiddlePoint2)
Call oSketch.ExitEdit
End Sub
Result:



Leave a Reply