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

Value of the angle

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
robsonjmartins
564 Views, 8 Replies

Value of the angle

How can I get the angle of a line as shown in the picture?

 

angle.png

 

if (obj.GetType() == typeof(Line))
        {
 Line linha = (Line)obj; double angulo = linha.Angle; Point3d startPoint = linha.StartPoint; Point3d endPoint = linha.EndPoint; }

 

 

For in my code I techo angle value in double.
Could I have a method return the integer value of the angle?

Robson

8 REPLIES 8
Message 2 of 9

You already have the angle as a double. Have you tried converting the double to an integer? Unless I am misunderstanding what you want, this is really a very basic beginner programming question.

Steven Elliott

When I was a little bitty boy, my grandmother bought me a cute little toy. Silver bells hangin' on a string... she told me it was my ding-a-ling-a-ling!
Message 3 of 9


Could I have a method return the integer value of the angle?

Smiley Happy Yes!

int angInt = (int) angulo;

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 4 of 9

To be completely clear my doubt, I have a " Block Reference " where I walk every entity in search of line with the desired angle.  When I have a line that has 0 degree and 180 degree method returns me to the ralor 1.5707963267948966 and when I have a line that has 90 degrees and 270 degrees the method returns me 0.0.

0_180.png

90_270.png

 

using System;
using System.Collections.Generic;
using System.Text;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;

namespace filter
{
    public class Class1
    {
        [CommandMethod("cotas")]
        public void cotas()
        {
            // Pega o desenho corrente.
            Document documento = Application.DocumentManager.MdiActiveDocument;

            // Abre o banco de dados do desenho atual
            Database bancoDados = documento.Database;

            // Abre o editor do desenho corrente.
            Editor editor = documento.Editor;

            // Inicializa a transação.
            using (Transaction transacao = bancoDados.TransactionManager.StartTransaction())
            {
                // Seta os argumentos do filtro.
                TypedValue[] argumentos = new TypedValue[2];
                argumentos.SetValue(new TypedValue((int)DxfCode.Start, "INSERT"), 0);
                argumentos.SetValue(new TypedValue((int)DxfCode.LayerName, "Dimension"), 1);

                // Cria o filtro passando os dois argumentos para o mesmo.
                SelectionFilter filtro = new SelectionFilter(argumentos);

                // Faz a seleção das entidades no desenho de acordo com o filtro.
                var selecao = editor.SelectAll(filtro).Value.GetObjectIds();

                // Pega a quantidade de entidade selecionada no desenho.
                int qtd = selecao.Length;

                // Verifica se foi feita alguma seleção de entidade no desenho.
                if (qtd > 0)
                {
                    for (int i = 0; i < qtd; i++)
                    {
                        // Pega a id da seleção corrente.
                        ObjectId id = selecao[i];

                        // Pega a id da referência do bloco.
                        BlockReference bRef = (BlockReference)id.GetObject(OpenMode.ForRead);

                        // Pega a id do registro do bloco.
                        BlockTableRecord reg = (BlockTableRecord)bRef.BlockTableRecord.GetObject(OpenMode.ForRead);

                        // Percorre cada entidade do bloco.
                        foreach (ObjectId idEnt in reg)
                        {
                            // Pega a entidade.
                            DBObject obj = (DBObject)idEnt.GetObject(OpenMode.ForRead);

                            // Verifica o tipo de entidade.
                            if (obj.GetType() == typeof(Line))
                            {
                                Line linha = (Line)obj;
                                double angulo = linha.Angle;
                                Point3d startPoint = linha.StartPoint;
                                Point3d endPoint = linha.EndPoint;
                            }
                        }
                    }
                }
            }
        }
    }
}

Robson

 

Message 5 of 9

You can not convert from Radians to Degree?

http://www.vcskicks.com/csharp_net_angles.php

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 6 of 9

There was a mistake on my part that the values ​​mentioned above was because I was taking only the first entity in each block.
And from what I could see this returned value in decimal, the value would be in radians, or simply convert the radian ( radian eg - > degree = 1.5707963267948966 - > 89.99999999987068956723, rounded, 90).

 

Thanks to the help of friends.
Robson

Message 7 of 9

Glad to see you have that cleared up! Now, please mark the response(s) that solved your problem as answers to this topic so that others who have a similar problem and are searching the discussion groups can quickly see what the answer is.

Steven Elliott

When I was a little bitty boy, my grandmother bought me a cute little toy. Silver bells hangin' on a string... she told me it was my ding-a-ling-a-ling!
Message 8 of 9
Anonymous
in reply to: robsonjmartins

Robson, seu interesse com cotas seria para gerar memorial descritivo?

Message 9 of 9

Não amigo,

 

Estou em um projeto onde o objetivo é pegar as cotas que na verdade são blocos exportados de um desenho feito no programa Tekla Structures e transforma-las em cotas reais do AutoCAD.

 

Robson

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