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: 

Change drawing section hatch layer according to material

7 REPLIES 7
Reply
Message 1 of 8
oliver.tilbury
594 Views, 7 Replies

Change drawing section hatch layer according to material

oliver.tilbury
Enthusiast
Enthusiast

Hi all,

 

I'd like to know if it is possible with iLogic or VBA code to automate the process of changing the layer for hatches on 2D drawing section views according to their material.

 

I found this forum discussion here but this talks about changing the view geometry lines and hidden lines according to material:

https://forums.autodesk.com/t5/inventor-programming-ilogic/assign-layers-to-materials/td-p/2871324

 

Whereas all I want to do is in effect select the hatch region and change it’s layer to the appropriate material layer.

We use many different materials and our company standard (in AutoCAD which I am trying to replicate as closely as possible in Inventor!) is to have a different hatch colour (layer) per material.

 

At the moment in Inventor I have the hatch styles set-up as I want in the Style and Standards Editor > Material Hatch Pattern Defaults tab so the correct hatch styles are used per material when taking section views. That’s working great!

 

I also have the layers set-up as I want. For example:

Layer Name / Colour:

'MDF' / Green

'Steel' / Blue

‘Solid Timber’ / Brown

 

My current process is to manually select each hatch region of a given material (E.G. all the hatch regions for MDF) and under the Annotate tab > Format > Layer drop down change the layer to the ‘MDF’ layer.

 

It would be a beautiful thing if this could be automated at the click of a button to do the above, either by:

  1. Selected view
  2. All views on a sheet
  3. Or all views on all sheets.

Even option 1. - just by one selected view at a time - would be amazing!

 

This would only apply to hatch regions that are ‘By Material’.

I.e. so if a hatch region in the Edit Hatch Pattern dialog (that you get when you double click / Right click a hatch region > Edit) has a check mark next to 'By Material' and the material is ‘MDF’, then the code will run to change the layer on which that hatch region resides to the MDF layer.

 

Hatch regions that are not 'By Material' would be ignored.

 

I guess the code would need to be edited to map the correct material to the correct layer.

 

If a layer does not exist for a material I think a pop up message would be best to say that that hatch region layer had not been changed and to prompt the user to make the appropriate layer (and necessary mapping addition to the code) and then run it again to mop-up that remaining hatch region and put it on the appropriate layer. Or I guess it could automatically create a new layer and have a pop up message alerting to the effect. Maybe that would be better actually! 

 

Really hoping this might be possible!

 

Many thanks in advance and kind regards,

 

Oliver

0 Likes

Change drawing section hatch layer according to material

Hi all,

 

I'd like to know if it is possible with iLogic or VBA code to automate the process of changing the layer for hatches on 2D drawing section views according to their material.

 

I found this forum discussion here but this talks about changing the view geometry lines and hidden lines according to material:

https://forums.autodesk.com/t5/inventor-programming-ilogic/assign-layers-to-materials/td-p/2871324

 

Whereas all I want to do is in effect select the hatch region and change it’s layer to the appropriate material layer.

We use many different materials and our company standard (in AutoCAD which I am trying to replicate as closely as possible in Inventor!) is to have a different hatch colour (layer) per material.

 

At the moment in Inventor I have the hatch styles set-up as I want in the Style and Standards Editor > Material Hatch Pattern Defaults tab so the correct hatch styles are used per material when taking section views. That’s working great!

 

I also have the layers set-up as I want. For example:

Layer Name / Colour:

'MDF' / Green

'Steel' / Blue

‘Solid Timber’ / Brown

 

My current process is to manually select each hatch region of a given material (E.G. all the hatch regions for MDF) and under the Annotate tab > Format > Layer drop down change the layer to the ‘MDF’ layer.

 

It would be a beautiful thing if this could be automated at the click of a button to do the above, either by:

  1. Selected view
  2. All views on a sheet
  3. Or all views on all sheets.

Even option 1. - just by one selected view at a time - would be amazing!

 

This would only apply to hatch regions that are ‘By Material’.

