ClassId and ClientId vs Assembly Guid

ClassId and ClientId vs Assembly Guid

Maxim-CADman77
Advisor Advisor
793 Views
7 Replies
Message 1 of 8

ClassId and ClientId vs Assembly Guid

Maxim-CADman77
Advisor
Advisor

Inventor AddIn developer is supposed to create manifest file (.addin) where fill unique values of ClassId and ClientId tags.

On the other hand when new vb.net project is created using Inventor SDK template the project gets AssemblyInfo.vb file with some (i believe unique) Assembly Guid value already filled (? by Visual Studio?).

I'd like to know whether Assembly Guid value should be used for ClassId and/or ClientId values?

 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
794 Views
7 Replies
Replies (7)
Message 2 of 8

Maxim-CADman77
Advisor
Advisor

... and consequent question:
I see my Addin can get own Guid value like this:

 

 

Dim sGUID As String = CType(Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), GetType(GuidAttribute)), GuidAttribute).Value

 

 

But if there a way to get ClassId, ClientId, DisplayName and other values contained within .addin file without parsing it (I believe there should be some more natural way)?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 3 of 8

jjstr8
Collaborator
Collaborator

Inventor doesn't seem to care what the assembly's Guid is.  It's looking for a COM-visible class in the specified assembly that has a Guid attribute that matches the ClassId entry in the .addin file.  The API documentation states that the ClientId entry is used to identify the owner of certain objects your addin creates, such as ribbons and toolbars.  For simplicity's sake, I just make them all the same.

 

As for your second post, what would you do with anything extracted from the .addin file?  I can see going the other direction by using a T4 Text Template to generate the .addin file with the correct Guid.

0 Likes
Message 4 of 8

Maxim-CADman77
Advisor
Advisor

It's all about avoid of code doubling.
Isn't it natural to want all Add-In messages to have caption equal to DisplayName value filled in .addin file?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 5 of 8

Michael.Navara
Advisor
Advisor

I agree with @jjstr8 . My experience is that this GUIDs are generated by project template and I don't need to change them during all lifecycle of the addin (couple of years).

I don't use this cryptic line of code to obtain the clientId but I define const string with the appropriate value inthe AddInServer class and use them everywhere in the code.

Public Const ClientId As string = "{C0717AA7-C127-4AAD-8290-34353FA2511B}"

 

The second part of previous post is about Resources instead of .addin file. This approach allows you to change the title for different languages if necessary. 

0 Likes
Message 6 of 8

Frederick_Law
Mentor
Mentor

I've setup my VS Template to auto create GUID for new project.

Use: $safeprojectname$ $guid1$ $guid2$

There are a few places to change.

.addin file:

<Addin Type="Standard">
  <!--Created for Autodesk Inventor Version 16.0-->
  <ClassId>{$guid1$}</ClassId>
  <ClientId>{$guid1$}</ClientId>
  <DisplayName>$safeprojectname$</DisplayName>
  <Description>$safeprojectname$</Description>
  <Assembly>$safeprojectname$.dll</Assembly>
  <!--LoadOnStartUp 1 LoadOnStartUp-->
  <LoadAutomatically>1</LoadAutomatically>

  <!--LoadBehavior  0:Start with Inventor -->
  <!--LoadBehavior  1:Start with part -->
  <!--LoadBehavior  2:Start with assembly -->
  <!--LoadBehavior  3:Start with presentation -->
  <!--LoadBehavior  4:Start with drawing -->
  <!--LoadBehavior 10:On Demand -->

  <LoadBehavior>1</LoadBehavior>
  <UserUnloadable>1</UserUnloadable>
  <Hidden>0</Hidden>
  <SupportedSoftwareVersionGreaterThan>15..</SupportedSoftwareVersionGreaterThan>
  <DataVersion>1</DataVersion>
  <UserInterfaceVersion>1</UserInterfaceVersion>
</Addin>

 

StandardAddinServer.vb:

 

Namespace $safeprojectname$
  <GuidAttribute("$guid1$")> _
  Public Class $safeitemname$

 

MyTemplate.vstemplate

IV AddIn Ribbon.vbproj

IV AddIn Ribbon.X.manifest

 

I'm converting this to C#.

 

I've attached my Template.  Working in VC2022 Community.

Please take a look and let me know if I missed anything.

0 Likes
Message 7 of 8

Maxim-CADman77
Advisor
Advisor

Standard VB AddIn Template contains the function to get GUID:

 

 

Public Function AddInClientID() As String
    Dim guid As String = ""
    Dim t As Type = GetType(CrossCutter.StandardAddInServer)
    Dim customAttributes() As Object = t.GetCustomAttributes(GetType(GuidAttribute), False)
    Dim guidAttribute As GuidAttribute = CType(customAttributes(0), GuidAttribute)
    guid = guidAttribute.Value.ToString()

    Return guid
End Function

 

 

I believe it gets the value from the *.Addin file, right?

If so then I'd like to know, whether something alike could be done to get the addin's DisplayName and Description values set by the *.Addin file.

 

@jjstr8 

I want to use addin's attribute values for it's RibbonButton definition.


JFYI:
I used to set both values in *.addin file in language-dependant way:

 

<DisplayName Language="1033">MyAddinName_EN<DisplayName>
<DisplayName Language="1040">MyAddinName_IT<DisplayName>
...

 

 

PS:
I just want to have one place to set those values.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 8 of 8

jjstr8
Collaborator
Collaborator

@Maxim-CADman77 :  The function gets the guid from the StandardAddinServer class at runtime.  The guid attribute for that class is set when you create the project from a template.  If you look through the template, you'll see template parameters scattered about:  $safeprojectname$,  $projectname$, $safeitemname$, $guid1$, and $guid2$. The GUIDs are generated randomly and substituted in the project files one time.  DisplayName and Description in the .addin file are both set to $safeprojectname$.  $safeprojectname$ is just your project name with any illegal characters replaced with an underscore.