.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Export Position Dimension

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
345 Views, 4 Replies

Export Position Dimension

Bom dia,

 

Gostaria de exportar o (cota alinhada) e (dimensão girado), que informação para se destacar?

propriedades
Guia Texto
1. Texto Posição X
2. Posição do Texto Y
3. Medição
4. Substituir texto

 

 

E estar no mesmo LISP, Texto


propriedades
Guia Geral
cor 151
Guia Texto
conteúdo
do texto Alinhamento X
Texto Alinhamento Y

 

 

Alguém pode me ajudar por favor?

 

Atenciosamente
Sidnei Gomes

4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

Good morning,

I would like to export the (aligned dimension) and (rotated dimension), what information to excel?

properties
Text Guide
1. Text Position X
2. Text Position Y
3. Measurement
4. Override Text

And being in the same LISP, Text
properties
General Guide
color 151
Text Guide
contents
Text Alignment X
Text Alignment Y

Can someone help me please?

Best Regards
Sydney Gomes

Message 3 of 5
moogalm
in reply to: Anonymous

Hi Sidnei,

I understand that you want to export said properties to excel file.
I have written a sample code which can be used as boiler plate code to export required properties to CSV ,
which you can open in a excel sheet.


SampleCode:

[CommandMethod("DimensionExport")]

        public void Test_cmd2()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var dimensionId = ObjectId.Null;
            var psr = ed.GetSelection();
            if (psr.Status != PromptStatus.OK) return;
            if (psr.Value.Count == 1)
            {
                var selId = psr.Value[0].ObjectId;
                if (selId.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Dimension))))
                {
                    dimensionId = selId;
                }
            }
            if (dimensionId == ObjectId.Null)
            {
                var peo = new PromptEntityOptions("\nSelect a Dimension Entity");
                peo.SetRejectMessage("\nEntity is not a Dimension Entity.");
                peo.AddAllowedClass(typeof(Dimension), false);
                var per = ed.GetEntity(peo);
                if (per.Status != PromptStatus.OK)
                    return;
                dimensionId = per.ObjectId;
            }
            var psfo = new PromptSaveFileOptions("Export Data");
            psfo.Filter = "Comma Delimited (*.csv)|*.csv";
            var pr = ed.GetFileNameForSave(psfo);
            if (pr.Status != PromptStatus.OK)
                return;
            var csv = pr.StringResult;
            // Our main StringBuilder to get the overall CSV contents
            var sb = new StringBuilder();
            using (var t = db.TransactionManager.StartTransaction())
            {
                AlignedDimension aDim = t.GetObject(dimensionId, OpenMode.ForRead) as AlignedDimension;
                //  var sb2 = new StringBuilder();
                var colortext = aDim.Color.ToString();
                sb.Append(colortext);
                sb.AppendLine();
                var dimStyleName = aDim.DimensionStyleName;
                sb.Append(dimStyleName);
                sb.AppendLine();
                var dimText = aDim.DimensionText;
                sb.Append(dimText);
                sb.AppendLine();
                /*You can append required properties to the string builder and export those to CSV stream*/
                //
                //
                //
                t.Commit();
            }

            var contents = sb.ToString();
            if (!String.IsNullOrWhiteSpace(contents))
            {
                try
                {
                    // Write the contents to the selected CSV file
                    using (var sw = new StreamWriter(csv, false, Encoding.UTF8))
                    {
                        sw.WriteLine(sb.ToString());
                    }
                }
                catch (System.IO.IOException)
                {
                    // We might have an exception, if the CSV is open in
                    // Excel, for instance... could also show a messagebox
                    ed.WriteMessage("\nUnable to write to file.");
                }
            }
        }

 

 

Posted by: Madhukar Moogala

Contact information: madhukar.moogala@autodesk.com.

Message 4 of 5
moogalm
in reply to: Anonymous

Hi Sidnei,

 

I understand that you want to export said properties to excel file.<br>
I have written a sample code which can be used as boiler plate code to export required properties to CSV ,<br>
which you can open in a excel sheet.

 

Sample Code :

[CommandMethod("DimensionExport")]
        public void Test_cmd2()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var dimensionId = ObjectId.Null;
            var psr = ed.GetSelection();
            if (psr.Status != PromptStatus.OK) return;
            if (psr.Value.Count == 1)
            {
                var selId = psr.Value[0].ObjectId;
                if (selId.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Dimension))))
                {
                    dimensionId = selId;
                }
            }
            if (dimensionId == ObjectId.Null)
            {
                var peo = new PromptEntityOptions("\nSelect a Dimension Entity");
                peo.SetRejectMessage("\nEntity is not a Dimension Entity.");
                peo.AddAllowedClass(typeof(Dimension), false);
                var per = ed.GetEntity(peo);
                if (per.Status != PromptStatus.OK)
                    return;
                dimensionId = per.ObjectId;
            }
            var psfo = new PromptSaveFileOptions("Export Data");
            psfo.Filter = "Comma Delimited (*.csv)|*.csv";
            var pr = ed.GetFileNameForSave(psfo);
            if (pr.Status != PromptStatus.OK)
                return;
            var csv = pr.StringResult;
            // Our main StringBuilder to get the overall CSV contents
            var sb = new StringBuilder();
            using (var t = db.TransactionManager.StartTransaction())
            {
                AlignedDimension aDim = t.GetObject(dimensionId, OpenMode.ForRead) as AlignedDimension;
                //  var sb2 = new StringBuilder();
                var colortext = aDim.Color.ToString();
                sb.Append(colortext);
                sb.AppendLine();
                var dimStyleName = aDim.DimensionStyleName;
                sb.Append(dimStyleName);
                sb.AppendLine();
                var dimText = aDim.DimensionText;
                sb.Append(dimText);
                sb.AppendLine();
                /*You can append required properties to the string builder and export those to CSV stream*/
                //
                //
                //
                t.Commit();
            }

            var contents = sb.ToString();
            if (!String.IsNullOrWhiteSpace(contents))
            {
                try
                {
                    // Write the contents to the selected CSV file
                    using (var sw = new StreamWriter(csv, false, Encoding.UTF8))
                    {
                        sw.WriteLine(sb.ToString());
                    }
                }
                catch (System.IO.IOException)
                {
                    // We might have an exception, if the CSV is open in
                    // Excel, for instance... could also show a messagebox
                    ed.WriteMessage("\nUnable to write to file.");
                }
            }
        }

 Thanks,

Madhukar

Message 5 of 5
Anonymous
in reply to: moogalm

I will check, Thanks

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost