How can I get the angle of a line as shown in the picture?
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
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
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.
Could I have a method return the integer value of the angle?
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
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.
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
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
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
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.
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