
Этот код должен автоматически обновить чертеж, например с A0 на 3A0. Но код выдает сообщение об ошибке ниже. ==> Основная идея заключается в том, что когда пользователь хочет изменить размер листа, он просто нажимает на новый размер, и код автоматически запускает обновление.
Я работаю на .NET Framework 4.8 (обновление 528372).
Line 225 : 'NXOpen.BlockStyler.PropertyList' does not contain a definition for 'SetStringList' and no extension method 'SetStringList' accepting a first argument of type 'NXOpen.BlockStyler.PropertyList' could be found (are you missing a using directive or an assembly reference?)
Line 264 : ) expected
Line 264 : ; expected
Line 264 : Invalid expression term ')'
Line 264 : ; expected
Line 264 : Invalid expression term ')'
ниже полного кода
using System;
using NXOpen;
using NXOpen.BlockStyler;
using System.Collections.Generic;
public class sDrawing_Size
{
private static Session theSession = null;
private static UI theUI = null;
private string theDlxFileName;
private NXOpen.BlockStyler.BlockDialog theDialog;
private NXOpen.BlockStyler.Group group0;
private NXOpen.BlockStyler.ListBox list_box0;
private static readonly Dictionary DrawingSizes = new Dictionary
{
{ "A0", new Tuple(841, 1189) },
{ "A1", new Tuple(594, 841) },
{ "A2", new Tuple(420, 594) },
{ "A3", new Tuple(297, 420) },
{ "A4", new Tuple(210, 297) },
{ "2A0", new Tuple(1189 * 2, 841) },
};
public sDrawing_Size()
{
try
{
theSession = Session.GetSession();
theUI = UI.GetUI();
theDlxFileName = "C:\\Users\\iennadif\\Desktop\\NX_BLOCK_STYLER\\Drawing_Size.dlx";
theDialog = theUI.CreateDialog(theDlxFileName);
theDialog.AddApplyHandler(new NXOpen.BlockStyler.BlockDialog.Apply(apply_cb));
theDialog.AddOkHandler(new NXOpen.BlockStyler.BlockDialog.Ok(ok_cb));
theDialog.AddUpdateHandler(new NXOpen.BlockStyler.BlockDialog.Update(update_cb));
theDialog.AddInitializeHandler(new NXOpen.BlockStyler.BlockDialog.Initialize(initialize_cb));
theDialog.AddDialogShownHandler(new NXOpen.BlockStyler.BlockDialog.DialogShown(dialogShown_cb));
}
catch (Exception ex)
{
throw ex;
}
}
public static void Main()
{
sDrawing_Size thesDrawing_Size = null;
try
{
thesDrawing_Size = new sDrawing_Size();
thesDrawing_Size.Launch();
}
catch (Exception ex)
{
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
finally
{
if(thesDrawing_Size != null)
{
thesDrawing_Size.Dispose();
thesDrawing_Size = null;
}
}
}
public static int GetUnloadOption(string arg)
{
return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
}
public static void UnloadLibrary(string arg)
{
try
{
// Add any cleanup code here
}
catch (Exception ex)
{
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
}
public NXOpen.BlockStyler.BlockDialog.DialogResponse Launch()
{
try
{
return theDialog.Launch();
}
catch (Exception ex)
{
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
return NXOpen.BlockStyler.BlockDialog.DialogResponse.Cancel;
}
}
public void Dispose()
{
if(theDialog != null)
{
theDialog.Dispose();
theDialog = null;
}
}
public void initialize_cb()
{
try
{
group0 = (NXOpen.BlockStyler.Group)theDialog.TopBlock.FindBlock("group0");
list_box0 = (NXOpen.BlockStyler.ListBox)theDialog.TopBlock.FindBlock("list_box0");
NXOpen.BlockStyler.PropertyList listBoxProps = list_box0.GetProperties();
List items = new List();
foreach (var size in DrawingSizes.Keys)
{
items.Add(size); // Add sizes to the list
}
listBoxProps.SetStringList("ListItems", items.ToArray());
}
catch (Exception ex)
{
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
}
public void dialogShown_cb()
{
// Add any pre-dialog launch logic here
}
public int apply_cb()
{
try
{
NXOpen.BlockStyler.PropertyList listBoxProps = list_box0.GetProperties();
// Assuming "SelectedItems" is a valid property name for the ListBox
var selectedItems = listBoxProps.GetStringList("SelectedItems");
if (selectedItems.Count > 0)
{
string selectedSize = selectedItems[0]; // Get the first selected item
if (DrawingSizes.TryGetValue(selectedSize, out var size))
{
double width = size.Item1;
double height = size.Item2;
// Add logic to set the drawing size in NX here
theUI.NXMessageBox.Show("Drawing Size Updated", NXMessageBox.DialogType.Information,
"Width: " + width + " mm, Height: " + height + " mm");
}
else
{
theUI.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "Invalid drawing size selected.");
}
}
else
{
theUI.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, "No drawing size selected.");
}
}
catch (Exception ex)
{
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
return 1;
}
return 0;
}
public int update_cb(NXOpen.BlockStyler.UIBlock block)
{
try
{
if(block == list_box0)
{
// Add any update logic for list_box0 here
}
}
catch (Exception ex)
{
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
return 0;
}
public int ok_cb()
{
return apply_cb();
}
public PropertyList GetBlockProperties(string blockID)
{
try
{
return theDialog.GetBlockProperties(blockID);
}
catch (Exception ex)
{
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
return null;
}
}
}
найдите ниже ошибку, соответствующую строке основного кода
listBoxProps.SetStringList("ListItems", items.ToArray());
NXOpen.BlockStyler.PropertyList' does not contain a definition for 'SetStringList' and no extension method 'SetStringList' accepting a first argument of type 'NXOpen.BlockStyler.PropertyList' could be found (are you missing a using directive or an assembly reference?)
if (DrawingSizes.TryGetValue(selectedSize, out var size))
: ) expected
: ; expected
: Invalid expression term ')'
: ; expected
: Invalid expression term ')'
: ; expected
else
: Invalid expression term 'else'
: ; expected
Подробнее здесь: https://stackoverflow.com/questions/791 ... elp-please
Мобильная версия