Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Hatch Regions

8 REPLIES 8
Reply
Message 1 of 9
J-Camper
471 Views, 8 Replies

Hatch Regions

J-Camper
Advisor
Advisor

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?

0 Likes

Hatch Regions

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?

8 REPLIES 8
Message 2 of 9
WCrihfield
in reply to: J-Camper

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes

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

EESignature

(Not an Autodesk Employee)

Message 3 of 9
J-Camper
in reply to: WCrihfield

J-Camper
Advisor
Advisor

@WCrihfield,

 

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

0 Likes

@WCrihfield,

 

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

Message 4 of 9
WCrihfield
in reply to: J-Camper

WCrihfield
Mentor
Mentor

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.

WCrihfield_0-1684170845622.png

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

EESignature

(Not an Autodesk Employee)

0 Likes

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.

WCrihfield_0-1684170845622.png

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

EESignature

(Not an Autodesk Employee)

Message 5 of 9
J-Camper
in reply to: WCrihfield

J-Camper
Advisor
Advisor

@WCrihfield,

 

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:
temp_pic.JPG

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.

0 Likes

@WCrihfield,

 

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:
temp_pic.JPG

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.

Message 6 of 9
J-Camper
in reply to: WCrihfield

J-Camper
Advisor
Advisor

Here is the error I get when running your code on my the drawingview shown in my previous post:
temp_pic.JPG

It's the BoundaryGeometries Property line # 10

0 Likes

Here is the error I get when running your code on my the drawingview shown in my previous post:
temp_pic.JPG

It's the BoundaryGeometries Property line # 10

Message 7 of 9
WCrihfield
in reply to: J-Camper

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes

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

EESignature

(Not an Autodesk Employee)

Message 8 of 9
J-Camper
in reply to: WCrihfield

J-Camper
Advisor
Advisor

I just did another test with extremely surprising results: 

 

  • my initial section view [For elevation, cut from the top view base view of my assembly] expecting 47 regions, or 49 if you include 2 objects that have section participation as none, Inventor returned 50 Regions [nearly what I expect, but not exact.  maybe I turned a hatch off and don't remember? but I don't think I did.]
  • The section view taken from the first view expecting 39 regions cropped, or 41 if the crop was deleted, Inventor returned 80 Regions [possibly adding both sets of regions, as a few regions for my wall, floor, ceiling, trim parts are the same body in both views]
  • The detail view I have shown in a previous post expecting 13 regions, Inventor returned 196 regions.  This one really puzzles me.  I can find no logic for why it should have any more regions than the section it came from...  I can only imagine the reason I'm getting a "HatchRegion" of the side of my cabinet is because the first view I tested does have a separate horizontal section view through that body but that view is not a part of the tree for the detail view; it's a separate branch. 

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: 

 

  • my initial section view [For elevation, cut from the top view base view of my assembly] expecting 47 regions, or 49 if you include 2 objects that have section participation as none, Inventor returned 50 Regions [nearly what I expect, but not exact.  maybe I turned a hatch off and don't remember? but I don't think I did.]
  • The section view taken from the first view expecting 39 regions cropped, or 41 if the crop was deleted, Inventor returned 80 Regions [possibly adding both sets of regions, as a few regions for my wall, floor, ceiling, trim parts are the same body in both views]
  • The detail view I have shown in a previous post expecting 13 regions, Inventor returned 196 regions.  This one really puzzles me.  I can find no logic for why it should have any more regions than the section it came from...  I can only imagine the reason I'm getting a "HatchRegion" of the side of my cabinet is because the first view I tested does have a separate horizontal section view through that body but that view is not a part of the tree for the detail view; it's a separate branch. 

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.

Message 9 of 9
J-Camper
in reply to: WCrihfield

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report