I want to add fixedSpiral to the alignment using c#.net by calling Civil3D API.
I need to enter multiple parameters. (shown in the screenshot below)
1)
2 )
3)
4)
5)
They are( 1)previousEntity,(2)spiralCurveType,(3)spiral direction(clockwise or counterclockwise),(4)spiral length, (5)spiral radius.
In the Civil3D API, 5 methods are provided. (shown in the screenshot below)
1).
2).
3).
4).
5).
According to the parameters in Civil3D, I should choose the second method in API.But the parameter "isclockwise " is missing in this method, if i ignore it, just enter previousEntityId, radius,length,spiralCurveType,spiralDefinition,
the fixed spiral generated by programming is wrong,how can I solve this problem ?
Solved! Go to Solution.
Solved by lu_an_jie. Go to Solution.
能否自己计算出spiralPI,
然后使用这个方法来实现?
public AlignmentSpiral AddFixedSpiral(
int previousEntityId,
Point3d startPoint,
Point3d spiralPI,
double radius,
double length,
SpiralCurveType spiralCurveType,
bool isClockwise,
SpiralType spiralDefinition
)
王磊
您认为此帖子是否有用?欢迎为此帖点赞。
您的问题是否已得到解答?请点击“接受解答”按钮。
hello, i also had problems with that.
to solve, I simply created a temporary line before the spiral, thus obtaining an ID. With this id, it creates the spiral in the simplest methods
Of course it will depend on whether you are drawing a spiral with an initial radius greater or less than the final radius. If the starting radius is infinite, use a temporary straight line at the beginning. If it's any radius, prefer a temporary arc
After the spiral is drawn, erase the temporary line or arc
Thank you!
But you may have misunderstood me.I want to draw an alignment end with two continuous spirals using .NET API(shown in the figure below),I can't do it with existing API(I tried different ways).Do you have any good suggestions or methods?
Try this:
Dim alinId As ObjectId = Alignment.Create(CivilDOC,
Alignment.GetNextUniqueName("test"),
ObjectId.Null,
DB.LayerZero,
CivilDOC.Styles.AlignmentStyles.First,
CivilDOC.Styles.LabelSetStyles.AlignmentLabelSetStyles.First)
Dim alin As Alignment = alinId.GetObject(OpenMode.ForWrite)
Dim line1 = alin.Entities.AddFixedLine(New Point3d(100, 100, 0), New Point3d(200, 100, 0))
Dim spi1 = alin.Entities.AddFloatSpiral(line1.EntityId, 100.0#, 30.0#, True, Autodesk.Civil.SpiralType.Clothoid)
Dim line2 = alin.Entities.AddFixedLine(New Point3d(100, 50, 0), New Point3d(200, 50, 0))
Dim spi2 = alin.Entities.AddFloatSpiral(line2.EntityId, 100.0#, 30.0#, False, Autodesk.Civil.SpiralType.Clothoid)
instead of using the AddFixedSpiral method, use AddFloatSpiral
Could you give some more details. What is wrong? Does it throw an exception? Does it produce wrong geometry.
It would be helpful to have the code and the alignment sample.
Could you archive it manually?
You can mimic the counterclockwise be following process:
1. get the endpoint from the entity before (P1)
2. create a temporary fixed spiral clockwise and get the endpoint (P2), delete the entity
3. create a temporary fixed tangent (whatever length), get the endpoint (P3) , delete the entity
4. mirror the P2 with axis P1 to P2 as P4
5. Create fixed spiral from P1 to P4
You could get the mirror axis also from the end point and direction of the entity before's last subentity
Thank you !
I try to Add Float Spiral to the alignment,the code as follows(C#):
....
Point3d p1 = new Point3d(518449.1529, 3014242.9764, 0);
Point3d p2 = new Point3d(518467.7166, 3014023.4374, 0);
aAlignmentCircle1=oCurAlignment.Entities.AddFixedCurve(p1, p2, 150, false);
sAlignmentSpiral1=oCurAlignment.Entities.AddFloatSpiral(aAlignmentCircle1.EntityId,150, 134.5379, false, Autodesk.Civil.SpiralType.Clothoid);
oCurAlignment.Entities.AddFloatSpiral(sAlignmentSpiral1.EntityId, 800, 91.125, true, Autodesk.Civil.SpiralType.Clothoid);
The circle could be drawn,but the spiral couldn't be drawn.Civil 3D displays :No solution!
Thank you!
I want to draw the alignment using .NET API as shown in the figure below.
The parameters are shown in the figure below:
The code is shown in the figure below:
.....
Point3d p1 = new Point3d(535541.148358431, 3927421.86155505, 0);
Point3d p2 = new Point3d(535676.110015142, 3927479.89070189, 0);
aAlignmentCircle1 =oCurAlignment.Entities.AddFixedCurve(p1, p2, 200, true);
sAlignmentSpiral1=oCurAlignment.Entities.AddFixedSpiral(aAlignmentCircle1.EntityId,200, 45,SpiralCurveType.OutCurve, Autodesk.Civil.SpiralType.Clothoid);
oCurAlignment.Entities.AddFixedSpiral(sAlignmentSpiral1.EntityId, 100, 45, SpiralCurveType.InCurve, Autodesk.Civil.SpiralType.Clothoid);
the result as follows:
the second spiral is incorrect!
Please provide next time your code in a executable and testable form and not only a snippet. That would reduce the effort for the people looking at your problem.
Here is my solution:
I call the method that @465340553 suggested. I create temporarily a floating line, so I can find the second point (PI) of the second spiral.
// (C) Copyright 2021 by Andreas Luka (Lu An Jie)
//
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.Civil;
using Autodesk.Civil.DatabaseServices;
[assembly: CommandClass(typeof(ALC_AlignmentAddEntity.MyCommands))]
namespace ALC_AlignmentAddEntity
{
public class MyCommands
{
public static ObjectId SelectAlignment()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ObjectId result = ObjectId.Null;
PromptEntityOptions entOpts = new PromptEntityOptions("\nSelect alignment: ");
entOpts.SetRejectMessage("...not an Alignment, try again!:");
entOpts.AddAllowedClass(typeof(Alignment), true);
PromptEntityResult entRes = ed.GetEntity(entOpts);
if (entRes.Status == PromptStatus.OK) result = entRes.ObjectId;
return result;
}
[CommandMethod("ALCAddFixedSpiralCCW")]
public void ALCAddFixedSpiralCCW()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = Application.DocumentManager.MdiActiveDocument.Database;
ObjectId alignId = SelectAlignment();
if (alignId == ObjectId.Null) return;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
Alignment align = (Alignment)alignId.GetObject(OpenMode.ForRead);
AlignmentEntity lastEntity = align.Entities.GetEntityByOrder(align.Entities.Count - 1);
AlignmentSpiral firstSpiral = align.Entities.AddFixedSpiral(lastEntity.EntityId, 200, 45, SpiralCurveType.OutCurve, SpiralType.Clothoid);
Point3d p0 = new Point3d (firstSpiral.EndPoint.X, firstSpiral.EndPoint.Y,0);
// temporary floating line for finding PI of the spiral
// need r as double to avoid ambigiuenes overload
AlignmentLine tempTangent = align.Entities.AddFloatingLine(firstSpiral.EntityId, 45.0);
Point3d pI = new Point3d (tempTangent.EndPoint.X, tempTangent.EndPoint.Y,0);
align.Entities.Remove(tempTangent);
AlignmentSpiral secondSpiral = align.Entities.AddFixedSpiral(firstSpiral.EntityId,
p0, pI, 100, 45, SpiralCurveType.InCurve, false, SpiralType.Clothoid);
tr.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage(ex.Message);
}
}
}
}
}
Can't find what you're looking for? Ask the community or share your knowledge.