Author Topic: Create A New Dimension Style  (Read 1532 times)

0 Members and 1 Guest are viewing this topic.

SOURCECODE

  • Guest
Create A New Dimension Style
« on: November 29, 2011, 04:05:34 PM »
I am Trying to create a new Dimension Style but I dont know where to get the properties such as
Text Height, Arrow Size etc etc.

Here is my code so far

What do I need to add so that I can access the Dimension Style Properties

 
Code: [Select]
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
        Dim db As Database = doc.Database
        Dim ed As Editor = doc.Editor
        Using trx As Transaction = db.TransactionManager.StartTransaction()
            Dim dimTbl As DimStyleTable = trx.GetObject(db.DimStyleTableId, OpenMode.ForRead)

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Create A New Dimension Style
« Reply #1 on: November 29, 2011, 04:32:19 PM »
Have you looked in the docs?
 

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Create A New Dimension Style
« Reply #2 on: November 30, 2011, 01:05:34 AM »
Code: [Select]
    public static ObjectId AddStandardDimstyle()
    {
        Document doc=acadApp.DocumentManager.MdiActiveDocument;
        Editor ed=doc.Editor;
        Database db=doc.Database;       
        DimStyleTableRecord dimstyle = new DimStyleTableRecord();

        using(Transaction tr=db.TransactionManager.StartTransaction())
        {
            DimStyleTable dt = tr.GetObject
                (db.DimStyleTableId, OpenMode.ForRead) as DimStyleTable;
            if(dt.Has("Standard")) return dt["Standard"];
        }

        dimstyle.Name = "Standard";
        Color byblock = Color.FromColorIndex(ColorMethod.ByBlock, 0);

        dimstyle.Dimadec = 0;
        dimstyle.Dimalt = false;
        dimstyle.Dimaltd = 2;
        dimstyle.Dimaltf = 25.4;
        dimstyle.Dimaltrnd = 0.0;
        dimstyle.Dimalttd =2;
        dimstyle.Dimalttz = 0;
        dimstyle.Dimaltu = 2;
        dimstyle.Dimaltz = 0;
        dimstyle.Dimapost = "";
        dimstyle.Dimarcsym = 0;
        dimstyle.Dimasz = 0.18;
        dimstyle.Dimatfit = 3;
        dimstyle.Dimaunit = 0;
        dimstyle.Dimazin = 0;

        dimstyle.Dimblk = ObjectId.Null;
        dimstyle.Dimblk1 = ObjectId.Null;
        dimstyle.Dimblk2 = ObjectId.Null;

        dimstyle.Dimcen = 0.09;
        dimstyle.Dimclrd = Color.FromColorIndex(ColorMethod.ByBlock,0);
        dimstyle.Dimclre = Color.FromColorIndex(ColorMethod.ByBlock, 0);
        dimstyle.Dimclrt = Color.FromColorIndex(ColorMethod.ByBlock, 0); ;

        dimstyle.Dimdec = 4;
        dimstyle.Dimdle = 0.0;
        dimstyle.Dimdli = 0.3800;
        dimstyle.Dimdsep = char.Parse(".");

        dimstyle.Dimexe = 0.18;
        dimstyle.Dimexo = 0.0625;

        dimstyle.Dimfrac = 0;

        dimstyle.Dimgap = 0.09;
        dimstyle.Dimldrblk = ObjectId.Null;
        dimstyle.Dimlfac = 1.0;
        dimstyle.Dimlim = false;
        dimstyle.Dimltype = db.ByBlockLinetype;
        dimstyle.Dimlunit = 2;
        dimstyle.Dimlwd = LineWeight.ByBlock;
        dimstyle.Dimlwe = LineWeight.ByBlock;

        dimstyle.Dimpost = "";
        dimstyle.Dimrnd = 0.0;


        dimstyle.Dimsah = true;
        dimstyle.Dimscale = 1;
        dimstyle.Dimsd1 = false;
        dimstyle.Dimsd2 = false;
        dimstyle.Dimse1 = false;
        dimstyle.Dimse2 = false;
        dimstyle.Dimsoxd = false;

        dimstyle.Dimtad = 0;
        dimstyle.Dimtdec = 4;
        dimstyle.Dimltex1 = db.ByBlockLinetype;
        dimstyle.Dimltex2 = db.ByBlockLinetype;
        dimstyle.Dimtxtdirection = false;

        dimstyle.Dimtfac = 1.0;
        dimstyle.Dimtih = true;
        dimstyle.Dimtix = false;
        dimstyle.Dimtm = 0.0;
        dimstyle.Dimtmove = 0;
        dimstyle.Dimtofl = false;
        dimstyle.Dimtoh = true;
        dimstyle.Dimtol = false;
        dimstyle.Dimtolj = 1;
        dimstyle.Dimtp = 0.0;
        dimstyle.Dimtsz = 0.0;
        dimstyle.Dimtxsty =Layers.Layers.StandardTextStyle();
        dimstyle.Dimtvp = 0.0;
        dimstyle.Dimtxt = 0.18;
        dimstyle.Dimtzin = 0;

        dimstyle.Dimupt = false;

        dimstyle.Dimzin = 0;


        if (isMM)
        {
            dimstyle.Dimaltf = (double)10 / 254.0;
            dimstyle.Dimasz = 2.4;
            dimstyle.Dimcen = 2.4;
            dimstyle.Dimdec = 1;
            dimstyle.Dimdle = 1.5;
            dimstyle.Dimdli = 13;
            dimstyle.Dimexe = 1.5;
            dimstyle.Dimexo = 1.5;
            dimstyle.Dimgap = 2.4;
            dimstyle.Dimlunit = 2;
            dimstyle.Dimtdec = 0;
            dimstyle.Dimtxt = 3;
        }

        ObjectId id=ObjectId.Null;
        using (Transaction tr = db.TransactionManager.StartTransaction())
        {
            DimStyleTable dt = tr.GetObject
                (db.DimStyleTableId, OpenMode.ForWrite) as DimStyleTable;
            id= dt.Add(dimstyle);
            tr.AddNewlyCreatedDBObject(dimstyle, true);

            tr.Commit();
        }
       
        return id;

    }  //end

SOURCECODE

  • Guest
Re: Create A New Dimension Style
« Reply #3 on: November 30, 2011, 10:41:58 AM »
Thanks again Jeff.

Thanks also Bryco I used your code but I am getting a few errors
   
"'Layers' is not declared. It may be inaccessible due to its protection level."
'isMM' is not declared. It may be inaccessible due to its protection level."

How do I clear these errors


Bryco

  • Water Moccasin
  • Posts: 1883
Re: Create A New Dimension Style
« Reply #4 on: November 30, 2011, 03:44:10 PM »
isMM is a sub to check if the drawing is metric, if so those settings need to be used. Delete all that.

If you want to set the textstyle you need to supply the objectid of the textstyle you want to use
dimstyle.Dimtxsty =yourobjectId;
else delete that line