Change drawing section hatch layer according to material

Change drawing section hatch layer according to material

oliver.tilbury
Advocate Advocate
6,566 Views
21 Replies
Message 1 of 22

Change drawing section hatch layer according to material

oliver.tilbury
Advocate
Advocate

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
6,567 Views
21 Replies
Replies (21)
Message 21 of 22

J-Camper
Advisor
Advisor

@oliver.tilbury,

I honestly don't know of good/proper uses for assembly model edits other then maybe showing finished cuts while leaving parts with scribe material.  I don't use them in my typical workflow, i just started playing around with them a while ago and found out they were causing issues with my code. 

I would always use the drawing section tools for drawing views.  Even for partial section views like you mentioned, i would do a combination of section cut and projected view to get a cutaway view for the drawing. Like this:

JCamper_0-1734106690957.png

 

Also, the assembly cuts still might be the reason you are missing things with the code I sent.  If you have an assembly cut feature the affected bodies will always return as assembly level result bodies, even if the assembly cut is suppressed.

0 Likes
Message 22 of 22

J-Camper
Advisor
Advisor

@oliver.tilbury,

The "On Error Resume Next" action is something don't like because if one line fails it will then just move on to the next line regardless, which could turn into compounding/cascading errors or hidden bugs because a line fails early in a process without you knowing. 

 

In general the only time I use "On Error ..." actions is when i'm working with transactions, so i can make sure i don't leave any uncommitted transactions if code fails for some reason.  In these cases i prefer to do the "On Error GoTo <named line for error handling>" action, like you used earlier in the code, where I log an error and abort the transaction.

0 Likes