Export new Mark feature, rename layer name

Export new Mark feature, rename layer name

JelteDeJong
Mentor Mentor
1,137 Views
5 Replies
Message 1 of 6

Export new Mark feature, rename layer name

JelteDeJong
Mentor
Mentor

I'm testing the new "Mark" command in Inventor 2023. I try to export a flat pattern with the following code:

Dim doc As PartDocument = ThisDoc.Document
Dim oCompDef As SheetMetalComponentDefinition = doc.ComponentDefinition

If oCompDef.HasFlatPattern = False Then
    oCompDef.Unfold()
Else
    oCompDef.FlatPattern.Edit()
End If

Dim fileName As String = "C:\temp\test.dxf"

If (IO.File.Exists(fileName)) Then
    IO.File.Delete(fileName)
End If

Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=2000&MarkSurfaceBackLayer=qwert"
oCompDef.DataIO.WriteDataToFile(sOut, fileName)
oCompDef.FlatPattern.ExitEdit()

 That works as expected but the Mark layer does not change to the new name (here qwert). Probably I use the wrong argument. I checked the help files (here) but I guess those are not updated yet. Also, I guessed a couple of names but the argument seems not to follow the same naming conversion as the other argument names.  Did someone already use this new feature and knows which arguments to use to change the mark layer name?

@johnsonshiue 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Accepted solutions (2)
1,138 Views
5 Replies
Replies (5)
Message 2 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

I don't know it is solution, but may be a workaround.

Layer settings for MarkSurface layer is available in StylesEditor. I hope (not tested) it is modifiable using standard API for styles.

Later on your code works without settings in sOut string and respects this style settings.

Sorry for CZ printscreen

MichaelNavara_0-1652455309919.png

 

Message 3 of 6

JelteDeJong
Mentor
Mentor

I did not know it was there as a style and it does what I need (for now). But still, I'm surprised that I'm not able to change the layer by code. 

With your information, I did have an extra look at the API of the "MarkFeature". But I'm also unable to change the mark style for a specific feature. I can't even find the style name used by a specific mark feature. 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 4 of 6

SevInventor
Advocate
Advocate

I guess it's

&MarkSurfaceDownLayer=qwert"

but i have no Inventor 2023 to test try

0 Likes
Message 5 of 6

Hochenauer
Autodesk
Autodesk

There can be multiple Markstyles with multiple downlayers. There is full api access to Mark Styles, ideally you set up your style library so all users have the appropriate settings without a need for changing the name on export.

There also is a postProcess that allows you to rename layers automatically based on xml definition.



Gerald Hochenauer
Senior Principal Engineer, Inventor
Autodesk, Inc.

0 Likes
Message 6 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

Here is few code samples without error checking for MarkFeature styles

 

Get all mark styles 

 

Dim part As PartDocument = ThisDoc.Document
Logger.Debug(String.Format("Styles count: {0}", part.MarkStyles.Count))
For Each oMarkStyle As MarkStyle In part.MarkStyles
	Logger.Debug("{1}{0}{2}", vbTab, oMarkStyle.Name, oMarkStyle.InternalName)
Next

 

 

Get current MarkStyle for specific feature

 

Dim pick As Object = ThisApplication.CommandManager.Pick( _
	SelectionFilterEnum.kPartFeatureFilter, _
	"Pick mark")

Dim oMarkFeature As MarkFeature = TryCast(pick, MarkFeature)
If oMarkFeature Is Nothing Then
	Logger.Error("This is not MarkFeature")
	Return
End If

Dim markDef As MarkDefinition = oMarkFeature.Definition

For i As Integer = 1 To markDef.MarkGeometrySetCount
	Dim styleName = markDef.MarkGeometrySetItem(i).Style.Name
	Logger.Debug("{1}{0}{2}", vbTab, i, styleName)
Next

 

 

Complex sample for change MarkStyle

 

Sub Main
	Dim part As PartDocument = ThisDoc.Document

	'Get MarkFeature
	Dim oMarkFeature As MarkFeature = PickMark()
	If oMarkFeature Is Nothing Then Return

	'Get MarkStyle
	Dim newMarkStyle As MarkStyle = SelectNewMarkStyle(part)
	If newMarkStyle Is Nothing Then Return

	'Get MarkDefinition
	Dim markDef As MarkDefinition = oMarkFeature.Definition

	'Set Mark Style
	For i As Integer = 1 To markDef.MarkGeometrySetCount
		markDef.MarkGeometrySetItem(i).Style = newMarkStyle
	Next
End Sub

Function PickMark()
	Dim oMarkFeature As MarkFeature
	Do
		Dim pick As Object = ThisApplication.CommandManager.Pick( _
			SelectionFilterEnum.kPartFeatureFilter, _
			"Pick mark")
			
		oMarkFeature = TryCast(pick, MarkFeature)
		If oMarkFeature Is Nothing Then
			Dim tryAgain As MsgBoxResult = MsgBox( _
				"This is not MarkFeature" & vbCrLf & "Try again?", _
				MsgBoxStyle.Question + MsgBoxStyle.YesNo, _
				"Pick Mark")
			If tryAgain <> MsgBoxResult.Yes Then
				Return Nothing
			End If
		Else
			Exit Do
		End If
	Loop While True
	Return oMarkFeature
End Function

Function SelectNewMarkStyle(part As PartDocument) As MarkStyle

	Dim currentStyles As New List(Of MarkStyleItem)
	For Each oMarkStyle As MarkStyle In part.MarkStyles
		currentStyles.Add(New MarkStyleItem(oMarkStyle))
	Next

	Dim newMarkStyleItem As MarkStyleItem = InputListBox("Select Style", currentStyles)
	If newMarkStyleItem Is Nothing Then Return Nothing

	Logger.Debug(newMarkStyleItem.Style.Name)
	Return newMarkStyleItem.Style
End Function

Class MarkStyleItem
	Public Sub New(markStyle As MarkStyle)
		Me.Style = markStyle
	End Sub

	Public Property Style As MarkStyle

	Public Overrides Function ToString() As String
		Return Style.Name
	End Function
End Class