14/04/2014
Создание выноски-сплайна при помощи Jig
Ниже код, который позволяет создать выноску-сплайн при помощи EntityJig. Это модифицированная версия из этой статьи в блоге Киана.
Код - C#: [Выделить]
- public class SplinedLeaderJig : EntityJig
- {
- Point3dCollection _mPts;
- Point3d _mTempPoint;
- public static bool _mIsJigStarted;
- public SplinedLeaderJig()
- : base(new Leader())
- {
- _mPts = new Point3dCollection();
- Leader leader = Entity as Leader;
- leader.SetDatabaseDefaults();
- _mIsJigStarted = false;
- leader.IsSplined = true;
- }
- protected override SamplerStatus Sampler(JigPrompts prompts)
- {
- Editor ed
- = Application.DocumentManager.MdiActiveDocument.Editor;
- JigPromptPointOptions opts = new JigPromptPointOptions();
- opts.UserInputControls = (
- UserInputControls.Accept3dCoordinates |
- UserInputControls.NoNegativeResponseAccepted |
- UserInputControls.NullResponseAccepted);
- if (_mPts.Count >= 1)
- {
- opts.BasePoint = _mPts[_mPts.Count - 1];
- opts.UseBasePoint = true;
- }
- opts.Message = "\nУкажите вершину выноски: ";
- PromptPointResult res = prompts.AcquirePoint(opts);
- if (_mTempPoint == res.Value)
- {
- return SamplerStatus.NoChange;
- }
- else if (res.Status == PromptStatus.OK)
- {
- _mTempPoint = res.Value;
- return SamplerStatus.OK;
- }
- return SamplerStatus.Cancel;
- }
- protected override bool Update()
- {
- try
- {
- Leader leader = Entity as Leader;
- Editor ed
- = Application.DocumentManager.MdiActiveDocument.Editor;
- if (_mIsJigStarted)
- {
- // Удаляем последнюю вершину, которая нужна только для JIG
- leader.RemoveLastVertex();
- }
- Point3d lastVertex
- = leader.VertexAt(leader.NumVertices - 1);
- if (!_mTempPoint.Equals(lastVertex))
- {
- // Временно добавляем указанную точку как вершину
- leader.AppendVertex(_mTempPoint);
- _mIsJigStarted = true;
- }
- }
- catch (System.Exception ex)
- {
- Document doc
- = Application.DocumentManager.MdiActiveDocument;
- doc.Editor.WriteMessage("\nИсключение: " + ex.Message);
- return false;
- }
- return true;
- }
- public void addVertex()
- {
- Leader leader = Entity as Leader;
- leader.AppendVertex(_mTempPoint);
- _mPts.Add(_mTempPoint);
- }
- public void removeLastVertex()
- {
- Leader leader = Entity as Leader;
- if (_mPts.Count >= 1)
- {
- leader.RemoveLastVertex();
- }
- }
- public Entity getEntity()
- {
- return Entity;
- }
- [CommandMethod("MYSL")]
- public static void MySplinedLeader()
- {
- Document doc
- = Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- Database db = doc.Database;
- SplinedLeaderJig jig = new SplinedLeaderJig();
- bool bSuccess = true;
- bool bComplete = false;
- while (bSuccess && !bComplete)
- {
- SplinedLeaderJig._mIsJigStarted = false;
- PromptResult dragres = ed.Drag(jig);
- bSuccess = (dragres.Status == PromptStatus.OK);
- if (bSuccess)
- jig.addVertex();
- bComplete = (dragres.Status == PromptStatus.None);
- if (bComplete)
- {
- jig.removeLastVertex();
- }
- }
- if (bComplete)
- {
- // Добавляем примитив к базе данных
- Transaction tr
- = db.TransactionManager.StartTransaction();
- using (tr)
- {
- BlockTable bt = tr.GetObject(
- db.BlockTableId, OpenMode.ForRead
- ) as BlockTable;
- BlockTableRecord ms =
- bt[BlockTableRecord.ModelSpace].GetObject
- (OpenMode.ForWrite) as BlockTableRecord;
- ms.AppendEntity(jig.getEntity());
- tr.AddNewlyCreatedDBObject(jig.getEntity(),
- true);
- tr.Commit();
- }
- }
- }
Источник: http://adndevblog.typepad.com/autocad/2014/04/creating-a-splined-leader-using-a-jig.html
Обсуждение: http://adn-cis.org/forum/index.php?topic=679
Опубликовано 14.04.2014