I.e. so if a hatch region in the Edit Hatch Pattern dialog (that you get when you double click / Right click a hatch region > Edit) has a check mark next to 'By Material' and the material is ‘MDF’, then the code will run to change the layer on which that hatch region resides to the MDF layer.

 

Hatch regions that are not 'By Material' would be ignored.

 

I guess the code would need to be edited to map the correct material to the correct layer.

 

If a layer does not exist for a material I think a pop up message would be best to say that that hatch region layer had not been changed and to prompt the user to make the appropriate layer (and necessary mapping addition to the code) and then run it again to mop-up that remaining hatch region and put it on the appropriate layer. Or I guess it could automatically create a new layer and have a pop up message alerting to the effect. Maybe that would be better actually! 

 

Really hoping this might be possible!

 

Many thanks in advance and kind regards,

 

Oliver

Labels (6)
7 REPLIES 7
Message 2 of 8

oliver.tilbury
Enthusiast
Enthusiast

Or if anybody knows if hatch selection can be called with iLogic or VBA code that would be a start. 🤔 😄

0 Likes

Or if anybody knows if hatch selection can be called with iLogic or VBA code that would be a start. 🤔 😄

Message 3 of 8
WCrihfield
in reply to: oliver.tilbury

WCrihfield
Mentor
Mentor

Hi @oliver.tilbury.  This might be possible to make happen by code, but I have never attempted it before, so I do not have any example code for you to try at the moment.  How it is done may depend on what version/year of Inventor you have too.  I can point out a few things that may help though.  I have not tried the code below, but you can play around with it, and see if it is going in the right direction.  It is not complete yet.  Just something to maybe get you started towards where you want to go, and some ideas.

Sub Main
	Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then Return
	Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a drawing view.")
	If oView Is Nothing Then Return
	Dim oDVHRs As DrawingViewHatchRegions = oView.HatchRegions
	If oDVHRs.Count = 0 Then Return
	For Each oDVHR As DrawingViewHatchRegion In oDVHRs
		If oDVHR.ByMaterial = True Then
			Dim sMaterialName As String = ""
			'maybe find out which material the model is currently set to here
			Dim oViewDoc As Inventor.Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
			If TypeOf oViewDoc Is PartDocument Then
				Dim oPDoc As PartDocument = oViewDoc
				sMaterialName = oPDoc.ActiveMaterial.DisplayName
				'now get the Layer you want to use for this Material, one way or another
				Dim oMyLayer As Inventor.Layer = Nothing
				'probably need to have a NameValueMap or Dictionary (2 factor lists)
				'where material name and layer name are in pairs
				'then iterate through those, checking agains this material name, to get the layer name
				Try
					oMyLayer = oDDoc.StylesManager.Layers.Item("MyLayerName")
				Catch
					oMyLayer = oDDoc.StylesManager.Layers.Item(1).Copy("MyLayerName")
					'set the properties of this new layer now, before using it
				End Try
				'set the Layer of this hatch region in the view
				oDVHR.Layer = oMyLayer
			End If 'end of document type check (nothing if assembly)
		End If 'end of ByMaterial check
	Next 'oDVHR
	oView.Parent.Update
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

Hi @oliver.tilbury.  This might be possible to make happen by code, but I have never attempted it before, so I do not have any example code for you to try at the moment.  How it is done may depend on what version/year of Inventor you have too.  I can point out a few things that may help though.  I have not tried the code below, but you can play around with it, and see if it is going in the right direction.  It is not complete yet.  Just something to maybe get you started towards where you want to go, and some ideas.

