Sheet Metal Mark Feature in VBA

Sheet Metal Mark Feature in VBA

amillsLD4X8
Participant Participant
1,558 Views
10 Replies
Message 1 of 11

Sheet Metal Mark Feature in VBA

amillsLD4X8
Participant
Participant

Hi,

I have been trying to use the mark feature with a sheet metal part while the part is in its flat state, however I've been unsuccessful. 

Would someone be able to write some VBA to use the mark feature on a flat pattern? I've attached image of what I am trying to do. I'd rather not post my code on here as it is rather long and messy.

 

Thanks,

0 Likes
1,559 Views
10 Replies
Replies (10)
Message 2 of 11

Andrii_Humeniuk
Advisor
Advisor

Hi @amillsLD4X8 . I tried to write the rule you wanted, but it doesn't work. Cannot create mark (line 31). I don't know why so.

Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oMarkStyle As MarkStyle = oPartDoc.MarkStyles.Item(1)
Dim oSheetDef As SheetMetalComponentDefinition = oPartDoc.ComponentDefinition
If Not oSheetDef.HasFlatPattern() Then
	oSheetDef.Unfold()
End If
Dim oFlatPatn As FlatPattern = oSheetDef.FlatPattern
oFlatPatn.Edit()
Dim oPlane As Plane = oFlatPatn.TopFace.Geometry
Dim oSketch As PlanarSketch = oFlatPatn.Sketches.Add(oFlatPatn.TopFace, False)
oSketch.Edit()
oSketch.ProjectedCuts.Add()
For Each oLine As SketchLine In oSketch.SketchLines
	oLine.Construction = True
Next
Dim oSketchRange As Inventor.Box2d = ThisApplication.TransientGeometry.CreateBox2d
For Each oEntity As SketchEntity In oSketch.SketchEntities
	Call oSketchRange.Extend(oEntity.RangeBox.MinPoint)
	Call oSketchRange.Extend(oEntity.RangeBox.MaxPoint)
Next
Dim oPoint As Inventor.Point2d = oTG.CreatePoint2d(oSketchRange.MinPoint.X + 1, oSketchRange.MinPoint.Y + 1)
oSketch.TextBoxes.AddFitted(oPoint, "123", oPartDoc.TextStyles.Item(1))
oSketch.ExitEdit()
Dim oSketchObjects As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
For Each oSketchText As Inventor.TextBox In oSketch.TextBoxes
	oSketchObjects.Add(oSketchText)
Next
Dim oMarkFeat As MarkFeatures = oSheetDef.Features.MarkFeatures
Dim oMarkDef As MarkDefinition = oMarkFeat.CreateMarkDefinition(oSketchObjects, oMarkStyle)
Dim oMark As MarkFeature = oMarkFeat.Add(oMarkDef)

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 11

amillsLD4X8
Participant
Participant

Thank you, @Andrii_Humeniuk, for the attempt. I do appreciate it.

I was able to do a mark feature on a standard part and a sheet metal part, but never on a flat pattern.

0 Likes
Message 4 of 11

dimamazutaMMJ32
Advocate
Advocate

A mark that was added in flat pattern mode remains visible only in flat pattern mode (both in the model and in the drawing if you insert a flat pattern). Could you clarify what exactly needs to be done?

Знімок екрана 2023-05-03 211957.png

0 Likes
Message 5 of 11

amillsLD4X8
Participant
Participant

@dimamazutaMMJ32  Yes, I can clarify. I'm trying to "mark through" the body. I'd like the line that is created by the mark to show up in the dwg file.

From there I will export the dwg as a dxf to be cut on a cnc. I am aware of the "Export Face As" feature, but I'd like the dxf to be driven from the dwg. I am also aware that any features drawn on the flat pattern won't show up on the folded model.

 

0 Likes
Message 6 of 11

jeremy.goenen
Advocate
Advocate
Did you find a Solution? I had the Same Problem Today, but i made it work, if you still need it i can help
Fanden Sie diesen Beitrag hilfreich? Fühlen Sie sich frei, diesen Beitrag zu liken.
Wurde Ihre Frage erfolgreich beantwortet? Klicken Sie dann auf die Schaltfläche LÖSUNG AKZEPTIEREN

Inventor Versionen:
2025.2
0 Likes
Message 7 of 11

grahov
Participant
Participant
Hi!please tell me about your Solution
0 Likes
Message 8 of 11

amillsLD4X8
Participant
Participant

@jeremy.goenen Yes I would be interested in your solution. Sorry for the late reply, I'm just now seeing your comment.

0 Likes
Message 9 of 11

grahov
Participant
Participant

I have found a solution

 

'==================== Creating an Objectcollection to be Marked ======================
Dim oSketchObjects As ObjectCollection
oSketchObjects = ThisApplication.TransientObjects.CreateObjectCollection
    
' Get all entities in the sketch
Dim oSketchText As TextBox
For Each oSketchText In oSketch.TextBoxes
oSketchObjects.Add(oSketchText)
Next

'==================== Creating the Mark on the textbox  ======================

