How do I defile a global variable in C#? Thanks.
|
"How we think determines what we do, and what we do determines what we get."
Sincpac C3D ~ Autodesk Exchange Apps
Computer Specs:
Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000
What is your definition of 'Global'
ie : how long to you want to keep the value
and what do you want to access it from,
and will it be local to a document or to the application ?
You could save it to the Lisp environment, save it to file or the registry, or a couple of other methods, depending on the answers.
As Jeff said, C# does not have a globally accessable memory block that can be accessed from disparate programs/assemblies.
Regards
Kerry / Jeff -
I did not know this about C#, does VB.NET also suffer this shortcoming? I thought that was the point of using a Namespace within an Assembly, to allow for defining of variables, Classes, Properties, etc. without the risk of creating a conflict between Namespaces, no?
"How we think determines what we do, and what we do determines what we get."
Sincpac C3D ~ Autodesk Exchange Apps
Computer Specs:
Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000
Thanks for the hint Ed, unfortunately for me though, most of what Kerry, the Jeff's (M & H), Gile, Dgorsman (and the like) post is usually above my ahead. Don't even get me started on TheMaster (Mr. T)! LoL
"How we think determines what we do, and what we do determines what we get."
Sincpac C3D ~ Autodesk Exchange Apps
Computer Specs:
Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000
I'm trying to clean up the following code. In fact, there may be an easier way to accomplish what i'm doing, but this is where i'm at. I would like to define the categories once and reference them. One problem is they are dependent on the 'commandData'. Thoughts? Thanks.
Code:namespace Projects.QuickVisibility_4.CS { public partial class VisibilityForm : System.Windows.Forms.Form { UIDocument docUI; Document doc; //Check category visibility in the view and populate the checkbox public VisibilityForm(ExternalCommandData commandData) { docUI = commandData.Application.ActiveUIDocument; doc = commandData.Application.ActiveUIDocument.Document; RvtView curView = doc.ActiveView; Category catSections = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Sections); Category catGrids = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Grids); Category catRefplanes = doc.Settings.Categories.get_Item(BuiltInCategory.OST_CLines); InitializeComponent(); bool sectionVis = curView.getVisibility(catSections); checkBox1.Checked = sectionVis == true ? true : false; bool gridVis = curView.getVisibility(catGrids); checkBox2.Checked = gridVis == true ? true : false; bool refplaneVis = curView.getVisibility(catRefplanes); checkBox3.Checked = refplaneVis == true ? true : false; } //Get checkbox value and set visibilty in the view private void button1_Click(object sender, EventArgs e) { RvtView curView = doc.ActiveView; Category catSections = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Sections); Category catGrids = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Grids); Category catRefplanes = doc.Settings.Categories.get_Item(BuiltInCategory.OST_CLines); Transaction trans = new Transaction(doc); trans.Start("Hide or Unhide"); bool sTorF = checkBox1.Checked == true ? true : false; curView.setVisibility(catSections, sTorF); bool gTorF = checkBox2.Checked == true ? true : false; curView.setVisibility(catGrids, gTorF); bool rTorF = checkBox3.Checked == true ? true : false; curView.setVisibility(catRefplanes, rTorF); trans.Commit(); } } }
Bryan,
Is what you want to do different to the way you've declared and initialise the variables docUi and doc ??
BTW.
Naming the method the same name as the class is not usual practice.
Usually a class is a noun, a Method is a verb
ref: http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx
Yes, doing the variables docUi and doc differently would be nice also, what are my options? But really I was trying to not have to define categories two times.