Change hatch by pick

Change hatch by pick

cadman777
Advisor Advisor
1,217 Views
11 Replies
Message 1 of 12

Change hatch by pick

cadman777
Advisor
Advisor

Hey Guys,

Does anyone know if it's possible to change the hatch patterns on a drawing view by picking?
The scenario is like this:

Inventor NEVER puts the hatch angle and scale to 'normal' drafting standards.

So I ALWAYS waste tons of time fixing the views to be presentable.

But it would be much better if I could have a 'button' that I can press and set the hatch angle and scale, then pick on all the hatches I want changed to those settings. Nearly always the only thing I do is make some go 45 deg and the adjacent ones go 135 deg @ the default ANSI 31. Rarely do I use any other settings.

Would be great to have that tool available, so any input is appreciated!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Accepted solutions (1)
1,218 Views
11 Replies
Replies (11)
Message 2 of 12

cadman777
Advisor
Advisor

!BUMP!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 3 of 12

WCrihfield
Mentor
Mentor
Accepted solution

Hi @cadman777.  I doubt this will be possible for you if you are using the 2010 version of Inventor.  That year we got the DrawingView.DisplayHatching property, but the DrawingView.HatchRegions property, which gives us API access to those DrawingViewHatchRegion objects, did not become available until the 2022 version of Inventor.  And the DrawingDocument.DrawingHatchPatternsManager property, that gives us access to the DrawingHatchPatternsManager object, did not become available until the 2021 version of Inventor.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 12

cadman777
Advisor
Advisor

Hi Wesley,

Thanks for this info.

It's SO SAD(!) that these functions are not 'native'.

It's even SADDER(!!) that Autodesk has always FORCED their end-users to DO THEIR WORK for them.

If I did that, I would be 'on the bread line', or worse, in court!

Anyway, I can understand about my 2010 version, but not 2023!

Thanks again....

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 5 of 12

brianM328K
Enthusiast
Enthusiast

Hi Wesley

 

I'm also interested in picking a group of hatches and changing the angle or scale.

Do you know if anyone has written a program to do this kind of thing.

 

I'm running inventor 2024 if that helps.

 

Kind Regards

0 Likes
Message 6 of 12

WCrihfield
Mentor
Mentor

Hi @brianM328K.  Not really.  It is a relatively new area for us to explore by code, as you can see from my response in Message 3 above.  I have not done an extensive search on the topic yet within this forum, but I do not recall that much activity in that area yet.  I do not really have that much work related interest in that area yet either.  I did create an iLogic rule once, just for research purposes into those areas.  I will post that code below, just so you can continue on from there, but it does not attempt to change anything, or access any specific settings, such as angle, just collections and objects, down through the several possible levels.

 

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 oHRs Is Nothing 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 oHRBGs Is Nothing 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 oHAs Is Nothing 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 oHABGs Is Nothing 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

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Edit:  Here are a few more related forum links, but maybe not what you were looking for yet:

https://forums.autodesk.com/t5/inventor-programming-ilogic/accessing-quot-edit-hatch-pattern-quot-in... 

https://forums.autodesk.com/t5/inventor-programming-ilogic/drawing-view-hatch-hided-and-edited/m-p/1... 

https://forums.autodesk.com/t5/inventor-programming-ilogic/hatch-scale/m-p/9797912 

https://forums.autodesk.com/t5/inventor-programming-ilogic/hatch-regions/m-p/11964839 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 12

J-Camper
Advisor
Advisor

I've had issues with the Hatch region property returning non-hatch regions for detail views from section views of assemblies.  I had to check the HatchRegion.BoundaryGeometries, in a Try/Catch, to sift these out.  I have not tried to change the hatch properties either. [this was an issue in 2023.3 build 359, but I have not tried without the Try/Catch since then]

 

The non-iLogic way we have been handling this is to create Hatch styles.  The user can quickly select all the hatches that need to change then go to the drop down and pick with material direction they want:
temp_pic.JPG

 

With a combination of setting custom selection filters to hatch only and these styles, the changes can be very quick.

Message 8 of 12

brianM328K
Enthusiast
Enthusiast

Thank you for your response.

I have been playing around mashing some iLogic rules together today, and have come up with the following code thanks to @WCrihfield .

With this code I can change all the hatch patterns in a selected drawing view.

What I really would like to do is to select a number of independent hatches and change their angle.

If anyone has any ideas on the code to select a number of hatches independently this would be much appreciated.

 

Thanks Brian

 

					'''Checks DWG is active'''
	
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbCritical, "Wrong Document Type")
		Exit Sub
	End If
		
					'''Select a view to adjust'''
	
	Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a View.")
	
	If oView Is Nothing Then
'		oAns = MsgBox("Nothing was selected. Exiting.", vbOKOnly, " ")
		Exit Sub
	End If
	
					'''Select hatches to adjust'''		'''Cant get the code right here'''
	
