Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: C# Global Variable

  1. #11
    Active Member
    Join Date
    2006-08
    Location
    Brisbane : GMT+10
    Posts
    87
    Login to Give a bone
    0

    Default Re: C# Global Variable

    My statement may have been unclear ... I meant to suggest that you COULD use the same access method as you use for docUI and doc.
    ie:
    Code:
    namespace Projects.QuickVisibility_4.CS
    {
        public partial class VisibilityForm : System.Windows.Forms.Form
        {
            UIDocument 	docUI;
            Document 	doc;
            Category 	catSections;
            Category 	catGrids;
            Category 	catRefplanes;
    
    
            //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;
    
                catSections 	= doc.Settings.Categories.get_Item(BuiltInCategory.OST_Sections);
                catGrids 		= doc.Settings.Categories.get_Item(BuiltInCategory.OST_Grids);
                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;
                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();
            }
        }
    }
    I don't play with Revit so not sure of some of it's pecularities regarding Categories and InitializeComponent();

    also;
    could this
    Code:
                bool sTorF = checkBox1.Checked == true ? true : false;
                curView.setVisibility(catSections, sTorF);
    become this ;
    Code:
                curView.setVisibility(catSections, checkBox1.Checked == true ? true : false);
    Regards

  2. #12
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: C# Global Variable

    Quote Originally Posted by Kerry Brown View Post
    I don't play with Revit so not sure of some of it's pecularities regarding Categories and InitializeComponent();
    I believe that InitializeComponent() is the standard VS generated code for a winform.
    C:> ED WORKING....


    LinkedIn

  3. #13
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    202
    Login to Give a bone
    0

    Default Re: C# Global Variable

    Quote Originally Posted by Kerry Brown View Post
    also;
    could this
    Code:
                bool sTorF = checkBox1.Checked == true ? true : false;
                curView.setVisibility(catSections, sTorF);
    become this ;
    Code:
                curView.setVisibility(catSections, checkBox1.Checked == true ? true : false);
    Regards
    Better (IMO)
    Code:
                curView.setVisibility(catSections, checkBox1.Checked);

  4. #14
    Active Member
    Join Date
    2006-08
    Location
    Brisbane : GMT+10
    Posts
    87
    Login to Give a bone
    0

    Default Re: C# Global Variable

    Yes, of course

  5. #15
    Active Member
    Join Date
    2009-08
    Posts
    93
    Login to Give a bone
    0

    Default Re: C# Global Variable

    Quote Originally Posted by RenderMan View Post
    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?
    It must be contained within a class. You can create static or shared within a project but to accesss it you must use the class like MyClass.MyVariable.

    VB will do things under the hood to mimic global varibles. If you place your variable in a module behind the scences VB adds a imports statement to each file in the project since in VB you can import elements(classes, modules, struct, enums, ....) so it seems you are not accessing the variable through the class but MyVariable will be replaced with MClass.MyVarible when compiled.

  6. #16
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: C# Global Variable

    Quote Originally Posted by Jeff H View Post
    It must be contained within a class. You can create static or shared within a project but to accesss it you must use the class like MyClass.MyVariable.

    VB will do things under the hood to mimic global varibles. If you place your variable in a module behind the scences VB adds a imports statement to each file in the project since in VB you can import elements(classes, modules, struct, enums, ....) so it seems you are not accessing the variable through the class but MyVariable will be replaced with MClass.MyVarible when compiled.
    Jeff, as always, thanks for the clarification.

    This is something that I have done before, despite my earlier confusion; recently in the context of a shared function that resided in my "__.vb" Class which contains many sub-functions, so that calls to this function from other Classes resembled core AutoCAD command line calls such as "__.MySubFunc()". *geek*

    I am really trying to give C# a go - I've already purchased Andrew Treolsen's "Pro C# 2010 and the .NET 4 Platform" at Kerry's recommendation.
    "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

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Grid Scale global variable
    By Wish List System in forum Civil 3D Wish List
    Replies: 0
    Last Post: 2014-09-17, 02:17 PM
  2. Global Variable
    By zoommby in forum Revit - Platform
    Replies: 1
    Last Post: 2012-01-19, 09:14 PM
  3. Global variable/parameter/attribute library?
    By trailbarge in forum AutoCAD General
    Replies: 4
    Last Post: 2009-08-31, 06:49 PM
  4. Variable height/variable count family (studs in a sloped wall)
    By DoTheBIM in forum Revit Architecture - Families
    Replies: 6
    Last Post: 2006-06-15, 02:48 PM
  5. Global scale variable in metric and imperial
    By rolibolibo in forum AutoLISP
    Replies: 2
    Last Post: 2006-02-24, 04:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •