Sketch Symbol with current Date on it

Sketch Symbol with current Date on it

JShearer98
Participant Participant
287 Views
3 Replies
Message 1 of 4

Sketch Symbol with current Date on it

JShearer98
Participant
Participant

Hi all,

 

I'm currently trying to setup a Sketch Symbol for a Stamp with the date on it.

 

I'm wanting for it to either grab the date as it is placed on the drawing automatically or failing that have a prompt appear upon placement so the user can insert the date.

 

An External Rule to apply the stamp would also work if anyone can help with coding it.

 

Looking at other posts I can see other users have a prompt box appear when using Format Text but it does't appear on mine.

 

JShearer98_0-1744719815760.png

 

0 Likes
Accepted solutions (1)
288 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @JShearer98.  In order for others to write a code that would do all that you want, we would have to know more details about the sketched symbol, such as what <DATE> represents, and where you want it on the sheet.  I will post a 'starter' example iLogic rule code below.  It assumes the 'name' of the sketched symbol's definition is "DateStamp", so you will likely need to change that within this code first of all.  Next, is that definition already within the 'active' drawing, or does it need to be imported from an external sketched symbols library somewhere?  This example assumes that the definition already exists within the active document.  Next, where to place it.  This example is placing it at 3 units (CM by default) by 3 units from the lower left corner of the sheet, as a default location, so you may have to change that.  Next is how to set-up or include the date.  In this example, it expects the Date portion of the text to be a single TextBox representing a 'Prompted Entry'.  It also expects there to be just one Prompted Entry.  If either is not true, it will error out.  It fills in that one prompt with todays date in short String format.

Sub Main
	Dim oInvApp As Inventor.Application = ThisApplication
	Dim oDDoc As DrawingDocument = TryCast(oInvApp.ActiveDocument, Inventor.DrawingDocument)
	If oDDoc Is Nothing Then Return
	Dim oSSDefs As SketchedSymbolDefinitions = oDDoc.SketchedSymbolDefinitions
	Dim oSSDef As SketchedSymbolDefinition = Nothing
	Try
		oSSDef = oSSDefs.Item("DateStamp") '<<< CHANGE THIS >>>
	Catch
		MsgBox("Could not find Specified SketchedSymbolDefinition!", vbCritical, "iLogic")
	End Try
	If oSSDef Is Nothing Then Return
	Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
	Dim oSSs As SketchedSymbols = oSheet.SketchedSymbols
	Dim oSS As SketchedSymbol = Nothing
	Dim oPos As Inventor.Point2d = oInvApp.TransientGeometry.CreatePoint2d(3, 3)
	Dim oPrompts() As String = {Now.ToShortDateString}
	Try
		oSS = oSSs.Add(oSSDef, oPos, 0, 1, oPrompts)
	Catch
		MsgBox("Error Adding SketchedSymbol Instance To Active Sheet!", vbCritical, "iLogic")
	End Try
	
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

Ivan_Sinicyn
Advocate
Advocate
Accepted solution

@JShearer98 Hi
Here's one of the options. You only need to replace the symbol name in the code and set the insertion coordinates.

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim currentDate As String = Now.ToString("dd.MM.yyyy")
Dim symbolName As String = "Project and Order" ' SketchedSymbol Name

' Get the active sheet
Dim oSheet As Sheet = oDoc.ActiveSheet

' Find the symbol definition
Dim oSymbolDef As SketchedSymbolDefinition = Nothing
For Each def As SketchedSymbolDefinition In oDoc.SketchedSymbolDefinitions
    If def.Name = symbolName Then
        oSymbolDef = def
        Exit For
    End If
Next

' Check if the definition was found
If oSymbolDef Is Nothing Then
    MessageBox.Show("Symbol '" & symbolName & "' not found in the drawing.", "Error")
    Exit Sub
End If

Try
    ' Insert the symbol at point (10, 10) cm
    Dim position As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)
    Dim oSymbol As SketchedSymbol = oSheet.SketchedSymbols.Add(oSymbolDef, position)
    
    ' Open the symbol sketch for editing
    Dim oSketch As DrawingSketch
    oSymbolDef.Edit(oSketch)
    
    ' Iterate through text boxes
    For Each oTextBox As Inventor.TextBox In oSketch.TextBoxes
        If InStr(1, oTextBox.FormattedText, "&lt;DATE&gt;", vbTextCompare) > 0 Then
            Dim newText As String = Replace(oTextBox.FormattedText, "&lt;DATE&gt;", currentDate)
            oTextBox.FormattedText = newText
        End If
    Next
    
    ' Save changes
    oSymbolDef.ExitEdit(True)
    
Catch ex As Exception
    oSymbolDef.ExitEdit(False)
    MessageBox.Show("Error inserting or editing symbol: " & ex.Message, "Error")
End Try

oDoc.Update

 

INV 2025.3
0 Likes
Message 4 of 4

JShearer98
Participant
Participant

Hi Ivan,

 

This works great.

 

Thank you very much.

0 Likes