Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8676189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:07:55+00:00 2026-06-12T20:07:55+00:00

I am trying to write data to a file and the code below includes

  • 0

I am trying to write data to a file and the code below includes a writer method which allows to override the write() method of the base class GH_Component. The code compiles with no erros but the data does not get written as planned. What am i doing wrong?

         public class SettingsComponent : GH_Component

       {
            public SettingsComponent(): base("LoadSettings", "LoadSettings", "Loading ini", "Extra", "Silkworm") { }

            public override void CreateAttributes()
            {
                m_attributes = new SettingsComponentAttributes(this);
            }

            string m_settings_temp;
            string[] m_settings;

            public void ShowSettingsGui()
            {
                var dialog = new OpenFileDialog { Filter = "Data Sources (*.ini)|*.ini*|All Files|*.*" };
                if (dialog.ShowDialog() != DialogResult.OK) return;

                m_settings_temp = File.ReadAllText(dialog.FileName);
                m_settings = m_settings_temp.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                ExpireSolution(true);
            }


            public override bool Read(GH_IO.Serialization.GH_IReader reader)
            {
                if (m_settings != null && m_settings.Length > 0)
                {
                    Int32 a = m_settings.Length;
                    reader.TryGetInt32("StringCount", ref a);
                    for (int i = 0; i < m_settings.Length; i++)
                    {
                        reader.TryGetString("String", i, ref m_settings[i]);
                    }
                }
                return base.Read(reader);
            }


            public override bool Write(GH_IO.Serialization.GH_IWriter writer)
            {
                if (m_settings != null && m_settings.Length > 0)
                {
                    writer.SetInt32("StringCount", m_settings.Length);
                    for (int i = 0; i < m_settings.Length; i++)
                    {
                        writer.SetString("String", i, m_settings[i]);
                    }
                }
                return base.Write(writer);
            }



            protected override void SolveInstance(IGH_DataAccess DA)
            {
                if (m_settings == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "You must declare some valid settings");
                    return;
                }
                else
                {
                   DA.SetDataList(0, m_settings);
                }      
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:07:56+00:00Added an answer on June 12, 2026 at 8:07 pm

    I needed to override the Write() and Read() methods on GH_Component:

     //deserializes the variable m_settings to make the data persistant
            public override bool Write(GH_IWriter writer)
            {
                if (m_settings != null && m_settings.Length > 0)
                {
                    writer.SetInt32("StringCount", m_settings.Length);
                    for (int i = 0; i < m_settings.Length; i++)
                    {
                        writer.SetString("String", i, m_settings[i]);
                    }
                }
    
                return base.Write(writer);
            }
    
            //deserializes the variable m_settings to make the data persistant
            public override bool Read(GH_IReader reader)
            {
                m_settings = null;
    
                int count = 0;
                reader.TryGetInt32("StringCount", ref count);
                if (count > 0)
                {
                    System.Array.Resize(ref m_settings, count);
                    for (int i = 0; i < count; i++)
                    {
                        string line = null;
                        reader.TryGetString("String", i, ref line);
                        m_settings[i] = line;
                    }
                }
    
                return base.Read(reader);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to write image data to a text file as a base 64
I am trying to write data stored in a binary file using turbo C++.
I want to write data into the file in binary form. I was trying
I am trying to write my spatial data from a table to a file.
I'm trying to write an xml file with utf-8 encoded data using ElementTree like
I'm trying to write an extension method to insert data into a dictionary of
I've been trying to write data back to a pre-defined plist file (data.plist) in
I am new to JSP and I am trying to write the below code:
I am trying to write data to a php file everytime the page is
I'm trying to write some code to look through an image file for groups

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.