Jump to content

Using a Form Button to run a Mycommands Class Method

Recommended Posts


The following procedure works in the command class to change dimstyle variables.

I can used the command DimStyleChange to change dim style variables.



// public static void CreateModifyDimStyle1(string DimStyleName, out string message)

public void StandardStyleChange()


String DimStyleName;

DimStyleName = "Standard";


// Initialise the message value that gets returned by an exception (or not!)

message = string.Empty;




using (Transaction tr = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction())


Database db = Application.DocumentManager.MdiActiveDocument.Database;

DimStyleTable dst = (DimStyleTable)tr.GetObject(db.DimStyleTableId, OpenMode.ForWrite, true);


// Initialise a DimStyleTableRecord

DimStyleTableRecord dstr = null;

// If the required dimension style exists

if (dst.Has(DimStyleName))


// get the dimension style table record open for writing

dstr = (DimStyleTableRecord)tr.GetObject(dst[DimStyleName], OpenMode.ForWrite);



// Initialise as a new dimension style table record

dstr = new DimStyleTableRecord();


// Set all the available dimension style properties

// Most/all of these match the variables in AutoCAD.

dstr.Name = DimStyleName;




// If the dimension style doesn't exist

if (!dst.Has(DimStyleName))


// Add it to the dimension style table and collect its Id

Object dsId = dst.Add(dstr);

// Add the new dimension style table record to the document

tr.AddNewlyCreatedDBObject(dstr, true);


dstr.Dimasz = 0.1875;//Arrow head size

dstr.Dimscale = 5;//Dim Scale

dstr.Dimtxt = 0.085;//Dim Text size


// Commit the changes.




catch (Autodesk.AutoCAD.Runtime.Exception e)


message = e.Message.ToString();



But when I create a form button and try to start the above method the proceedure

does not make changes. So what should I look at to trouble shoot?


Here is my button code.

private void button7_Click(object sender, EventArgs e)


MyCommands ObjMycommands = new MyCommands();




Thank you,

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now