Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Material-Hatch Mapping

J-Camper
Advisor

Material-Hatch Mapping

J-Camper
Advisor
Advisor

With Hatch Patterns getting API access, has anyone found a way to access this Material/Hatch Pattern Map from the Styles Editor?  I'm working on something, and I want to be able to check the User defined HatchMap, but I'm not sure how to access it.

 

temp_pic.JPG

 

 

Reply
261 Views
4 Replies
Replies (4)

WCrihfield
Mentor
Mentor

Hi @J-Camper.  I do not think those will be found in the 'usual' place (DrawingStylesManager.ActiveStandardStyle...).  I believe those are dictated from the following location:

DrawingDocument.DrawingHatchPatternsManager

DrawingHatchPatternsManager 

...and its properties/methods.

 

Edit:  After closer review, the resource I pointed to does provide a way to access or create a list of hatch patterns, but it does not really seem to provide a way to pair a material with a hatch pattern, so maybe what you are looking for is just not available to the Inventor API yet.

When you go to manually select a hatch pattern from the drop-down list, and choose "Other...", it opens a dialog titled "Select Hatch Pattern", and that dialog has the Load & Export buttons, similar to the DrawingHatchPatternsManager methods available at that link.  May have to ask someone from Autodesk if that is available to access by code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

J-Camper
Advisor
Advisor

I tried those first, but no luck.

 

Right now I'm manually parsing through design data xml files.  I found a section in the "standard.xml" file starting with "<HatchMaterialMap>" and ending with "</HatchMaterialMap>" That looks like the data I'm interested in. 

I might have to try this as the route for now

J-Camper
Advisor
Advisor

@WCrihfield,

 

I was able to put this together:

Private Function BuildHatchMap(StyleName As String) As NameValueMap
	Dim OutputMap As NameValueMap = g_inventorApplication.TransientObjects.CreateNameValueMap()

	Dim DesignDateFolder As String = g_inventorApplication.DesignProjectManager.ActiveDesignProject.DesignDataPath
	Dim StandardXMLFullFileName As String = DesignDateFolder & "standard.xml"
	Dim GenericStyleHeading As String = "Style"
	Dim HatchMapHeading As String = "HatchMaterialMap"
	Dim MaterialAttribute As String = "Material"
	Dim PatternHeading As String = "PatternLine"

	Dim StandardXMLdoc As XDocument = XDocument.Load(StandardXMLFullFileName)


	Dim styleElement As XElement

	For Each s As XElement In StandardXMLdoc.Descendants(GenericStyleHeading)

		If s.Value.Contains(StyleName) Then styleElement = s : Exit For

	Next

	If styleElement.Value Is String.Empty Then Return Nothing

	Dim HatchMapXElement As XElement = styleElement.Descendants(HatchMapHeading)(0)

	If HatchMapXElement.Value Is String.Empty Then Return Nothing

	'Now We need to parse this for Materials

	For Each s As XElement In HatchMapXElement.Elements()

		Dim MaterialName As String = s.Attribute(MaterialAttribute).Value

		Dim PatternLine0 As String = s.Descendants(PatternHeading)(0).Value.Split(",")(0)

		PatternLine0 = Right(PatternLine0, PatternLine0.Length - 1)

		OutputMap.Add(MaterialName, PatternLine0)

	Next

	Return OutputMap
End Function

 

It builds a namevaluemap for the StyleStandard name provided.  I was feeding from Main:

dDoc.StylesManager.ActiveStandardStyle.Name

 

I'm wondering if anyone has a more elegant solution.

 

0 Likes

J-Camper
Advisor
Advisor

Here is an iLogic friendly version for testing:

AddReference "System.Xml"
AddReference "System.Xml.Linq"

Imports System.Xml
Imports System.Xml.Linq

Sub Main
	
	Dim dDoc As DrawingDocument = TryCast(ThisApplication.ActiveDocument, DrawingDocument)
	If IsNothing(dDoc) Then Logger.Debug("Not Run In Drawing Document") : Exit Sub
	
	Dim HatchMap As NameValueMap = BuildHatchMap(dDoc.StylesManager.ActiveStandardStyle.Name)
	If HatchMap Is Nothing Then Exit Sub
		
	MessageBox.Show(HatchMap.Count, "Materials Mapped to Hatches")
	
End Sub

Private Function BuildHatchMap(StyleName As String) As NameValueMap
	Dim OutputMap As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()

	Dim DesignDateFolder As String = ThisApplication.DesignProjectManager.ActiveDesignProject.DesignDataPath
	Dim StandardXMLFullFileName As String = DesignDateFolder & "standard.xml"
	Dim GenericStyleHeading As String = "Style"
	Dim HatchMapHeading As String = "HatchMaterialMap"
	Dim MaterialAttribute As String = "Material"
	Dim PatternHeading As String = "PatternLine"

	Dim StandardXMLdoc As XDocument = XDocument.Load(StandardXMLFullFileName)


	Dim styleElement As XElement

	For Each s As XElement In StandardXMLdoc.Descendants(GenericStyleHeading)

		If s.Value.Contains(StyleName) Then styleElement = s : Exit For

	Next

	If styleElement.Value Is String.Empty Then Return Nothing

	Dim HatchMapXElement As XElement = styleElement.Descendants(HatchMapHeading)(0)

	If HatchMapXElement.Value Is String.Empty Then Return Nothing

	'Now We need to parse this for Materials

	For Each s As XElement In HatchMapXElement.Elements()

		Dim MaterialName As String = s.Attribute(MaterialAttribute).Value

		Dim PatternLine0 As String = s.Descendants(PatternHeading)(0).Value.Split(",")(0)

		PatternLine0 = Right(PatternLine0, PatternLine0.Length - 1)

		OutputMap.Add(MaterialName, PatternLine0)

	Next

	Return OutputMap
End Function