from win32com.client import Dispatch, gencache
# -----------------------------------------------------------------------------
# inventor v2021
# -----------------------------------------------------------------------------
import inventorApiV21
from inventorApiV21 import constants as in_const_
ThisApplication = Dispatch('Inventor.Application')
AppInvType = inventorApiV21.Application(ThisApplication)
objCollect = ThisApplication.TransientObjects.CreateObjectCollection()
# objCollect = inventorApiV21.ObjectCollection(objCollect)
oDrawDoc = ThisApplication.ActiveDocument
oDrawDoc = inventorApiV21.DrawingDocument(oDrawDoc)
oActiveSheet = oDrawDoc.ActiveSheet
oSketch = ThisApplication.ActiveEditObject
oTG = ThisApplication.TransientGeometry
# геометрия -----------------------------------------------------------------------------
line1 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(4.1, 8.2), oTG.CreatePoint2d(10.9, 21.8))
objCollect.Add(line1)
line2 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(9.1, 21.8), oTG.CreatePoint2d(15.9, 8.2))
objCollect.Add(line2)
line3 = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(17, 10), oTG.CreatePoint2d(3, 10))
objCollect.Add(line3)
addcg1 = oSketch.GeometricConstraints.AddGround(line1)
addcg2 = oSketch.GeometricConstraints.AddGround(line2)
addcg3 = oSketch.GeometricConstraints.AddGround(line3)
oPoint1 = oSketch.SketchPoints.Add(oTG.CreatePoint2d(0, 10), True)
oSketch.GeometricConstraints.AddCoincident(line1, oPoint1)
oSketch.GeometricConstraints.AddCoincident(line2, oPoint1)
objCollect.Add(oPoint1)
oPoint2 = oSketch.SketchPoints.Add(oTG.CreatePoint2d(0, 10), True)
oSketch.GeometricConstraints.AddCoincident(line2, oPoint2)
oSketch.GeometricConstraints.AddCoincident(line3, oPoint2)
objCollect.Add(oPoint2)
oPoint3 = oSketch.SketchPoints.Add(oTG.CreatePoint2d(0, 10), True)
oSketch.GeometricConstraints.AddCoincident(line1, oPoint3)
oSketch.GeometricConstraints.AddCoincident(line3, oPoint3)
objCollect.Add(oPoint3)
addcg1.Delete()
addcg2.Delete()
addcg3.Delete()
# -----------------------------------------------------------------------------
oProfile = oSketch.Profiles.AddForSolid(False, objCollect)
oHatchPattern = oDrawDoc.DrawingHatchPatternsManager.Item("ANSI 31")
oHatchRegion = oSketch.SketchHatchRegions.Add(oProfile, oHatchPattern)
print("done")