Jump to content

Recommended Posts

Posted

Good Day

 

How does one program to draw an arc(Point, Radius, Angle, Angle)

 

The arc keeps getting drawn according to the WCS? The angles Relate also to the WCS. If a line gets drawn from two Point3D - no problem about the ucs - but arcs and circles retain to WCS even if the user has changed to a UCS?

 

Aye Help needed here

Even if just a simple example to draw an arc on current user UCS will be Great

 

Cheers

CaveMan

Posted

These links may be of use:

 

AutoCAD .NET Developers Guide, here's a snippet:

 

 

Create an Arc object

 

This example creates an arc in Model space with a center point of (6.25,9.125,0), a radius of6, start angle of 1.117 (64 degrees), and an end angle of 3.5605 (204 degrees).

 

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry

Namespace FOO
   Class Foo
       <CommandMethod("AddArc")> _
       Public Sub AddArc()
           '' Get the current document and database
           Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
           Dim acCurDb As Database = acDoc.Database
           '' Start a transaction
           Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
               '' Open the Block table for read
               Dim acBlkTbl As BlockTable
               acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
               '' Open the Block table record Model space for write
               Dim acBlkTblRec As BlockTableRecord
               acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                               OpenMode.ForWrite)
               '' Create an arc that is at 6.25,9.125 with a radius of 6, and
               '' starts at 64 degrees and ends at 204 degrees
               Dim acArc As Arc = New Arc(New Point3d(6.25, 9.125, 0), _
                                          6, 1.117, 3.5605)
               acArc.SetDatabaseDefaults()
               '' Add the new object to the block table record and the transaction
               acBlkTblRec.AppendEntity(acArc)
               acTrans.AddNewlyCreatedDBObject(acArc, True)
               '' Save the new object to the database
               acTrans.Commit()
           End Using
       End Sub
   End Class
End Namespace

 

Convert Angle from UCS to WCS

 

Calculating the Angle Between UCS and WCS

 

HTH

Posted (edited)

Cheers Thanks for the source code supplied

Will review it when i have a chance

 

Below is the two public modules i created - which also works.

Highlited in red was my mistake - Arc was not transformed to current ucs.

 

______________________________________________________________________

 

 
Code:

PublicModule ModDrawArc
FriendFunction DrawArc(ByVal startPoint As Point3d, ByVal Radius AsDouble, ByVal StartAngle AsDouble, ByVal EndAngle AsDouble) As Arc
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
acDoc.LockDocument()
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
Dim acBlkTbl As BlockTable
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead)
Dim acBlkTblRec As BlockTableRecord
acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim acArc As Arc = New Arc(startPoint, Radius, StartAngle, EndAngle)
[color=red]acArc.TransformBy(GetUcsMatrix(acCurDb))[/color]
acBlkTblRec.AppendEntity(acArc)
acTrans.AddNewlyCreatedDBObject(acArc, True)
acTrans.Commit()
[size=2][size=2][color=black]End[/color][/size][/size][size=2][size=2][color=black]Using[/color][/size]
[/size][color=black][size=2][size=2]End[/size][/size][size=2][size=2]Function[/size][/size][/color]
[size=2][color=#0000ff][size=2][color=#0000ff]_____________________________________________________________[/color][/size][/color][/size]
[color=black] [/color]
[color=black][size=2][size=2]Friend[/size][/size][size=2][size=2]Function[/size][/size][size=2] GetUcsMatrix([/size][size=2][size=2]ByVal[/size][/size][size=2] db [/size][size=2][size=2]As[/size][/size][size=2] Database) [/size][size=2][size=2]As[/size][/size][size=2] Matrix3d[/size][/color]
[color=black][size=2][size=2]Dim[/size][/size][size=2] origin [/size][size=2][size=2]As[/size][/size][size=2] Point3d = db.Ucsorg[/size][/color]
[color=black][size=2][size=2]Dim[/size][/size][size=2] xAxis [/size][size=2][size=2]As[/size][/size][size=2] Vector3d = db.Ucsxdir[/size][/color]
[color=black][size=2][size=2]Dim[/size][/size][size=2] yAxis [/size][size=2][size=2]As[/size][/size][size=2] Vector3d = db.Ucsydir[/size][/color]
[color=black][size=2][size=2]Dim[/size][/size][size=2] zAxis [/size][size=2][size=2]As[/size][/size][size=2] Vector3d = xAxis.CrossProduct(yAxis)[/size][/color]
[color=black][size=2][size=2]Return[/size][/size][size=2] Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, _[/size][/color]
[size=2][color=black]Vector3d.ZAxis, origin, xAxis, yAxis, zAxis)[/color][/size]
[color=black][size=2][size=2]End[/size][/size][size=2][size=2]Function[/size][/size][/color]

Appreciate

Cheers

CaveMan

Edited by CaveMan

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...