Hi Guys, I’m trying to create a way to automate several dynamo by command in C#, but I’m not able to handle it due to some blockage of the dynamo player, the file is written automatically in AppSettings.json, but it is not recognized.
namespace plugin
{
public class Class1
{
[CommandMethod("dynamoPropertySet")]
public void dynamo1()
{
string path = @"C:\\Users\\anonymous\\Documents\\anonymous_TOOLS\\01_Rotines\\01_Dynamo\\Tools__PropertySets";
string displayName = "Tools__PropertySets";
dynamoComInput1(path, displayName);
}
public void dynamoComInput1(string fullPath, string displayname)
{
try
{
List<string> linhas = new List<string>();
List<string> linhasFalse = new List<string>();
List<string> linhasAjustadas = new List<string>();
string[] arquivo = File.ReadAllLines(caminhoJson());
int cont = 1;
if (arquivo.Length == 1)
{
string[] l = arquivo[0].Split(',');
foreach (var item in l)
{
if (cont != l.Length)
{
linhas.Add(item + ",");
}
else
{
linhas.Add(item);
}
cont++;
}
}
else
{
string[] l = File.ReadAllLines(caminhoJson());
foreach (var item in l)
{
linhas.Add(item);
}
}
foreach (string line in linhas)
{
if (line.Contains("isDefault") && line.Contains("true"))
{
linhasFalse.Add(line.Replace("true", "false"));
}
else
{
linhasFalse.Add(line);
}
}
int marcador = 0;
int marcador2 = 0;
foreach (string line in linhasFalse)
{
if (line.Contains("displayName") && line.Contains("Tools"))
{
marcador = 1;
int lIn = line.IndexOf("displayName");
if (line.Contains("{"))
{
linhasAjustadas.Add(line.Substring(0, lIn + 14).Insert(lIn + 14, (displayname + '\u0022' + ",")));
marcador2 = 1;
}
else
{
linhasAjustadas.Add(line.Substring(0, lIn + 15).Insert(lIn + 15, (displayname + '\u0022' + ",")));
}
}
else if (line.Contains("fullPath") && marcador == 1)
{
if (marcador2 == 1)
{
linhasAjustadas.Add(line.Substring(0, 12).Insert(12, (fullPath + '\u0022' + ",")));
}
else
{
linhasAjustadas.Add(line.Substring(0, 19).Insert(19, (fullPath + '\u0022' + ",")));
}
}
else if (line.Contains("isDefault") && marcador == 1)
{
linhasAjustadas.Add(line.Replace("false", "true"));
marcador = 0;
}
else
{
linhasAjustadas.Add(line);
}
}
//Irá abrir o arquivo .json e reescrever para exibir a rotina desejada
using (StreamWriter sw = File.CreateText(caminhoJson()))
{
foreach (var linha in linhasAjustadas)
{
sw.WriteLine(linha);
}
}
//Abre Dynamo Player já na função desejada.
AcadApplication acadApp = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
acadApp.ActiveDocument.SendCommand("(command " + (char)34 + "AECCLAUNCHDYNAMOPLAYER" + (char)34 + ")" + " ");
}
catch (System.Exception e)
{
message.MessageBox.Show(e.ToString());
}
}
public string caminhoJson()
{
string caminho = @"C:\Users\" + Environment.UserName + @"\AppData\Local\dynamoplayer-5\2024\User data\DynamoPlayer\AppSettings.json";
return caminho;
}
}
}
How would it be possible to include the path automatically using c# .NET programming?