.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Save some variables into DWG file - how? C#.

22 REPLIES 22
SOLVED
Reply
Message 1 of 23
GrzesiekGP
5767 Views, 22 Replies

Save some variables into DWG file - how? C#.

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.

Tags (2)
22 REPLIES 22
Message 21 of 23
Yehoshua18
in reply to: _gile

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++;
            }
        }

 

 

 

 

 

Message 22 of 23
_gile
in reply to: Yehoshua18

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++;
	}
}

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 23 of 23
Yehoshua18
in reply to: _gile

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!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost