Jump to content

Using a Form Button to run a Mycommands Class Method


Recommended Posts

Posted

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

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

 

[CommandMethod("DimStyleChange")]

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

public void StandardStyleChange()

{

String DimStyleName;

DimStyleName = "Standard";

System.Windows.Forms.MessageBox.Show("Test");

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

message = string.Empty;

 

try

{

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

{

Database db = Application.DocumentManager.MdiActiveDocument.Database;

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

//System.Windows.Forms.MessageBox.Show("Test");

// 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);

}

else

// 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.

tr.Commit();

}

}

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();

ObjMycommands.StandardStyleChange();

 

}

Thank you,

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...