Get Programmer Name From API

Get Programmer Name From API

Infinite_Chatter
Contributor Contributor
1,438 Views
9 Replies
Message 1 of 10

Get Programmer Name From API

Infinite_Chatter
Contributor
Contributor

I have written a plugin and the last step I need is to get the programmer name from the project. I believe Project class has this info but I was hoping someone could guide me to how to access it.

0 Likes
Accepted solutions (1)
1,439 Views
9 Replies
Replies (9)
Message 2 of 10

luc_ponsaerts
Advocate
Advocate

Hi, 

I use the copyright value of the assemblyInfo. However there are other ways, I asked ClaudeAI about it, and I got the following answer from ClaudeAI :

 

C# : when starting a new app (Windows application, .net framework 4.8), where can I store the name of the programmer, and how can I retrieve the name of the programmer to be used in a string ?

 

I'll help you create a solution for storing and retrieving the programmer's name in a .NET Framework Windows application. Here are a couple of common approaches:

 

// Method 1: Using App.config

// First, add this to your App.config file:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

    <appSettings>

        <add key="ProgrammerName" value="John Doe" />

    </appSettings>

</configuration>

 

// Then in your code, add this using statement:

using System.Configuration;

 

// To retrieve the programmer name:

public string GetProgrammerNameFromConfig()

{

    return ConfigurationManager.AppSettings["ProgrammerName"] ?? "Unknown Programmer";

}

 

// Method 2: Using Assembly Information

// In AssemblyInfo.cs (found in Properties folder), add or modify:

[assembly: AssemblyCompany("Your Company Name")]

[assembly: AssemblyCopyright("Copyright © 2025 by Your Programmer Name")]

 

// To retrieve the information:

using System.Reflection;

 

public class ProgrammerInfo

{

    public string GetProgrammerNameFromAssembly()

    {

        // Get copyright info which contains the programmer name

        var copyright = Assembly.GetExecutingAssembly()

            .GetCustomAttribute<AssemblyCopyrightAttribute>()?.Copyright ?? "Unknown";

       

        // Parse the copyright string to extract the programmer name

        // Assuming format: "Copyright © 2025 by Your Programmer Name"

        string programmerName = copyright.Split(new[] { "by " },

            StringSplitOptions.RemoveEmptyEntries).LastOrDefault()?.Trim() ?? "Unknown Programmer";

       

        return programmerName;

    }

}

 

// Method 3: Using a dedicated Settings file

// Right-click your project -> Properties -> Settings

// Add a new setting:

// Name: ProgrammerName

// Type: String

// Scope: Application

// Value: Your Name

 

// To retrieve the setting:

public string GetProgrammerNameFromSettings()

{

    return Properties.Settings.Default.ProgrammerName;

}

 

// Usage example:

public void DisplayProgrammerInfo()

{

    // Using App.config

    string configName = GetProgrammerNameFromConfig();

    MessageBox.Show($"Programmer (from config): {configName}");

 

    // Using Assembly info

    var programmerInfo = new ProgrammerInfo();

    string assemblyName = programmerInfo.GetProgrammerNameFromAssembly();

    MessageBox.Show($"Programmer (from assembly): {assemblyName}");

 

    // Using Settings

    string settingsName = GetProgrammerNameFromSettings();

    MessageBox.Show($"Programmer (from settings): {settingsName}");

}

 

I've provided three different methods for storing and retrieving the programmer's name, each with its own advantages:

  1. App.config: Good for application-wide settings that don't change often. Easy to modify without recompiling.
  2. Assembly Information: Built into the assembly metadata. Good for version control and official product information.
  3. Settings file: The most user-friendly approach, as it can be managed through Visual Studio's Properties window.

The most recommended approach would be Method 3 (Settings file) because:

  • It's easy to maintain through Visual Studio's UI
  • It's strongly typed
  • It's designed specifically for application settings
  • It can be scope-controlled (Application vs. User)