Dim oFlat As FlatPatternFeatures
oFlat = oCompDef.FlatPattern.Features 

Dim oMarkFeatures As MarkFeatures
oMarkFeatures = oFlat.MarkFeatures
    
'Get a mark style.
Dim oMarkStyle As MarkStyle
oMarkStyle = oPartDoc.MarkStyles.Item(1)
    
'Create mark definition.
Dim oMarkDef As MarkDefinition
oMarkDef = oMarkFeatures.CreateMarkDefinition(oSketchObjects, oMarkStyle)
	
'Create a mark feature.
Dim oMark As MarkFeature
oMark = oMarkFeatures.Add(oMarkDef)

'====================   
0 Likes
Message 10 of 11

jeremy.goenen
Advocate
Advocate

@amillsLD4X8  @grahov  Hi, i can't remember where exactly the problem was, but im using it in a sub.

"marksrting" is a function , "markedexport ", and "numberlessexport" are subs

 

Edit: Imporant! I just recalled that you can't do it in Inventor Version 2023.1, you will get a missing Member exception, i dont know for 2023.2 and 2023.3, but it will work in 2023.4

Also, if you want to test my code, be sure to set the Name of the Markstyle to match one of yours, and check if you have the Simplex Text Font Installed, or change the override to another one.

 

Sub marktextbox(ByVal position As Point, ByRef stringlength As Double, ByRef stringheight As Double, ByRef offset As Double)

'declared ahead to make deletion in case of errors possible
	Dim marksketch As PlanarSketch
	Dim markfeature As MarkFeature

Try
	Dim transgeom As TransientGeometry = ThisApplication.TransientGeometry
	Dim sheetmetalcomponentdefinition As SheetMetalComponentDefinition = ThisDoc.Document.ComponentDefinition
	Dim flatpattern As FlatPattern = sheetmetalcomponentdefinition.FlatPattern
	' create the sketch
	marksketch = flatpattern.Sketches.AddWithOrientation(flatpattern.TopFace, _
	sheetmetalcomponentdefinition.WorkAxes.Item(1), True,True, sheetmetalcomponentdefinition.WorkPoints(1),False)
	marksketch.Visible = False
	marksketch.Name = "MarkierskizzeBauteilnummer"
	' set the cornerpoints of the textbox
	Dim markcorner As Point2d = marksketch.ModelToSketchSpace(transgeom.CreatePoint((position.X+offset), (position.Y+offset), 0))
	Dim markcorner2 As Point2d = marksketch.ModelToSketchSpace(transgeom.CreatePoint((position.X + (offset + stringlength)), (position.Y + (offset + stringheight)), 0))
	' get the string, and create the textbox, "markstring" is a function here
	Dim text As String = markstring
	Dim textbox As Inventor.TextBox = marksketch.TextBoxes.AddByRectangle(markcorner,markcorner2,text)
	textbox.FormattedText = "<StyleOverride Font='SIMPLEX' FontSize='1'>" & text & "</StyleOverride>"
	' put the text into an object collection
	Dim markobjects As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	
	For Each markbox As Inventor.TextBox In marksketch.TextBoxes
	    markobjects.Add(markbox)
	Next markbox
	
	' get the style per Name
	Dim markstyle As MarkStyle
	For Each searchstyle As markstyle In ThisDoc.Document.MarkStyles
		If searchstyle.Name = "Fläche markieren" Then
			markstyle = searchstyle
			Exit For
		End If
	Next searchstyle
	
	' create the mark	
	Dim MarkFeatures As MarkFeatures = flatpattern.Features.MarkFeatures
	Dim markdefinition As MarkDefinition = markfeatures.CreateMarkDefinition(markobjects, markstyle)
	markfeature = markfeatures.Add(markdefinition)
	markfeature.Name = "Bauteilnummer"
	Call markedexport
	GoTo cleanup
Catch
	Call numberlessexport
	GoTo cleanup
End Try

cleanup :
	Try : markfeature.Delete : Catch : End Try
	Try : marksketch.Delete : Catch : End Try

End Sub

 

Fanden Sie diesen Beitrag hilfreich? Fühlen Sie sich frei, diesen Beitrag zu liken.
Wurde Ihre Frage erfolgreich beantwortet? Klicken Sie dann auf die Schaltfläche LÖSUNG AKZEPTIEREN

Inventor Versionen:
2025.2
0 Likes
Message 11 of 11

WCrihfield
Mentor
Mentor

Just dropping a link here to another similar topic with recent activity.

https://forums.autodesk.com/t5/inventor-programming-ilogic/adding-new-mark-feature-to-flat-pattern-w... 

At first the MartFeatures were not accessible, due to the local installation of Inventor not being updated to the latest update.  After updating, it became available.

After a quick glance at the code suggested in Message 2 here, it looks like the main reason the code was not working is because near the end, the MarkFeatures were being accessed from the SheetMetalComponentDefinition, instead of from under the FlatPattern object (FlatPatternFeatures.MarkFeatures).  The FlatPattern object is another type of ComponentDefinition, so it has its own set of parameters, features and such, and its own 'edit mode'.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)