'	Dim oHR As DrawingViewHatchRegion = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select Hatch.")
'	
'	If oHR Is Nothing Then
'		Exit Sub
'	End If
	
					'''Starts the adjustments'''
	
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	
			If oView.ViewType = DrawingViewTypeEnum.kSectionDrawingViewType Then
				Dim oSecView As SectionDrawingView = oView
				 If oSecView.HatchRegions.Count > 0 Then
	 
	 				'''Select new angle'''
	 
					 oAngle = InputBox("Enter New Hatch Angle", "Adjust Hatch Angle", "")	'Needs an error handeler
					 
					 '''or pick from a list'''
					 
'					 Dim Angle As New List(Of Double)
'							Angle.Add(90)
'							Angle.Add(60)
'							Angle.Add(45)
'							Angle.Add(30)
'							Angle.Add(180) 
'							Angle.Add(-30)
'							Angle.Add(-45)
'							Angle.Add(-60)
'							Angle.Add(-90)
'					Dim oAngle As Double = InputListBox("Select Angle.",Angle)	
					 
					 For Each oHR As DrawingViewHatchRegion In oSecView.HatchRegions		'remove if individual selection works ?

						If oHR.Angle Then oHR.Angle = oAngle
							
					Next																	'remove if individual selection works ?
				End If
			End If
  

 

Message 9 of 12

WCrihfield
Mentor
Mentor

Hi @brianM328K.  I am glad to see that you have something working or you.  I briefly tried to create something that would allow you to manually 'pick' the individual hatch regions, but was not successful either.  Even with the SelectionFilterEnum.AllEntities, it will not allow them to be 'Pick'ed.  I even tried allowing for 'pre-selection' of the hatch, but it would not remain selected when manually running the rule afterwards.  Here is the code I was fooling around with earlier, just for reference, even though it does not work.

Sub Main
	Dim oCM As CommandManager = ThisApplication.CommandManager
	Dim oSS As Inventor.SelectSet = ThisDoc.Document.SelectSet
	Dim oObj As Object
	Dim DVHR As DrawingViewHatchRegion
	RepeatThis :
	oObj = Nothing
	DVHR = Nothing
	oObj = oCM.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Select View Hatch")
	If oObj Is Nothing OrElse (TypeOf oObj Is DrawingViewHatchRegion = False) Then
		If oSS.Count = 0 Then
			Return
		Else
			For Each oEntity In oSS
				Logger.Info(TypeName(oEntity))
				If TypeOf oEntity Is DrawingViewHatchRegion Then
					DVHR = oEntity
					ChangeHatchRegion(DVHR) 'call custom Sub to run on it
				End If
			Next
		End If
	End If
	DVHR = oObj
	ChangeHatchRegion(DVHR) 'call custom Sub to run on it
	If MsgBox("Again?", vbYesNo+vbQuestion, "Again?") = vbYes Then GoTo RepeatThis
End Sub

Sub ChangeHatchRegion(DVHR As DrawingViewHatchRegion)
	Logger.Info("Angle Before Change:  " & DVHR.Angle.ToString)
	DVHR.Angle = (DVHR.Angle * 1.25)
	Logger.Info("Angle After Change:  " & DVHR.Angle.ToString)
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 12

brianM328K
Enthusiast
Enthusiast

Thank you Wesley

 

I will keep trying, at least I have a way to default the hatching its a start.

Trouble is I don't know what commands do what.

I can pick the bones out of others work but couldn't start from scratch.

How did you get started with code?

 

Regards Brian

0 Likes
Message 11 of 12

WCrihfield
Mentor
Mentor

How I got started is probably pretty typical.  I saw that there was a tab for it in Inventor and reviewed some of its help documentation out of curiosity.  Saw a few simple examples of it being used for fairly basic tasks, somewhere (I can't remember where).  The more I saw and read about it, the more interested I got in it, and the more ideas came to mind about all the ways I could take advantage of it.  Due to it being very interesting and exciting for me, I learned about it rapidly, and started creating a bunch of automation tools for work.  After successfully creating a bunch of my own automation rules, and having a little trouble figuring some stuff out once in a while, I naturally began looking into this online forum about that topic.  I also watch pretty much every webinar I see become available on the topic of Inventor automation, from our Autodesk solutions provider, from Autodesk directly, and from other similar entities/organizations.  I already liked helping others out with CAD / CAM related stuff, so I naturally starting to help others out on the forum, when I believed that I could, and had the time.  I really liked it when folks thanked me for helping them, and when they mentioned things like how much time a solution I provided (or helped fix) is going to save them, so I just kept doing it, as time and opportunity permitted.  Probably a fairly common story.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 12 of 12

brianM328K
Enthusiast
Enthusiast

Hello All

@cadman777 I have put together a code that will allow you to do the following.

First it asks you to select a view you would like to edit the hatching in, once you have picked a view the following pops up. (Note: this code will edit all hatches in that view)

 

brianM328K_0-1702286877476.png

brianM328K_1-1702286891064.png

brianM328K_2-1702286919364.png

brianM328K_3-1702286931864.png

I would like to be able to select a group of hatching to edit but am struggling to work that part out. Attached is the code if you want to use it.

I hope this is of help .

 

Sub Note 13/02/2024

I have attached a revised version of the code with enhanced user interface and features. You can now also adjust the hatch pattern.

brianM328K_0-1707836146981.png

 

 

 

 

Regards Brian.