I'm starting to work with DrawingViewHatchRegions, but it seams to be including more than the actual hatch regions. I have a section with a multi solid body part and 2 of the # of bodies have hatch regions, but 5 of the # bodies have drawing curves shown. I would think the Hatch Regions Object would only return the 2 bodies, but it is return the 5 bodies. The only way I can seem to limit my search to actual hatch regions is checking the ObjectCollection returned from the BoundaryGeometries Property. The issue with this is it throws an exception if there is no boundary, instead of just returning an empty collection or nothing.
Anyone have a better idea other than throwing the ObjectCollection check into a try/catch?
I'm starting to work with DrawingViewHatchRegions, but it seams to be including more than the actual hatch regions. I have a section with a multi solid body part and 2 of the # of bodies have hatch regions, but 5 of the # bodies have drawing curves shown. I would think the Hatch Regions Object would only return the 2 bodies, but it is return the 5 bodies. The only way I can seem to limit my search to actual hatch regions is checking the ObjectCollection returned from the BoundaryGeometries Property. The issue with this is it throws an exception if there is no boundary, instead of just returning an empty collection or nothing.
Anyone have a better idea other than throwing the ObjectCollection check into a try/catch?
The last time I looked into these, I saw that it can go multiple layers deep, and got more complicated. The DrawingViewHatchRegion Object then has the HatchAreas property which returns a slightly different type of collection (DrawingViewHatchAreas). Then a single item within that collection is a DrawingViewHatchArea object. Then that has its own BondaryGeometries property. You may have to look into those.
Wesley Crihfield
(Not an Autodesk Employee)
The last time I looked into these, I saw that it can go multiple layers deep, and got more complicated. The DrawingViewHatchRegion Object then has the HatchAreas property which returns a slightly different type of collection (DrawingViewHatchAreas). Then a single item within that collection is a DrawingViewHatchArea object. Then that has its own BondaryGeometries property. You may have to look into those.
Wesley Crihfield
(Not an Autodesk Employee)
It's a similar issue with HatchAreas. Although I can actually cast it to an object variable without an exception; if I check the count, when the HatchRegion Boundaries would throw an exception, it also throws an exception. HatchAreas doesn't return Nothing in this case either, just an exception when you try to get a count, so it seems it would need the same Try/Catch or similar error handling just to determine that it is not an actual hatch region
It's a similar issue with HatchAreas. Although I can actually cast it to an object variable without an exception; if I check the count, when the HatchRegion Boundaries would throw an exception, it also throws an exception. HatchAreas doesn't return Nothing in this case either, just an exception when you try to get a count, so it seems it would need the same Try/Catch or similar error handling just to determine that it is not an actual hatch region
What a pain in the... This sounds like a good point to address with an idea in the Inventor Ideas forum to me. This is obviously unwanted behavior. Are you using the latest version? I don't know if it was fixed in any later versions or updates, but I rather doubt it. I finally got updated to 2024 the other day, so I decided to check this behavior with a quick rule that 'Loggs' its findings. The code ran without any errors, and I got some pretty interesting data.
Here is a screenshot of the only view on the sheet...it is a section view whos 'parent' is on sheet 1, and this is sheet 2.
And here is the iLogic code:
Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
Dim oHRs As DrawingViewHatchRegions = oView.HatchRegions
Logger.Info("About to check oHRs IsNothing & oHRs.Count")
If IsNothing(oHRs) OrElse oHRs.Count = 0 Then Exit Sub
Logger.Info("oHRs.Count = " & oHRs.Count)
For Each oHR As DrawingViewHatchRegion In oHRs
Logger.Info("About to get region boundary geometries to a variable.")
Dim oHRBGs As ObjectCollection = oHR.BoundaryGeometries
Logger.Info("About to check if region boundary geometries Is Nothing or Count = 0.")
If IsNothing(oHRBGs) OrElse oHRBGs.Count = 0 Then
Logger.Info("Region boundary geometries Is Nothing or count = 0")
Else
Logger.Info("Region boundary geometries count = " & oHRBGs.Count)
End If
Logger.Info("About to get region hatch areas to a variable.")
Dim oHAs As DrawingViewHatchAreas = oHR.HatchAreas
Logger.Info("Got region hatch areas to a variable. Now about to check Is Nothing & Count")
If IsNothing(oHAs) OrElse oHAs.Count = 0 Then
Logger.Info("Region Hatch Areas Is Nothing or count = 0")
Continue For
Else
Logger.Info("Region Hatch Areas Count = " & oHAs.Count)
For Each oHA As DrawingViewHatchArea In oHAs
Logger.Info("About to get hatch area boundary geometries to a variable.")
Dim oHABGs As ObjectCollection = oHA.BoundaryGeometries
Logger.Info("Got hatch area boundary geometries to a variable.")
If IsNothing(oHABGs) OrElse oHABGs.Count = 0 Then
Logger.Info("Hatch area boundary geometries IsNothing Or Count = 0")
Else
Logger.Info("Hatch area boundary geometries Count = " & oHABGs.Count)
End If
Next
End If
Next
...and here is the Logger contents:
INFO| 4: >>---------------------------
INFO|About to check oHRs IsNothing & oHRs.Count
INFO|oHRs.Count = 1
INFO|About to get region boundary geometries to a variable.
INFO|About to check if region boundary geometries Is Nothing or Count = 0.
INFO|Region boundary geometries count = 18
INFO|About to get region hatch areas to a variable.
INFO|Got region hatch areas to a variable. Now about to check Is Nothing & Count
INFO|Region Hatch Areas Count = 3
INFO|About to get hatch area boundary geometries to a variable.
INFO|Got hatch area boundary geometries to a variable.
INFO|Hatch area boundary geometries Count = 6
INFO|About to get hatch area boundary geometries to a variable.
INFO|Got hatch area boundary geometries to a variable.
INFO|Hatch area boundary geometries Count = 6
INFO|About to get hatch area boundary geometries to a variable.
INFO|Got hatch area boundary geometries to a variable.
INFO|Hatch area boundary geometries Count = 6
Wesley Crihfield
(Not an Autodesk Employee)
What a pain in the... This sounds like a good point to address with an idea in the Inventor Ideas forum to me. This is obviously unwanted behavior. Are you using the latest version? I don't know if it was fixed in any later versions or updates, but I rather doubt it. I finally got updated to 2024 the other day, so I decided to check this behavior with a quick rule that 'Loggs' its findings. The code ran without any errors, and I got some pretty interesting data.
Here is a screenshot of the only view on the sheet...it is a section view whos 'parent' is on sheet 1, and this is sheet 2.
And here is the iLogic code:
Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)
Dim oHRs As DrawingViewHatchRegions = oView.HatchRegions
Logger.Info("About to check oHRs IsNothing & oHRs.Count")
If IsNothing(oHRs) OrElse oHRs.Count = 0 Then Exit Sub
Logger.Info("oHRs.Count = " & oHRs.Count)
For Each oHR As DrawingViewHatchRegion In oHRs
Logger.Info("About to get region boundary geometries to a variable.")
Dim oHRBGs As ObjectCollection = oHR.BoundaryGeometries
Logger.Info("About to check if region boundary geometries Is Nothing or Count = 0.")
If IsNothing(oHRBGs) OrElse oHRBGs.Count = 0 Then
Logger.Info("Region boundary geometries Is Nothing or count = 0")
Else
Logger.Info("Region boundary geometries count = " & oHRBGs.Count)
End If
Logger.Info("About to get region hatch areas to a variable.")
Dim oHAs As DrawingViewHatchAreas = oHR.HatchAreas
Logger.Info("Got region hatch areas to a variable. Now about to check Is Nothing & Count")
If IsNothing(oHAs) OrElse oHAs.Count = 0 Then
Logger.Info("Region Hatch Areas Is Nothing or count = 0")
Continue For
Else
Logger.Info("Region Hatch Areas Count = " & oHAs.Count)
For Each oHA As DrawingViewHatchArea In oHAs
Logger.Info("About to get hatch area boundary geometries to a variable.")
Dim oHABGs As ObjectCollection = oHA.BoundaryGeometries
Logger.Info("Got hatch area boundary geometries to a variable.")
If IsNothing(oHABGs) OrElse oHABGs.Count = 0 Then
Logger.Info("Hatch area boundary geometries IsNothing Or Count = 0")
Else
Logger.Info("Hatch area boundary geometries Count = " & oHABGs.Count)
End If
Next
End If
Next
...and here is the Logger contents:
INFO| 4: >>---------------------------
INFO|About to check oHRs IsNothing & oHRs.Count
INFO|oHRs.Count = 1
INFO|About to get region boundary geometries to a variable.
INFO|About to check if region boundary geometries Is Nothing or Count = 0.
INFO|Region boundary geometries count = 18
INFO|About to get region hatch areas to a variable.
INFO|Got region hatch areas to a variable. Now about to check Is Nothing & Count
INFO|Region Hatch Areas Count = 3
INFO|About to get hatch area boundary geometries to a variable.
INFO|Got hatch area boundary geometries to a variable.
INFO|Hatch area boundary geometries Count = 6
INFO|About to get hatch area boundary geometries to a variable.
INFO|Got hatch area boundary geometries to a variable.
INFO|Hatch area boundary geometries Count = 6
INFO|About to get hatch area boundary geometries to a variable.
INFO|Got hatch area boundary geometries to a variable.
INFO|Hatch area boundary geometries Count = 6
Wesley Crihfield
(Not an Autodesk Employee)
I'm working in 2023.3 build 359. I only started getting the issues once I was working in an assembly view. Example view which caused issues:
It is a broken detail view of a 2nd level section view, but even the non-broken detail views were causing the same issue. The red line points to the drawing curve of the hatch region I was interested in. The blue line points to a separate solid body in the same part file, representing the side of a cabinet box, which gets processed when looking through HatchRegions for some reason. I didn't expect the blue line body to be a hatch region as it is not sliced in either of the parent section views, so I started to try to filter out these unexpected HatchRegions with the remaining properties under the DrawingViewHatchRegion Object. This filtering is where I started getting the issues with BoundaryGeometries ObjectCollection.
I'm working in 2023.3 build 359. I only started getting the issues once I was working in an assembly view. Example view which caused issues:
It is a broken detail view of a 2nd level section view, but even the non-broken detail views were causing the same issue. The red line points to the drawing curve of the hatch region I was interested in. The blue line points to a separate solid body in the same part file, representing the side of a cabinet box, which gets processed when looking through HatchRegions for some reason. I didn't expect the blue line body to be a hatch region as it is not sliced in either of the parent section views, so I started to try to filter out these unexpected HatchRegions with the remaining properties under the DrawingViewHatchRegion Object. This filtering is where I started getting the issues with BoundaryGeometries ObjectCollection.
Here is the error I get when running your code on my the drawingview shown in my previous post:
It's the BoundaryGeometries Property line # 10
Here is the error I get when running your code on my the drawingview shown in my previous post:
It's the BoundaryGeometries Property line # 10
Wow, your view was far more complex than I had imagined. If simply accessing that built-in property throws an error, then it seems to me that Autodesk should either further develop their code behind property to not throw an error, but instead return Nothing or an empty ObjectCollection; or provide another property like HasBoundaryGeometries which would allow us to avoid that potential error. That just feels like bad API development practice there, but I'm not a software designer by profession, and do not know what challenges may be behind that situation. Definitely worth an idea in the Inventor Ideas forum though. If you create a post there about this, post a link to it here and I will vote for it. Until then, I'm guessing we are going to need to use some Try...Catch blocks for now.
Wesley Crihfield
(Not an Autodesk Employee)
Wow, your view was far more complex than I had imagined. If simply accessing that built-in property throws an error, then it seems to me that Autodesk should either further develop their code behind property to not throw an error, but instead return Nothing or an empty ObjectCollection; or provide another property like HasBoundaryGeometries which would allow us to avoid that potential error. That just feels like bad API development practice there, but I'm not a software designer by profession, and do not know what challenges may be behind that situation. Definitely worth an idea in the Inventor Ideas forum though. If you create a post there about this, post a link to it here and I will vote for it. Until then, I'm guessing we are going to need to use some Try...Catch blocks for now.
Wesley Crihfield
(Not an Autodesk Employee)
I just did another test with extremely surprising results:
Anyways I will add an Idea post if you think that's the best place for this kind of issue. The Try/Catch allows my script to function, I just don't like using it.
I just did another test with extremely surprising results:
Anyways I will add an Idea post if you think that's the best place for this kind of issue. The Try/Catch allows my script to function, I just don't like using it.
Can't find what you're looking for? Ask the community or share your knowledge.