Anonymous
in reply to:
Anonymous
05-08-2020
06:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
05-08-2020
06:53 AM
I solved my own problem. The code works as well as it can, for the time being. Unfortunately, Inventor 2019 API currently does not support the application of a hatch pattern to a sketch profile. It only allows for a solid fill to be applied. However, I recently learned that hatching a sketch profile via iLogic was available on the now-closed beta build of Inventor 2021, which mean in future, this code can be improved to apply a real hatch pattern, not a solid fill.
Working code:
'Definitions Dim oDoc As DrawingDocument Dim oSht As Sheet Dim oDV As DrawingView Dim oSketch As DrawingSketch Dim oDC As DrawingCurve 'Set a reference to the active document. This assumes it is a drawing document. oDoc = ThisApplication.ActiveDocument 'Set a reference to the active sheet. oSht = oDoc.ActiveSheet 'Loop through all views that currently exist on the active sheet For Each oDV In oSht.DrawingViews 'Create a new sketch on the active view oSketch = oDV.Sketches.Add 'Put the sketch in edit mode oSketch.Edit 'Set a reference to the transient geometry object Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry 'Project all edges of the part shown in the view For Each oDC In oDV.DrawingCurves oSketch.AddByProjectingEntity(oDC) Next 'Create a profile from the projected edges Dim oProfile1 As Profile oProfile1 = oSketch.Profiles.AddForSolid(False, oCollection1) 'Fill the profile with a SOLID pattern Call oSketch.SketchFillRegions.Add(oProfile1) ''Fill the profile with a HATCH pattern (available only in Inventor 2021) 'Call oSketch.SketchHatchRegions.Add(oProfile1) 'Exit the sketch oSketch.ExitEdit Next