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

C# Draw Arc with 3 points

16 REPLIES 16
Reply
Message 1 of 17
newbie1221
6227 Views, 16 Replies

C# Draw Arc with 3 points

please help me, I'm trying to find a way to draw an Arc with 3 points but i can't.

here is parth of the code, (AddArc) method only accepts starting angle, end angle, radius, center point
I want to enter 3 points that define the Arc

AcadModelSpace mod;
mod.AddArc(p1, 23.4, 0, 180);

please Help
Thank you
16 REPLIES 16
Message 2 of 17
jbooth
in reply to: newbie1221

Since you are using COM interop I would suggest you visit the VBA forums for help in the future.

To answer your question, you could use the AutoCad command prompt using SendCommand() but I would advise against it (unless you absolutely have to).

If the addarc() function only takes those 3 arguments, you will probably have no choice but to calculate what those three arguments should be, and feed them to AutoCad in the manner it expects. You could also create a dummy arc and modify its properties, but again you would need to calculate those said properties on your own (radius, angles, etc...).

ie: Calculate your start/end angles, ctr pt, and radius and use those to define your arc in the format that AutoCad expects. If you do not want to handle the math, you will have to send text to the AutoCad command line through a script.
Message 3 of 17
Anonymous
in reply to: newbie1221

Hi Jason,

What is the point of a poster using .NET with the COM interop trying to get
help in the VBA newsgroup? Users there will see C# and refer them back
here. This is the NG for programming using .NET and should be so regardless
of the methods used within .NET


--


Regards

Laurie Comerford


wrote in message news:5838476@discussion.autodesk.com...
Since you are using COM interop I would suggest you visit the VBA forums for
help in the future.

To answer your question, you could use the AutoCad command prompt using
SendCommand() but I would advise against it (unless you absolutely have to).

If the addarc() function only takes those 3 arguments, you will probably
have no choice but to calculate what those three arguments should be, and
feed them to AutoCad in the manner it expects. You could also create a dummy
arc and modify its properties, but again you would need to calculate those
said properties on your own (radius, angles, etc...).

ie: Calculate your start/end angles, ctr pt, and radius and use those to
define your arc in the format that AutoCad expects. If you do not want to
handle the math, you will have to send text to the AutoCad command line
through a script.
Message 4 of 17
jbooth
in reply to: newbie1221

I didn't notice right away that his sample code was in C#.

However, on that subject, the other forum has much more info about the COM API that directly applies to questions like these. Most of the knowledge here seems to be biased towards the ObjectArx .NET libraries instead. Therefore the VBA forums is still a better place to look when interacting with the COM library, even when you need to translate any solutions you find into C#.

My comment was not meant to be a "stay out of this forum" post. It was more of a "here is better place to search for a solution".

ps: You like jumping on people, don't you?
Message 5 of 17
NathTay
in reply to: newbie1221

It's all about the API. All users in the VBA group use the ActiveX API. This includes VB6 and Delphi (have you ever told them to get lost) users. The users in this group predominantly use the .NET API. Therefore the OP might be more likely to get help in the VBA group if the users can see past the language he is using.

In this group there are both VB.NET & C# users using the .NET API . The fact they are using different languages has not stopped them help each other on the real purpose of this group the .NET API.
Message 6 of 17
newbie1221
in reply to: newbie1221

Thank you so much, Jason
I'm a Programmer and I'm just starting to learn more about Programming for AutoCAD.

Is there a better way to Program for AutoCAD rather than using COM interop, I saw some Database work like Commit() ,and Stuff? I tried looking at samples it all make sense but I always get FILENOTFOUND Execption just if I used anything in these NameSpaces:
Autodesk.AutoCAD.Geometry
Autodesk.AutoCAD.DatabaseServices
Although I added the 2references:
acdbmgd.dll
acmgd.dll

Any Tips?


Thanx again for your Help :) Message was edited by: Newbie1221
Message 7 of 17
NathTay
in reply to: newbie1221

2005 had a very limited .NET API. If you have 2006 onwards checkout http://through-the-interface.typepad.com/through_the_interface/2007/11/devtv-introduct.html
Message 8 of 17
jbooth
in reply to: newbie1221

http://usa.autodesk.com/adsk/servlet/index?id=1911627&siteID=123112

There should be links to documentation directly related to programming with the .NET arx API. Also look at the C++ documentation for ObjectArx, as I think there were some .NET samples hidden in the package you can download.

Also, Nathan is right about the "Through the interface" blogs. They have some great info.

As a last resort, you can search these forums.. The posts about how to set up a project that uses the arx.NET API are old, but they should still be here (they are what I used to get started).

Good luck.
Message 9 of 17
newbie1221
in reply to: newbie1221

Thank you all for the tips, Indeed those were very helpful :))
Message 10 of 17
Anonymous
in reply to: newbie1221

If you want to use the managed API (which means that you are building a NETLOAD-able DLL, not an .EXE), this is probably the easiest way to do what you need, without having to do the geometry calculations:

Using Autodesk.AutoCAD.Geometry;

Point3d startPoint = //... start point of the arc
Point3d pointOnArc = //... any point on the arc segment
Point3d endPoint = //... end point of the arc

CircularArc3d arc = new CircularArc3d( startPoint, pointOnArc, endPoint );

From there, you can query the properties of the CircularArc3d for its center, radius, and start/end angles, and use them to create an Arc entity.

