Author Topic: How to edit block parameters from a windows form (c#)?  (Read 769 times)

0 Members and 1 Guest are viewing this topic.

Offline JohannesRP

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
  • Gender: Male
    • prefered language: C
    • Prog expertise: Good
    • View Profile
How to edit block parameters from a windows form (c#)?
« on: January 17, 2013, 04:13:34 PM »
Hi, i try to change several dynamic blocks using my own application. I have a com connection with AuotCAD 2013 and i can run through all block definitions.
When i run through the block def. in AutoCad i can identify the one i want to change the parameters. But how to continue? How can i set the "heightLeft" to another value?

Code: [Select]
private void bt_openTemplate_Click(object sender, EventArgs e)
        {
            AcadApplication acadApp = null;
            AcadBlocks acadblock = null;
           
            try
            {
                object obj = Marshal.GetActiveObject("AutoCAD.Application.19");
               
                if (obj != null)
                {
                    acadApp = obj as AcadApplication;
                    acadblock = acadApp.ActiveDocument.Blocks;

                    string name = "";

                    foreach (AcadBlock  b in acadblock)
                    {
                        name = name + " :: " + b.Name;

                        if (b.Name == "WT")
                        {
                           
// HELP!!!
// Here i need to change the properties of the block with name "WT"
                           
                        }
                    }
                    tb.Text = name;
                }
                else
                {
                    MessageBox.Show("AutoCAD is not open or version is not right.");
                }
            }
            catch
            {
                MessageBox.Show("AutoCAD is not open or version is not right.");
            }
        }
    }


The main idea is to change several blocks at the same time by changing only one value in my application.

regards
Johannes

Offline fixo

  • Full Member
  • ***
  • Posts: 135
  • Karma: +4/-0
  • Gender: Male
    • prefered language: C
    • Prog expertise: Good
    • View Profile
Re: How to edit block parameters from a windows form (c#)?
« Reply #1 on: January 22, 2013, 08:32:28 PM »
Sorry for the belating JohannesRP,
You can use something like this, tested on my A2010 with good result
Code: [Select]
                    if (b.Name == "WT")
                        {
// HELP!!!
// Here i need to change the properties of the block with name "WT"
                            foreach (object item in b)
                            {
                                Autodesk.AutoCAD.Interop.Common.AcadLine ln = item as Autodesk.AutoCAD.Interop.Common.AcadLine;
                                if (ln != null)
                                {
                                    ln.Linetype = "Center";
                                    ln.LinetypeScale = 0.01;
                                    Autodesk.AutoCAD.Interop.Common.AcadAcCmColor acCol = ln.TrueColor;
                                    acCol.ColorIndex = Autodesk.AutoCAD.Interop.Common.AcColor.acCyan;
                                    ln.TrueColor = acCol;
                                }
                            }                         
                        }