Author Topic: Dimension Style Families  (Read 1703 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Dimension Style Families
« on: November 15, 2012, 09:28:27 AM »
I have read the ObjectARX SDK:
  • ObjectARX Reference Guide > Additional Information > Dimension Styles > Dimension Style Families
  • ObjectARX Reference Guide > Additional Information > Dimension Styles > Dimension Style Overrides
How can I create the Dimension Style Families (TESTSTYLE$0, TESTSTYLE$2, TESTSTYLE$3, TESTSTYLE$4, TESTSTYLE$6, TESTSTYLE$7) for my base TESTSTYLE through .NET API?

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Dimension Style Families
« Reply #1 on: November 20, 2012, 09:56:07 AM »
If you mean child dimensions

Code: [Select]
public void Dimset()
         {
            archtickId = GetArchtick();// pick what you want
            archtitxtId = Layers.Layers.Lexstyle();
            multipleDims();
        }//End Dimset
        public static ObjectId Lexstyle()
        {
           
            Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable ts = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                if(ts.Has("Lexstyle")) return ts["Lexstyle"];
                TextStyleTableRecord tsr = new TextStyleTableRecord();
                tsr.Name = "Lexstyle";
                tsr.XScale = 0.75;
                tsr.FileName = Getfontfolder() + @"\ARCHITXT.shx";
                ts.UpgradeOpen();
                ts.Add(tsr);
                tr.AddNewlyCreatedDBObject(tsr, true);
                tr.Commit();
                return tsr.Id;
            } //End using
        }  //End Lexstyle

        private static DimStyleTableRecord Setdims(DimStyleTableRecord dimstyle)
        {
            Color green = Color.FromColorIndex(ColorMethod.ByBlock, 3);
            Color byblock = Color.FromColorIndex(ColorMethod.ByBlock, 0);
               
            dimstyle.Dimadec = 1;
            dimstyle.Dimalt=false;
            dimstyle.Dimaltd=0;
            dimstyle.Dimaltf=25.4;
            dimstyle.Dimaltrnd=0;
            dimstyle.Dimalttd=0;
            dimstyle.Dimalttz=0;
            dimstyle.Dimaltu=2;
            dimstyle.Dimaltz=0;
            dimstyle.Dimarcsym=1;
            dimstyle.Dimasz=0.09375;
            dimstyle.Dimatfit= 0;
            dimstyle.Dimaunit=0;
            dimstyle.Dimazin=0;

            dimstyle.Dimblk = archtickId;
            dimstyle.Dimblk1 = archtickId;
            dimstyle.Dimblk2 = archtickId;
         
            dimstyle.Dimcen=0.09375;
            dimstyle.Dimclrd = green;
            dimstyle.Dimclre=green;
            dimstyle.Dimclrt=byblock;
           
            dimstyle.Dimdec=4;
            dimstyle.Dimdle=0.0625;
            dimstyle.Dimdli=0.5625;
            dimstyle.Dimdsep=char.Parse( ".");
           
            dimstyle.Dimexe=0.0625;
            dimstyle.Dimexo=0.0625;
           
            dimstyle.Dimfrac=0;
           
            dimstyle.Dimgap=0.09375;     
            dimstyle.Dimldrblk = ObjectId.Null;
            dimstyle.Dimlfac=1;
            dimstyle.Dimlim=false;
            dimstyle.Dimlunit=4;
            dimstyle.Dimlwd=LineWeight.ByBlock;     
            dimstyle.Dimlwe=LineWeight.ByBlock;
           
            dimstyle.Dimpost="";
            dimstyle.Dimrnd=0;     
           
           
            dimstyle.Dimsah=true;
            dimstyle.Dimscale= 1;
            dimstyle.Dimsd1=false;
            dimstyle.Dimsd2=false;
            dimstyle.Dimse1=false;
            dimstyle.Dimse2=false;
            dimstyle.Dimsoxd=false;
           
            dimstyle.Dimtad=1;
            dimstyle.Dimtdec=4;
            dimstyle.Dimtfac=0.8;
            dimstyle.Dimtih=false;
            dimstyle.Dimtix=false;
            dimstyle.Dimtm=0;
            dimstyle.Dimtmove=0;
            dimstyle.Dimtofl=true;
            dimstyle.Dimtoh=false;
            dimstyle.Dimtol=false;
            dimstyle.Dimtolj=1;
            dimstyle.Dimtp=0;
            dimstyle.Dimtsz=0;
            dimstyle.Dimtxsty = archtitxtId;
            dimstyle.Dimtvp=0;
            dimstyle.Dimtxt=0.125;
            dimstyle.Dimtzin=0;
           
            dimstyle.Dimupt=false;
           
            dimstyle.Dimzin=3;


            if (isMM)
            {
                dimstyle.Dimaltf = (double)   10 / 254;
                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;
            }

            return dimstyle;

        }  //end Setdims






    private void multipleDims()
    {

        Database db = HostApplicationServices.WorkingDatabase;
        string dim = "ARCH";
        string[] sDims;
        int[] iDims;
        int icurrent = 6;
        if (isMM)
        {
            iDims =new int[] { 1, 2, 5, 10, 20, 50, 100 };
            sDims =new string[] { "001", "002", "005", "010", "020", "050", "100" };
            icurrent = 3;
        }
        else
        {
            iDims = new int[] { 1, 2, 4, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 384 };
            sDims = new string[] { "001", "002", "004", "008", "012", "016",
                             "024", "032", "048", "064", "096", "128", "192", "384" };
        }


        for (int i = 0; i < iDims.GetUpperBound(0); i++)
        {
            dim = "ARCH" + sDims[i];
            ObjectId dimId = ObjectId.Null;
            DimStyleTableRecord dstr,existingDstr;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {               
                DimStyleTable dt = tr.GetObject(
                    db.DimStyleTableId, OpenMode.ForWrite) as DimStyleTable;
               
                dstr = new DimStyleTableRecord();
                dstr.Name = dim;
                dstr = Setdims(dstr);
                if (i == 0 || i == 1)
                    dstr.Dimdec = 5;
                dstr.Dimscale = iDims[i];
                if (dt.Has(dim))
                {
                    dimId = dt[dim];
                    existingDstr = tr.GetObject(dimId, OpenMode.ForWrite) as DimStyleTableRecord;
                    existingDstr.CopyFrom(dstr);
                    // goto AlreadyHasIt;
                }
                else
                {
                    dt.Add(dstr);
                    tr.AddNewlyCreatedDBObject(dstr, true);
                    dimId = dstr.ObjectId;
                }
                if (i == icurrent)
                {
                    db.Dimstyle = dimId;
                    db.SetDimstyleData(dstr);
                }
               

            //AlreadyHasIt:
                tr.Commit();
            }
            childDimset(dim, dimId);

        }
    }   //end multipleDims



    private void childDimset(string sDimStyle,ObjectId dimId)
       
    {
        Database db=HostApplicationServices.WorkingDatabase;
        DimStyleTableRecord linear = new DimStyleTableRecord();
        DimStyleTableRecord angular =new  DimStyleTableRecord();
        DimStyleTableRecord diameter =new  DimStyleTableRecord();
        DimStyleTableRecord radial =new  DimStyleTableRecord();
        DimStyleTableRecord leader =new  DimStyleTableRecord();
        DimStyleTableRecord existingDSTR;
        string sDim = sDimStyle + "$0";

        using(Transaction tr=db.TransactionManager.StartTransaction())
        {
            DimStyleTable dt = tr.GetObject
                (db.DimStyleTableId, OpenMode.ForWrite) as DimStyleTable;
           
            using (Transaction tr2 = db.TransactionManager.StartTransaction())
            {
                DimStyleTableRecord dim = tr2.GetObject
                    (dimId, OpenMode.ForWrite) as DimStyleTableRecord;             
                linear.CopyFrom(dim);
                linear.Name = sDim;
                if (dt.Has(sDim))
                {
                    existingDSTR = tr2.GetObject(dt[sDim], OpenMode.ForWrite) as DimStyleTableRecord;
                    existingDSTR.CopyFrom(linear);                     
                }
                else
                {
                    dt.Add(linear);
                    tr2.AddNewlyCreatedDBObject(linear, true);   
                }
                tr2.Commit();
            }

            sDim = sDimStyle + "$2";//Angular
         
            using (Transaction tr2 = db.TransactionManager.StartTransaction())
            {
                angular.CopyFrom(linear);
                angular.Name = sDim;
                angular.Dimatfit = 3;
                angular.Dimblk = ObjectId.Null;
                angular.Dimblk1 = ObjectId.Null;
                angular.Dimblk2 = ObjectId.Null;
                angular.Dimcen = 0;
                angular.Dimdle = 0;
                angular.Dimdli = 0.0625;
                angular.Dimexe = 0.125;
                if (isMM)
                {
                    angular.Dimdli = 1.5;
                    angular.Dimexe = 1.5;
                }
                angular.Dimsah = false;
                angular.Dimtad = 0;
                angular.Dimtih = true;
                angular.Dimtmove = 2;
                angular.Dimtofl = false;
                angular.Dimtoh = true;
                angular.Dimupt = true;


                if (dt.Has(sDim))
                {
                    existingDSTR = tr2.GetObject(dt[sDim], OpenMode.ForWrite) as DimStyleTableRecord;
                    //existingDSTR.CopyFrom(linear);
                    existingDSTR.CopyFrom(angular);
                }
                else
                {
                    dt.Add(angular);
                    tr2.AddNewlyCreatedDBObject(angular, true);                 
                }
                tr2.Commit();
            }

            sDim = sDimStyle + "$3";//Diameter

            using (Transaction tr2 = db.TransactionManager.StartTransaction())
            {         
                diameter.CopyFrom(angular);
                diameter.Name=sDim;
                diameter.Dimadec=1;
                //diameter.Dimatfit=0;
                diameter.Dimatfit = 3;
                diameter.Dimcen = 0;
                //diameter.Dimcen=0.09125;
                //if (isMM) diameter.Dimcen = 2.4;

                diameter.Dimtmove=0;
                if (dt.Has(sDim))
                {
                    DimStyleTableRecord dtr = tr2.GetObject(dt[sDim], OpenMode.ForWrite) as DimStyleTableRecord;
                    dtr.CopyFrom(diameter);
                }
                else
                {
                    dt.Add(diameter);
                    tr2.AddNewlyCreatedDBObject(diameter, true);
                }
                tr2.Commit();
            }

            sDim = sDimStyle + "$4";//Radial
   
            using (Transaction tr2 = db.TransactionManager.StartTransaction())
            {
                radial.CopyFrom(diameter);//Radial
                radial.Name = sDim;
                radial.Dimatfit = 3;
                //radial.Dimcen = 0;
                //radial.Dimtad = 0;
                radial.Dimtih = true;
                //radial.Dimtofl = false;
                //radial.Dimtoh = true;
                if (dt.Has(sDim))
                {
                    DimStyleTableRecord dtr = tr2.GetObject(dt[sDim], OpenMode.ForWrite) as DimStyleTableRecord;
                    dtr.CopyFrom(radial);
                }
                else
                {
                    dt.Add(radial);
                    tr2.AddNewlyCreatedDBObject(radial, true);
                }
                tr2.Commit();
            }
         
            //"$6" is ordinate

            sDim = sDimStyle + "$7";//Leader
            if (!dt.Has(sDim))
            {
                using (Transaction tr2 = db.TransactionManager.StartTransaction())
                {
                    leader.CopyFrom(radial);
                    leader.Name = sDim;
                    leader.Dimtad = 0;

                    dt.Add(leader);
                    tr2.AddNewlyCreatedDBObject(leader, true);
                    tr2.Commit();
                }
            }

            tr.Commit();
        }
    }  //end childDimset

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: Dimension Style Families
« Reply #2 on: November 20, 2012, 11:29:17 AM »
If you mean child dimensions
Yes, I have meaned it. Thank you! Everything appeared more simply than I thought. :)
Code - C#: [Select]
  1. // Now create child dimensions, based on our dimension style
  2. // Read the ObjectARX Reference Guide > Additional Information > Dimension Styles > Dimension Style Families
  3. String[] names = new String[] {
  4.         "$0", //  Linear child style (both rotated and aligned types)  
  5.         "$2", //  Angular child of style (both 2-line and 3-point types)  
  6.         "$3", //  Diameter child of style  
  7.         "$4", //  Radius child of style  
  8.         "$6", //  Ordinate child of style  
  9.         "$7" //  Leader child of style (used for tolerance entities (AcDbFcf) also)  
  10. };
  11. foreach (String item in names) {
  12.         AcDb.DimStyleTableRecord childStyle;
  13.         String childName = dimStyle.Name + item;
  14.         if (dst.Has(childName)) {
  15.                 childStyle = (AcDb.DimStyleTableRecord)tr.GetObject(dst[childName], AcDb.OpenMode.ForWrite);
  16.         }
  17.         else {
  18.                 childStyle = (AcDb.DimStyleTableRecord)dimStyle.Clone();
  19.                 childStyle.Name = childName;
  20.                 dst.Add(childStyle);
  21.                 tr.AddNewlyCreatedDBObject(childStyle, true);
  22.         }
  23. }
  24.  

Can you help me with such questions?
« Last Edit: November 20, 2012, 11:40:59 AM by Andrey »