If you've never used the managed ObjectARX API before, then be forewarned that it is not easy to learn (it can take years to learn it to the extent needed to develop real applications).

You can ease your way into the managed API gradually by using it in conjunction with ActiveX (your problem is a good example of that, because you can create the ARC through ActiveX, but use the managed API to do the needed calculations).

And contrary to what Laurie says, we generally don't link programming languages to APIs here. This newsgroup focuses mainly on using the managed ObjectARX API without regard for langauge. For ActiveX, your best bet is the VBA newsgroup because syntax differences aside, the API is the same regardless of what langauge you use.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5838744@discussion.autodesk.com...
Thank you all for the tips, Indeed those were very helpful :))
Message 11 of 17
newbie1221
in reply to: newbie1221

Thanx Tony 🙂
Message 12 of 17
Anonymous
in reply to: newbie1221

My Lord! Jason. It's in the subject line, as clear as day.

Seriously, how much weight do you expect your replies to carry when it's blatantly obvious that you're to lazy to even read a simple sentence? No, go on, tell me? How much?

You say 'seems'. So you don't really know, do you?
I think our just jumping on a bandwagon the Nathan seems to be driving. Step back off it.

P.S. Yes. i am jumping on you. With boots on.

Dave F.
Message 13 of 17
NathTay
in reply to: newbie1221

I'm not driving any bandwagon just pointing out facts in response to Laurie's bandwagon. You seem to have nothing intelligent to add (do you ever?) so you go mental over a simple thing as not reading a title. How much weight can we hold to your posts if you are that small of a man? No, go on, tell me? How much?
Message 14 of 17
Anonymous
in reply to: newbie1221

Nathan Taylor wrote:
> I'm not driving any bandwagon just pointing out facts in response to Laurie's bandwagon.

>You seem to have nothing intelligent to add (do you ever?)
Occasionally.
>so you go mental over a simple thing as not reading a title.
>How much weight can we hold to your posts if you are that small of a man?
>No, go on, tell me? How much?

I've never, repeat never, _expect_ my posts to carry any weight. I'll leave that to the arrogance of others. I simply reply to questions I know the
answers too. After I've read the question of course.

I get irritated by the time I (& others) have wasted whilst learning how to program by taking 'advice' from lazy posters who think they know it all,
but can't even be bothered to take the time to read the actual problem. Such as what's typed in the subject line.

Failing to do so fully, is just plain rude.

Dave F.
Message 15 of 17
NathTay
in reply to: newbie1221

>>Failing to do so fully, is just plain rude.

Or possibly an oversight with absolutely no intention of being rude unlike you.
Message 16 of 17
Anonymous
in reply to: newbie1221

Here is thee working code:

Public Shared Sub DrawArc3Points()
Dim doc As Document = AcApp.DocumentManager.MdiActiveDocument
Dim docklock As DocumentLock = doc.LockDocument()
Dim db As Database = HostApplicationServices.WorkingDatabase()
Dim ed As Editor = doc.Editor()
Using tr As Transaction = db.TransactionManager.StartTransaction
Try
Dim p1 As Point3d = ed.GetPoint(ControlChars.CrLf & "Specify first point of an arc (keep the counterclockwise order): ").Value
Dim opt As New PromptPointOptions(ControlChars.CrLf & "Specify second point of an arc:")
opt.AllowNone = False
opt.UseDashedLine = True
opt.BasePoint = p1
Dim p2 As Point3d = ed.GetPoint(opt).Value
opt.BasePoint = p2
opt.Message = ControlChars.CrLf & "Specify last point of an arc: "
Dim p3 As Point3d = ed.GetPoint(opt).Value
Dim carc As CircularArc3d = New CircularArc3d(p1, p2, p3)
Dim arc As Arc = ConvertToArc(carc)
Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
btr.AppendEntity(arc)
tr.AddNewlyCreatedDBObject(arc, True)
tr.Commit()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MessageBox.Show(ex.StackTrace)
End Try
End Using
docklock.Dispose()
End Sub
Public Shared Function ConvertToArc(ByVal seg As CircularArc3d) As Arc
' function from:
' http://through-the-interface.typepad.com/through_the_interface/files/kochize.cs
With seg
Dim cnt As Point3d = .Center
Dim norm As Vector3d = .Normal
Dim vec As Vector3d = .ReferenceVector
Dim pn As Plane = New Plane(cnt, norm)
Dim ang As Double = vec.AngleOnPlane(pn)
Dim rad As Double = .Radius
Dim sa As Double = .StartAngle
Dim ea As Double = .EndAngle
Return New Arc(cnt, norm, rad, sa + ang, ea + ang)
End With
End Function

~'J'~
Message 17 of 17
jbooth
in reply to: newbie1221

1. By reading the original poster's example code, I noticed right away he was using COM interop. Therefore the "VBA" forums would be the better place to look regardless if his final code was in C# or not. Is "seems" not strong enough for you? How about "is". Feel better? Probably not.
2. I may rarely post example code, but this is because I do not own the code I write - the company I work for does. I help when I can, but I prefer to help people solve their own problems rather than rely on code posted by random forum users.
3. I'm not usually a rude person - in fact in this case if I was rude it was unintentional. You seem to be the first to think so however.
4. With regards to the above: If you are as antagonistic as you appear to be, I don't really care what you think.

Please make constructive posts in the future instead of trying to make yourself look good by insulting others. I'm pretty sure forum trolling is against this forums' posting guidelines.

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