- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I am working on a drawing (.idw) for an assembly. The drawing contains multiple sheets. Each sheet contains multiple views, which are generated from view representations of the assembly. Each view shows off a unique part that is used in the assembly. The parts are simple, continuous solids with several flat surfaces (no holes, no interior geometry, etc.). All the parts are similar, but not identical. I would like to implement an iLogic rule that can achieve the following.
For each view on the sheet...
1. Create a new sketch (sketch needs to be associated with the view)
2. Project all the edges of the part
3. Create a closed profile from the collection of projected edges
4. Apply a hatch pattern to the closed profile
I have written a rule that, so far, achieves steps 1 and 2 but not steps 3 and 4. Here is my code:
'Definitions Dim oApp As Application Dim oDD As DrawingDocument Dim oSht As Sheet Dim oDV As DrawingView Dim oDS As DrawingSketch Dim oDC As DrawingCurve Dim oDCS As DrawingCurveSegment oApp = ThisApplication oDD = oApp.ActiveDocument oSht = oDD.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 oDS = oDV.Sketches.Add 'Project all edges of the part shown in the view For Each oDC In oDV.DrawingCurves oDS.AddByProjectingEntity(oDC) Next 'Create a closed profile from the collection of projected edges 'Apply a hatch pattern to the closed profile Next
I have included 2 screen shots with my post:
"OriginalViewsOnSheet.jpg" - Shows the sheet before running the rule
"HatchedViewsOnSheet.jpg" - Shows the sheet after running the rule (what I want the rule to do)
Any help would be much appreciated.
Thanks,
jpepper
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I found a solution to my problem. My code works now, but it doesn't apply a hatch. Instead, it applies a Solid fill. Inventor 2019 API does not support to application of a hatch pattern to a profile, only a solid fill. Apparently this feature is coming to Inventor 2021.
See the attached images.
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