Placing custom stamps on drawing (SketchedSymbolDefinition)

Placing custom stamps on drawing (SketchedSymbolDefinition)

Enflotech
Participant Participant
1,944 Views
8 Replies
Message 1 of 9

Placing custom stamps on drawing (SketchedSymbolDefinition)

Enflotech
Participant
Participant

Good day,

 

Hoping someone here can help me figure this out. I am using the code below (slapped together from snippets found here and help docs) to place custom stamps (sketched symbols) on drawings. On the drawing template file, I have a muli-value list parameter for each of the stamps we use. The stamps are saved in the drawing template and depending on the user's choice (radio buttons), this stamp is placed on each of the drawing sheets.

This worked well for me and my colleagues until a couple of months ago, when it suddenly stopped working for some of us. The only thing I can think of is something must have changed during one of the updates. This issue is also present in 2025. Whenever I run the code, I get the following error:

 

"Error on line 22 in rule: Place Stamps, in document: ENFMIL2407001 REV1.idw

The parameter is incorrect. (0x80070057 (E_INVALIDARG))"

 

Sub Main()
    oDrawDoc = ThisApplication.ActiveDocument
	DeleteStamps()
	PlaceStamp()
    oDrawDoc.Update
End Sub

Dim oDrawDoc As DrawingDocument
Dim oStamp As String

Sub PlaceStamp()
	'create insertion point, coordinates - are cm 
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oInsertionPoint As Point2d
	
	oStamp = "Stamp - " + Parameter("StampsList")
	'MessageBox.Show(oStamp + " is selected", "Stamp")

	'define the insert point for the symbol
	oInsertionPoint = oTG.CreatePoint2d(0,29.7) ' X = 0 cm , Y = 29.7 cm
	'define symbol Definition to use
	oSymDef = oDrawDoc.SketchedSymbolDefinitions.Item(oStamp​)
	
	' Iterate through the sheet
	For Each oSheet In oDrawDoc.Sheets
		oSheet.Activate
		'insert the new symbol
		'Nothing is used when teh symbol has no prompted entry
		oSym = oSheet.SketchedSymbols.Add(oSymDef,oInsertionPoint​,0,1,Nothing)	
	Next 'next sheet
End Sub

Sub DeleteStamps()
	' Iterate through the sheet
	For Each oSheet In oDrawDoc.Sheets
	oSheet.Activate
	'Iterate through each symbol in the active sheet
		For Each oSymbol In oSheet.SketchedSymbols
			'look for the symbol by name
			If oSymbol.Name.Contains ("Stamp") Then
			'delete the symbol
			oSymbol.Delete
			Else 
			End If
		Next 'next symbol
	Next 'next sheet
End Sub

 

0 Likes
Accepted solutions (1)
1,945 Views
8 Replies
Replies (8)
Message 2 of 9

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Enflotech.  It is difficult to tell from that what the problem may be.  It is obviously not finding the SketchedSymbolDefinition object based on the String name that has been assembled within the code routine.  This could be cause a couple ways.  The most obvious would be if it simply did not exist directly in that drawing document, but not likely.  Next, something odd may be going on where it is getting the name from the parameter, making the name of the definition not be accurate.  I see that you are using the iLogic shortcut snippet there, and not providing any specification about which document it should be getting that parameter's value from.  That may be an issue, but not sure.

