.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
how to Draw/creat e fillet using .NET ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Now I want to create 4 fillets at each corner with some radius using vb.net
Please somebody help me please
Thanks
dipak Edited by: dip_nik on Jan 13, 2010 11:22 AM
Re: how to Draw/creat e fillet using .NET ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
(spell all prompts)
{code}
using System;
using System.Text;
using System.Collections;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;
namespace CurveMod
{
public class CurveModify
{
[CommandMethod("FLT", CommandFlags.UsePickSet & CommandFlags.Redraw)]
static public void FilletLines()
{
Database db = HostApplicationServices.WorkingDatabase;
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
try
{
// Prompt for the fillet radius
PromptDoubleOptions pdo = new PromptDoubleOptions("\nEnter the fillet radius: ");
pdo.AllowZero = false;
pdo.AllowNegative = false;
pdo.AllowNone = false;
PromptDoubleResult pdr = ed.GetDouble(pdo);
if (pdr.Status != PromptStatus.OK)
return;
double rad = pdr.Value;
// Prompt for the lines to fillet
PromptEntityOptions peo = new PromptEntityOptions("\nSelect first line:");
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
ObjectId fid = per.ObjectId;
peo.Message = "\nSelect second line:";
per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
return;
ObjectId sid = per.ObjectId;
// get entities
Entity ent1 = tr.GetObject(fid, OpenMode.ForRead) as Entity;
Entity ent2 = tr.GetObject(sid, OpenMode.ForRead) as Entity;
// cast entites as lines
Line line1 = ent1 as Line;
Line line2 = ent2 as Line;
Point3dCollection intpts = new Point3dCollection();
// get intersection between lines
line1.IntersectWith(line2, Intersect.OnBothOperands, intpts, 0, 0);
if (intpts.Count != 1)
{
acadApp.ShowAlertDialog("Lines are colinear or does not intersects");
return;
}
Point3d ip = intpts[0];
Point3d midp1;
Point3d midp2;
// compare points
if (!(line1.StartPoint.Equals(ip)))
{
line1.UpgradeOpen();
line1.EndPoint = line1.StartPoint;
line1.StartPoint = ip;
}
midp1 = line1.GetPointAtDist(rad);
if (!(line2.StartPoint.Equals(ip)))
{
line2.UpgradeOpen();
line2.EndPoint = line2.StartPoint;
line2.StartPoint = ip;
}
midp2 = line2.GetPointAtDist(rad);
// get point on bisector
Point3d midp = new Point3d(
(midp1.X + midp2.X) / 2.0,
(midp1.Y + midp2.Y) / 2.0,
(midp1.Z + midp2.Z) / 2.0);
// get angles along lines from intersection
double ang1 = AngleFromX(ip, midp1);
double ang2 = AngleFromX(ip, midp2);
// get bisector angle
double ang = AngleFromX(ip, midp);
// calculate angle between lines
double angc = Math.Abs(ang2 - ang1);
// get a half of them
double bis = angc / 2.0;
// calculate hypotenuse
double hyp = rad / Math.Sin(bis);
// calculate center point of filleting arc
Point3d cp = PolarPoint(ip, ang, hyp);
// calculate another leg of a triangle
double cat = Math.Sqrt((Math.Pow(hyp, 2)) - (Math.Pow(rad, 2)));
// calculate center point on arc
Point3d pa = PolarPoint(ip, ang, hyp - rad);
// calculate start point of arc
Point3d ps = PolarPoint(ip, ang1, cat);
// calculate end point of arc
Point3d pe = PolarPoint(ip, ang2, cat);
// define arc
Arc arc = new Arc();
// check on direction of points
if (isLeft(midp2, ip, midp1))
{
arc = new Arc(cp, rad, AngleFromX(cp, pe), AngleFromX(cp, ps));
}
else
{
arc = new Arc(cp, rad, AngleFromX(cp, ps), AngleFromX(cp, pe));
}
// trim lines by arc
line1.UpgradeOpen();
line1.StartPoint = ps;
line2.UpgradeOpen();
line2.StartPoint = pe;
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
// add arc to space
btr.AppendEntity(arc);
tr.AddNewlyCreatedDBObject(arc, true);
tr.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
acadApp.ShowAlertDialog(ex.Message);
}
}//dispose transaction
}
///
/// Polar point // credit to Tony Tanzillo
///
///
C6309D9E0751D165D0934D0621DFF27919
Re: how to Draw/creat e fillet using .NET ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks a lottttttttt
for the reply.
Have a nice Day
Re: how to Draw/creat e fillet using .NET ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Cheers
~'J'~
C6309D9E0751D165D0934D0621DFF27919
Re: how to Draw/creat e fillet using .NET ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
is there a vb.net version?
thx
Re: how to Draw/creat e fillet using .NET ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
Here is a link that I personally find useful in converting code from C# to VB.Net and vice-versa.
Some basic things will need to be fixed if you get some compile errors.
http://www.developerfusion.com/tools/convert/cshar
Balaji
Developer Technical Services
Autodesk Developer Network
Re: how to Draw/creat e fillet using .NET ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
| <CommandMethod("FilletLines", "FLT", CommandFlags.UsePickSet Or CommandFlags.Redraw)> _ |
| Public Shared Sub FilletLines() |
| Dim db As Database = HostApplicationServices.WorkingDatabase |
| Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.D |
| Dim ed As Editor = doc.Editor |
| Dim tr As Transaction = db.TransactionManager.StartTransaction() |
| Using tr |
| Try |
| ' Prompt for the fillet radius |
| Dim pdo As New PromptDoubleOptions(vbLf & "Enter the fillet radius: ") |
| pdo.AllowZero = False |
| pdo.AllowNegative = False |
| pdo.AllowNone = False |
| Dim pdr As PromptDoubleResult = ed.GetDouble(pdo) |
| If pdr.Status <> PromptStatus.OK Then |
| Return |
| End If |
| Dim rad As Double = pdr.Value |
| ' Prompt for the lines to be filleted |
| Dim peo As New PromptEntityOptions(vbLf & "Select first line:") |
| Dim per As PromptEntityResult = ed.GetEntity(peo) |
| If per.Status <> PromptStatus.OK Then |
| Return |
| End If |
| Dim fid As ObjectId = per.ObjectId |
| peo.Message = vbLf & "Select second line:" |
| per = ed.GetEntity(peo) |
| If per.Status <> PromptStatus.OK Then |
| Return |
| End If |
| Dim sid As ObjectId = per.ObjectId |
| ' get entities |
| Dim ent1 As Entity = TryCast(tr.GetObject(fid, OpenMode.ForRead), Entity) |
| Dim ent2 As Entity = TryCast(tr.GetObject(sid, OpenMode.ForRead), Entity) |
| ' cast entites as lines |
| Dim line1 As Line = TryCast(ent1, Line) |
| Dim line2 As Line = TryCast(ent2, Line) |
| Dim intpts As New Point3dCollection() |
| ' get intersection between lines |
| line1.IntersectWith(line2, Intersect.OnBothOperands, intpts, 0, 0) |
| If intpts.Count <> 1 Then |
| Autodesk.AutoCAD.ApplicationServices.Application.S |
| Return |
| End If |
| Dim ip As Point3d = intpts(0) |
| Dim midp1 As Point3d |
| Dim midp2 As Point3d |
| ' compare points |
| If Not (line1.StartPoint.Equals(ip)) Then |
| line1.UpgradeOpen() |
| line1.EndPoint = line1.StartPoint |
| line1.StartPoint = ip |
| End If |
| midp1 = line1.GetPointAtDist(rad) |
| If Not (line2.StartPoint.Equals(ip)) Then |
| line2.UpgradeOpen() |
| line2.EndPoint = line2.StartPoint |
| line2.StartPoint = ip |
| End If |
| midp2 = line2.GetPointAtDist(rad) |
| ' get point on bisector |
| Dim midp As New Point3d((midp1.X + midp2.X) / 2.0, (midp1.Y + midp2.Y) / 2.0, (midp1.Z + midp2.Z) / 2.0) |
| ' get angles along lines from intersection |
| Dim ang1 As Double = AngleFromX(ip, midp1) |
| Dim ang2 As Double = AngleFromX(ip, midp2) |
| ' get bisector angle |
| Dim ang As Double = AngleFromX(ip, midp) |
| ' calculate angle between lines |
| Dim angc As Double = Math.Abs(ang2 - ang1) |
| ' get a half of them |
| Dim bis As Double = angc / 2.0 |
| ' calculate hypotenuse |
| Dim hyp As Double = rad / Math.Sin(bis) |
| ' calculate center point of filleting arc |
| Dim cp As Point3d = PolarPoint(ip, ang, hyp) |
| ' calculate another leg of a triangle |
| Dim cat As Double = Math.Sqrt((Math.Pow(hyp, 2)) - (Math.Pow(rad, 2))) |
| ' calculate center point on arc |
| Dim pa As Point3d = PolarPoint(ip, ang, hyp - rad) |
| ' calculate start point of arc |
| Dim ps As Point3d = PolarPoint(ip, ang1, cat) |
| ' calculate end point of arc |
| Dim pe As Point3d = PolarPoint(ip, ang2, cat) |
| ' define arc |
| Dim arc As New Arc() |
| ' check on direction of points |
| If isLeft(midp2, ip, midp1) Then |
| arc = New Arc(cp, rad, AngleFromX(cp, pe), AngleFromX(cp, ps)) |
| Else |
| arc = New Arc(cp, rad, AngleFromX(cp, ps), AngleFromX(cp, pe)) |
| End If |
| ' trim lines by arc |
| line1.UpgradeOpen() |
| line1.StartPoint = ps |
| line2.UpgradeOpen() |
| line2.StartPoint = pe |
| Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord) |
| ' add arc to space |
| btr.AppendEntity(arc) |
| tr.AddNewlyCreatedDBObject(arc, True) |
| tr.Commit() |
| Catch ex As Autodesk.AutoCAD.Runtime.Exception |
| Autodesk.AutoCAD.ApplicationServices.Application.S |
| End Try |
| End Using 'dispose transaction |
| End Sub |
C6309D9E0751D165D0934D0621DFF27919
Re: how to Draw/creat e fillet using .NET ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
thx Hallex.
'///
'/// Polar point // credit to Tony Tanzillo
'///
Public Shared Function PolarPoint(ByVal basepoint As Point3d, ByVal angle As Double, ByVal distance As Double) As Point3d
Return New Point3d(basepoint.X + (distance * Math.Cos(angle)), basepoint.Y + (distance * Math.Sin(angle)), basepoint.Z)
End Function
'///
'///
Public Shared Function AngleFromX(ByVal pt1 As Point3d, ByVal pt2 As Point3d) As Double
Dim ang As Double
Dim vec As Vector3d
Dim ucsplane As Plane
ucsplane = New Plane(New Point3d(0, 0, 0), New Vector3d(0, 0, 1))
vec = pt2 - pt1
ang = vec.AngleOnPlane(ucsplane)
Return ang
End Function
'///
'/// isleft function (edited) // credit to Bryco
'///
Public Shared Function isLeft(ByVal spt As Point3d, ByVal ept As Point3d, ByVal apt As Point3d) As Boolean
Dim Ans As Double
Dim result As Boolean
result = False
Ans = ((ept.X - spt.X) * (apt.Y - spt.Y) - (apt.X - spt.X) * (ept.Y - spt.Y))
If (Ans > 0) Then
result = True
Else
result = False
End If
Return result
End Function
Re: how to Draw/creat e fillet using .NET ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
You're welcome
Cheers ![]()
~'J'~
C6309D9E0751D165D0934D0621DFF27919