To implement the Settings approach:

  1. Right-click your project in Solution Explorer
  2. Select Properties
  3. Click on the Settings tab
  4. Add your programmer name setting
  5. Save the changes

Then you can use it as shown in the code example. Would you like me to elaborate on any of these methods?

 

Great. Let me try this now.

 

Good luck with the implementation! Let me know if you encounter any issues or need clarification on any of the methods. Since the Settings approach is the most straightforward, I recommend starting with that one. Don't forget to save your project after adding the new setting in the Properties window.

Claude can make mistakes. Please double-check responses.

0 Likes
Message 3 of 10

luc_ponsaerts
Advocate
Advocate

btw, The code generated by an AI will practically always have errors. 

It is important to check.

 

I am using :

/* information from assembly to be used in the About window.
*/
public static string AppInfo()
{
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
// var attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
// var guid = attribute.Value;

// productName is a global variable defined in the class Globals in unit GlobalVars
productName = fvi.ProductName;
// programmerName is a global variable defined in the class Globals in unit GlobalVars
// programName takes its value by splitting the LegalCopyright, taking the second part, which is the programmer.
// is is important that the LegalCopyright is in the form " <copyright text> : Programmer".
// The dividing char has to be a colon.
programmerName = fvi.LegalCopyright.Split(':')[1];
string result = "Product Name : " + productName
+ Environment.NewLine + "Product Version : " + fvi.ProductVersion
+ Environment.NewLine + "Build date : " + AssemblyCreationDate.Value
// + Environment.NewLine + "GUID : " + guid
+ Environment.NewLine + "Comments : " + fvi.Comments
+ Environment.NewLine + "Copyright : " + fvi.LegalCopyright
+ Environment.NewLine + "Company Name : " + fvi.CompanyName
+ Environment.NewLine + "Programmer Name : " + programmerName
;
return result;
}

0 Likes
Message 4 of 10

crashExpress
Contributor
Contributor

To be clear you need to get the programmer of the PowerMill project? :PM programmer.pngWriting_a_PowerMILL_plugin_v6.png

My issue is that the Project interface class doesn't seem to have the programmer as I was lead to believe from the example API plug-in on github:

powermill-api-examplesaddin-excel-setup.png

0 Likes
Message 5 of 10

luc_ponsaerts
Advocate
Advocate

OK, I misunderstood your request...

I never worked with plugins, in case of custom core the solution would be to execute an available macro command :

 

string programmerName = PMill.ExecuteEx("$project.programmer");

 

I don't know if this is available in plugins.

0 Likes
Message 6 of 10

icse
Advisor
Advisor

you also could use the user_id() function.

 

somehting like this:

var $programmer = pm.ExecuteEx("print par $user_id()")

0 Likes
Message 7 of 10

Infinite_Chatter
Contributor
Contributor

I ended up going with:

 

string partNameInfo = (string)PMill.ExecuteEx("print $project.PartName");

 

 

my goal was to avoid macros in general but i guess one call isn't the worst.

0 Likes
Message 8 of 10

Infinite_Chatter
Contributor
Contributor
Accepted solution

The current way to do this without macros in the API is:

PMill = new PMAutomation(Autodesk.ProductInterface.InstanceReuse.UseExistingInstance, Modes.WithoutGui);

string programmerName = PMill.GetPowerMillParameter("Programmer");

 

0 Likes
Message 9 of 10

luc_ponsaerts
Advocate
Advocate

Thanks for this information. Didn't know about the GetPowerMillParameter() function. I had an older (3.0.0) download of the Customcore source, and that function doesn't exist there.

It would be informative if the Customcore developer(s) would add a more elaborated explanation of new functions added. Please?

0 Likes
Message 10 of 10

Infinite_Chatter
Contributor
Contributor

One way I found this was to visit the API on Github and read the pull request messages. I know this is not ideal and would be nice to have some full fledged documentation.

Pmill API.png

0 Likes