I have copied your code over into a new internal rule, then made some edits for error proofing, then copied it back to the code window below for you.  I do not know if those edits will fix the issue, or maybe just point them out better though.  Some of the edits:  When iterating though a collection, and you know every element in that collection is the same Type, it is usually best to specify the Type of that variable, which then enables Intellisense recognition of it within that block of code.  It is also often a good idea to 'declare' each of your variables, especially if using them in a loop, which help reset them.  When combining (concatenating) multiple String values into one String, get in the habit of always using the & character, instead of the + character.  It is safer when numbers may get involved in the mix.  I also like to include some lines of code that provide helpful feedback when something that 'can possibly' go wrong does, and I usually prefer to use the iLogic Logger tool to write those comments to the iLogic Log window, for review after running them, which avoids pop-up dialogs when it is a production related code.  Also, when iterating through drawing sheets to do something on each of them, it is often a good idea to record which one was originally active to a variable before all iterations start, then set it back to active after the iterations.  Not sure why the 'oStamp' variable is being shared between routines here, since it is only being used in one of the routines.  I also eliminated a single space between 'Contains' and the ( character.  Those gaps can be common when converting code from VBA to iLogic/vb.net. 

Sub Main()
	oDrawDoc = ThisApplication.ActiveDocument
	DeleteStamps()
	PlaceStamp()
	oDrawDoc.Update
End Sub

Dim oDrawDoc As DrawingDocument
Dim oStamp As String

Sub PlaceStamp()
	'create insertion point, coordinates - are cm 
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oInsertionPoint As Point2d
	'define the insert point for the symbol
	oInsertionPoint = oTG.CreatePoint2d(0, 29.7) ' X = 0 cm , Y = 29.7 cm
	Dim sStampName As String = ""
	Try
		sStampName = Parameter("StampsList")
	Catch
		MessageBox.Show("Could not find parameter named 'StampsList'!", "StampsList Param Not Found")
	End Try
	If sStampName = "" Then Return
	'Logger.Info("Stamp Name From Param = " & sStampName)
	
	oStamp = "Stamp - " & sStampName
	'MessageBox.Show(oStamp + " is selected", "Stamp")
	'define symbol Definition to use
	Dim oSymDef As SketchedSymbolDefinition = Nothing
	Try
		oSymDef = oDrawDoc.SketchedSymbolDefinitions.Item(oStamp​)
	Catch
		MessageBox.Show("SketchedSymbolDefinition named '" & oStamp & "' not found.", "Stamp Def Not Found")
	End Try
	If oSymDef Is Nothing Then Return
	' Iterate through the sheet
	For Each oSheet As Sheet In oDrawDoc.Sheets
		oSheet.Activate
		'insert the new symbol
		'Nothing is used when teh symbol has no prompted entry
		Dim oSym As SketchedSymbol = oSheet.SketchedSymbols.Add(oSymDef, oInsertionPoint)
	Next oSheet
End Sub

Sub DeleteStamps()
	' Iterate through the sheet
	For Each oSheet As Sheet In oDrawDoc.Sheets
		oSheet.Activate
		'Iterate through each symbol in the active sheet
		For Each oSymbol As SketchedSymbol In oSheet.SketchedSymbols
			'look for the symbol by name
			If oSymbol.Name.Contains("Stamp") Then
				'delete the symbol
				oSymbol.Delete
			End If
		Next oSymbol
	Next oSheet
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)

Message 3 of 9

Enflotech
Participant
Participant

Hi @WCrihfield,


Firstly, thanks for the cleaned up code, it is a huge help.

I have replaced my version with yours and with the help of your error catching addition, I can now see that the requested stamp is not found...even though it is present in the document as can be seen in the screenshot below.

I have double-checked all stamp names as well as the code generated stamp names, they match 100%. So I can't see any reason for this behavior. The thing that bugs me most is that it used to work fine, then it suddenly didn't. It also still works for some of our other drafters.

 

Enflotech_1-1723638287713.png

 

 

 

0 Likes
Message 4 of 9

Curtis_Waguespack
Consultant
Consultant

@Enflotech , I used @WCrihfield's code and recreated your stamps ( with just a simple circle) using the names you show. I did this in Inventor 2022 as this was the version I had open at the moment, and everything worked fine.

 

When I open the same drawing in 2025, I see the same errant behavior you see with every stamp name.

 

I'm not sure what the issue is ( I didn't look too close just yet), but here is my file in case it helps others troubleshoot this.

 

Curtis_Waguespack_0-1723640369813.png

 

0 Likes
Message 5 of 9

Curtis_Waguespack
Consultant
Consultant

quick update:

 

I updated 2025 to the build shown here and still see the issue:

Curtis_Waguespack_0-1723642224379.png

 

 

0 Likes
Message 6 of 9

Curtis_Waguespack
Consultant
Consultant

Oddly if I add Option Explicit On a shown, it tells me that the variable is not declared or in not accessible.

 

Maybe someone else understands what 2025 is needing here? see updated rule in the attached drawing.

@MjDeck would you be able to take a look?

 

Curtis_Waguespack_0-1723644582734.png

 

0 Likes
Message 7 of 9

MjDeck
Autodesk
Autodesk

Hi @Curtis_Waguespack - on this line:

 

oSymDef = oDrawDoc.SketchedSymbolDefinitions.Item(oStamp​)

 

There is an extra character at the end of oStamp. It's invisible in the iLogic rule editor, but you can see it if you copy and paste the line into Notepad++. (Use View > Show Symbol > Show Non-Printing Characters in Notepad++.)
It is a Zero-width space .
To remove it, place the text cursor at the end of the line. Then hit Backspace slowly two or three times. You will see that the cursor doesn't move when you delete the zero-width space.
So the fix is to remove that character. The compiler is seeing it as part of the variable name. Removing it will give you the actual "oStamp" name.
Maybe Autodesk or Microsoft can fix this in a future release.


Mike Deck
Software Developer
Autodesk, Inc.

Message 8 of 9

Enflotech
Participant
Participant

@MjDeck, well spotted! Thanks a lot to all of you for your efforts.

Cheers!

 

Message 9 of 9

MjDeck
Autodesk
Autodesk

In Inventor 2024 and earlier, a zero-width space will not cause a problem. (As long as it's at the beginning or end of a word. It can cause a problem if it's in the middle.)
In Inventor 2025, we moved to .NET 8 and the Roslyn compiler for Visual Basic in iLogic. It looks like that treats it differently.


Mike Deck
Software Developer
Autodesk, Inc.