Hello!
Please let me know if I'm able to save some variables into current DWG?
I would like to provide availability for user to save some data which is different for each DWG file.
Thanks.
Solved! Go to Solution.
Hi, I'm not sure how to cast variables into the result buffer type.
This is my settings class I want to store persistently in the DWG:
public class Commands
{
public class Settingsftl
{
public double threshold { get; set; } = 0.05;
public DBObjectCollection allPlines { get; set; }
public void prompttosetoptions()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
PromptDoubleOptions PdblOpts = new PromptDoubleOptions("\n Enter new threshold value");
PdblOpts.DefaultValue = threshold;
PromptDoubleResult bdblResult = doc.Editor.GetDouble(PdblOpts);
threshold = bdblResult.Value;
doc.Editor.WriteMessage("\n Value Chosen is {0}", threshold);
}
}
This is the method I'm trying to use to do this. I'm pretty lost here, I need a better understanding of the fundamentals. Can you help me understand?
public void saveSettings(Settingsftl settingsftl)
{
SetXrecord("SettingsThresh", "1", settingsftl.threshold.ToString);
int i = 1;
foreach (FeatureLine obj in settingsftl.allPlines)
{
SetXrecord("SettingsFeatureLinesList", i.ToString, obj.ObjectId.Handle.ToString);
i++;
}
}
The third argument of the SetXrecord method must be of type ResultBuffer.
public void saveSettings(Settingsftl settingsftl)
{
SetXrecord(
"SettingsThresh",
"1",
new ResultBuffer(new TypedValue((int)DxfCode.Real, settingsftl.threshold)));
int i = 1;
foreach (FeatureLine obj in settingsftl.allPlines)
{
SetXrecord(
"SettingsFeatureLinesList",
i.ToString,
new ResultBuffer(new TypedValue((int)DxfCode.Handle, obj.ObjectId.Handle)));
i++;
}
}
Thanks! That worked splendidly. I figured it all out with your help. I think though, from now on I'm going to use an external csv text file to save persistent information. It's not so user friendly, but it's more elegant I think.
Thank you!