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

API Return Enumerator Name instead of numeric value?

pball
Advisor

API Return Enumerator Name instead of numeric value?

pball
Advisor
Advisor

Is it possible to have the API return the name of an enumerator like kAlighTextLeft instead of 19970? Having the name be returned could save a trip to the API help to find out what it is.

 

Debug.Print ThisApplication.ActiveDocument.ActiveSheet.DrawingNotes.GeneralNotes.Item(1).HorizontalJustification

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Reply
1,607 Views
9 Replies
Replies (9)

HermJan.Otterman
Advisor
Advisor

Hello,

 

when I use VB.net (visual studio) and I Add  ".tostring" I get the text value

 

        Dim oDrawDoc As Inventor.DrawingDocument = _inventorApp.ActiveDocument

        MsgBox(oDrawDoc.ActiveSheet.DrawingNotes.GeneralNotes.Item(1).HorizontalJustification.ToString)

 

without the tostring, I get the number.

 

in iLogic I always get the number....

 

what are you using?

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


MechMachineMan
Advisor
Advisor

I tried the .ToString method but couldn't get it to work.

 

Also tried the .GetName method, but it says cannot use on Type integer.

 

Stuck using a select case structure...

 

Wondering if there is any way around this?

 

'oRow.BOMStructure.GetName("BOMStructureEnum", oRow.BOMStructure),

vs 

		Select Case oRow.BOMStructure
			Case 51970
				oRowBOMStructure = "Normal"
			Case 51973
				oRowBOMStructure = "Purchased"
			Case 51971
				oRowBOMStructure = "Phantom"
			Case 51972
				oRowBOMStructure = "Reference"
			Case 51974
				oRowBOMStructure = "Inseparable"
			Case Else
				oRowBOMStructure = "??????????"	
		End Select

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes

pball
Advisor
Advisor

I use VBA, iLogic, and VB.net for different things. Though I frequently use VBA for testing and playing around with code, which then gets moved to my VB.net addin. So a solution that works in VBA and/or iLogic would be best.

 

Thanks for posting your VB.net solution. I'm sure I'll end up using it at some point.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes

ekinsb
Alumni
Alumni

VBA doesn't support anything to get the name of an enum value, like .NET does.  It would be possible, with some work, to write your own function similar to what Justin suggests above but it's not built into VBA.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes

Maxim-CADman77
Advisor
Advisor

Sorry for updating this but there is still something to discuss - https://forums.autodesk.com/t5/inventor-customization/fail-to-get-textual-names-of-browser-node-type... 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes

JhoelForshav
Mentor
Mentor
0 Likes

JelteDeJong
Mentor
Mentor

in iLogic i use 2 functions to find the name of an object or an Enum. check this rule. (i didnt find a vba version of this rules.)

Public Sub Main()
	' for inventor objects you can use this to find the object type.
    showtInventorObjectType(ThisDoc.Document)
	
	' for enum objects you can use this for the name
    showEnumName(Of HorizontalTextAlignmentEnum)(ThisApplication.ActiveDocument.ActiveSheet.DrawingNotes.GeneralNotes.Item(1).HorizontalJustification)

End Sub

Public Sub showtInventorObjectType(obj As Object)
    showEnumName(Of ObjectTypeEnum)(obj.type)
End Sub

Public Sub showEnumName(Of T)(obj As Object)
    MsgBox(CType(obj, T).ToString())
End Sub

 

 

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

BrianEkins
Mentor
Mentor

As I said before, this isn't supported in VBA but with .NET it's built-in and can easily be done.  Here's an example that will work in a Visual Basic program or an iLogic rule (since they both use .NET) that will display the name of an enum value for the current document type.  The first argument identifies which enum and the second is the enum value and it returns the name of the enum.

 

MsgBox([Enum].GetName(GetType(Inventor.DocumentTypeEnum), doc.DocumentType))

  

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com

Maxim-CADman77
Advisor
Advisor

This helped me.
Good trick. Thanks!!

Please vote for Inventor-Idea Text Search within Option Names

0 Likes