Sub Main
	Dim oDDoc As DrawingDocument = TryCast(ThisDoc.Document, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then Return
	Dim oView As DrawingView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a drawing view.")
	If oView Is Nothing Then Return
	Dim oDVHRs As DrawingViewHatchRegions = oView.HatchRegions
	If oDVHRs.Count = 0 Then Return
	For Each oDVHR As DrawingViewHatchRegion In oDVHRs
		If oDVHR.ByMaterial = True Then
			Dim sMaterialName As String = ""
			'maybe find out which material the model is currently set to here
			Dim oViewDoc As Inventor.Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
			If TypeOf oViewDoc Is PartDocument Then
				Dim oPDoc As PartDocument = oViewDoc
				sMaterialName = oPDoc.ActiveMaterial.DisplayName
				'now get the Layer you want to use for this Material, one way or another
				Dim oMyLayer As Inventor.Layer = Nothing
				'probably need to have a NameValueMap or Dictionary (2 factor lists)
				'where material name and layer name are in pairs
				'then iterate through those, checking agains this material name, to get the layer name
				Try
					oMyLayer = oDDoc.StylesManager.Layers.Item("MyLayerName")
				Catch
					oMyLayer = oDDoc.StylesManager.Layers.Item(1).Copy("MyLayerName")
					'set the properties of this new layer now, before using it
				End Try
				'set the Layer of this hatch region in the view
				oDVHR.Layer = oMyLayer
			End If 'end of document type check (nothing if assembly)
		End If 'end of ByMaterial check
	Next 'oDVHR
	oView.Parent.Update
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 8
J-Camper
in reply to: oliver.tilbury

J-Camper
Advisor
Advisor

@oliver.tilbury,

I've been working on an add-in to allow solidbody level material assignments in Multi-solidbody parts, and some of the framework I have would be similar to what I think you need/want.  I took a couple things from that and added what would be needed to assign layers, as I was not changing layers.  See the Attached txt file. 

 

It currently has the user select the layer from a list to be assigned to each hatch region, by material.  You could write some mapping logic for your expected Materials and layers to automate that step.  I also have not included any clean up of un-mapped materials/Layers.

 

Let me know if you have any questions/issues.

0 Likes

@oliver.tilbury,

I've been working on an add-in to allow solidbody level material assignments in Multi-solidbody parts, and some of the framework I have would be similar to what I think you need/want.  I took a couple things from that and added what would be needed to assign layers, as I was not changing layers.  See the Attached txt file. 

 

It currently has the user select the layer from a list to be assigned to each hatch region, by material.  You could write some mapping logic for your expected Materials and layers to automate that step.  I also have not included any clean up of un-mapped materials/Layers.

 

Let me know if you have any questions/issues.

Message 5 of 8
oliver.tilbury
in reply to: WCrihfield

oliver.tilbury
Enthusiast
Enthusiast

Hi Wesley,

 

Thanks very much for this.

 

Massively encouraging and exciting that there may be a way!

 

It was the end of the day here when I got your message and as it's now the weekend I won't be able to look at this properly until next week.

 

I can answer one of your questions though... I'm using Inventor Profesional 2024, latest release (can check the exact release number on Monday).

 

Thanks again!

 

Oliver

0 Likes

Hi Wesley,

 

Thanks very much for this.

 

Massively encouraging and exciting that there may be a way!

 

It was the end of the day here when I got your message and as it's now the weekend I won't be able to look at this properly until next week.

 

I can answer one of your questions though... I'm using Inventor Profesional 2024, latest release (can check the exact release number on Monday).

 

Thanks again!

 

Oliver

Message 6 of 8
oliver.tilbury
in reply to: J-Camper

oliver.tilbury
Enthusiast
Enthusiast

Thank you very much for this @J-Camper.

 

Again, I'll take a proper look at this next week when back to work. 

 

Out of interest and as an aside: the add-in you've been working on - is that to assign different materials to different solid bodies in a multi body part? I believe that is not possible with Inventor out the box? 

I know Solidworks has this functionality. 

I work in bespoke furniture and that would be extremely handy to know more about / if there is some rabbit out of a hat to make this work! 

 

Thanks again for the reply and your code re. the material hatches. Will look at it all properly next week.

 

Oliver

 

 

0 Likes

Thank you very much for this @J-Camper.

 

Again, I'll take a proper look at this next week when back to work. 

 

Out of interest and as an aside: the add-in you've been working on - is that to assign different materials to different solid bodies in a multi body part? I believe that is not possible with Inventor out the box? 

I know Solidworks has this functionality. 

I work in bespoke furniture and that would be extremely handy to know more about / if there is some rabbit out of a hat to make this work! 

 

Thanks again for the reply and your code re. the material hatches. Will look at it all properly next week.

 

Oliver

 

 

Message 7 of 8
J-Camper
in reply to: oliver.tilbury

J-Camper
Advisor
Advisor

@oliver.tilbury,

 

That's right, solidbody level materials are not a thing out of the box for Inventor.  I have wanted this functionality for a while, and started thinking of a way to implement it when Autodesk exposed HatchRegions to the API.  I work in a similar field, custom residential millwork/casework, so most of the overrides are to get a MDF/glass field panel in a solid wood door frame. 

I made get & set extension methods for a solidbody level attribute for the overridden material.  As far as Inventor knows, the solidbodies just have an attribute but this is enough for my team to store/get the information we need for shop drawings.  Currently I have these functions working:

  • Assign material to select solidbodies in a part
  • Calculate the mass of a part with respect to any overridden solidbody materials
  • Add/update material leaders to all hatch regions in select drawingviews
  • Override hatch patterns as needed in drawings
    • This one does require mapping hatch patterns to each material needed in the styles manager

I haven't built any functionality to interact from the assembly level, but they do work with ModelStates in parts.

0 Likes

@oliver.tilbury,

 

That's right, solidbody level materials are not a thing out of the box for Inventor.  I have wanted this functionality for a while, and started thinking of a way to implement it when Autodesk exposed HatchRegions to the API.  I work in a similar field, custom residential millwork/casework, so most of the overrides are to get a MDF/glass field panel in a solid wood door frame. 

I made get & set extension methods for a solidbody level attribute for the overridden material.  As far as Inventor knows, the solidbodies just have an attribute but this is enough for my team to store/get the information we need for shop drawings.  Currently I have these functions working:

  • Assign material to select solidbodies in a part
  • Calculate the mass of a part with respect to any overridden solidbody materials
  • Add/update material leaders to all hatch regions in select drawingviews
  • Override hatch patterns as needed in drawings
    • This one does require mapping hatch patterns to each material needed in the styles manager

I haven't built any functionality to interact from the assembly level, but they do work with ModelStates in parts.

Message 8 of 8

oliver.tilbury
Enthusiast
Enthusiast

Hi @J-Camper , @WCrihfield,

 

I just wanted to message to say I have not forgotten about this thread!

 

I have been very busy over the last few weeks on getting a project completed to 'showcase' Inventor to my colleagues so have not had a chance to give proper time to working out this 'change hatch layer according to material' dilemma. 

 

I tried the above codes very quickly shortly after you sent them but to be totally honest I don't know what I'm doing so have little ability to adapt and develop the code to get it to do what I want.

 

I'm trying to watch YouTube videos to help learn iLogic and am dabbling with code snippets I'm finding online to achieve simpler tasks but who knows when I'll be able to just write code form my fingertips. That's the dream! 

 

Anyway - thanks again and hopefully I can look at this again soon(ish!),

 

Oliver

0 Likes

Hi @J-Camper , @WCrihfield,

 

I just wanted to message to say I have not forgotten about this thread!

 

I have been very busy over the last few weeks on getting a project completed to 'showcase' Inventor to my colleagues so have not had a chance to give proper time to working out this 'change hatch layer according to material' dilemma. 

 

I tried the above codes very quickly shortly after you sent them but to be totally honest I don't know what I'm doing so have little ability to adapt and develop the code to get it to do what I want.

 

I'm trying to watch YouTube videos to help learn iLogic and am dabbling with code snippets I'm finding online to achieve simpler tasks but who knows when I'll be able to just write code form my fingertips. That's the dream! 

 

Anyway - thanks again and hopefully I can look at this again soon(ish!),

 

Oliver

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

Post to forums  

Autodesk Design & Make Report