Jump to content

Making AutoCAD C# Variables public in a form.


muck

Recommended Posts

I have the statement.

 

Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

in a form routine.

 

I would like to be able to use acDoc in all my form routines. How do I make acDoc usable within my form?

 

Thank you,

Link to comment
Share on other sites

A simple way is to add a parameter in the constructor and pass it in.

 

 

public AcadForm(Document acDoc )

{

 

 

}

Link to comment
Share on other sites

Could you give me a better more complete example?

I am somewhat new to this. I don't even know what a constructor is?

Thank you,

Link to comment
Share on other sites

Could you give me a better more complete example?

I am somewhat new to this. I don't even know what a constructor is?

 

More complete examples often follow the posting of the code you're having trouble with. :thumbsup:

 

 

 

Your plug-in exists within a Namespace, which implements Classes (aka Types), which provide Properties, Methods, and Events. A Constructor 'builds' or instantiates an instance of the Class (Type), and can be Overloaded (provide more than one Method, each accepting a different set of parameter, if any at all).

 

Since you didn't post code, I can only speculate that you call your Form within a particular Method, simply add a Form Constructor, which accepts 'Document acDoc' as parameter within your Form's Class, and then pass it along:

 

Pseudo-code:

// <snip>

Document acDoc = acDocs.MdiActiveDocument;

MyForm myForm = new MyForm(acDoc);

//<-- do something useful

// <snip>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...