How are splines drawn from graphics primitives?
Solved! Go to Solution.
Solved by Alexander.Rivilis. Go to Solution.
@Anonymous wrote:
How are splines drawn from graphics primitives?
Autodesk.AutoCAD.DatabaseServices.Spline class represent Spline entity.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Sorry, not sure that's what I'm looking for, should have gave more detail in the original post.
What I'm doing is using a drawable overrule and subentitytraits to fill closed entities that have certain xData.
Have it working for polylines, polyline2d, circles and ellipses by redrawing the entity with worlddraw.geometry.
I am stuck with splines. I don't know how to draw a spline with worlddraw.geometry.
It is only pseudo code:
public virtual bool WorldDraw( Drawable drawable, Autodesk.AutoCAD.GraphicsInterface.WorldDraw wd ) { using (Spline sp = new Spline()) { // Next setting spline value //....
// Draw Spline wd.Geometry.Draw(spline); } return true; }
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Thanks for replying. I could do that part but I couldn't find how to fill the spline.
The other entities I redrew and using the graphics primitives.
I'm currently trying to generate a hatch on the fly to fill the spline
@Anonymous wrote:
Thanks for replying. I could do that part but I couldn't find how to fill the spline.
The other entities I redrew and using the graphics primitives.
I'm currently trying to generate a hatch on the fly to fill the spline
I think it is easy to approximate spline with points and after using "graphics primitives" (for example, with help of Geometry.Polygon)
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
There is a sample:
using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using AcGi = Autodesk.AutoCAD.GraphicsInterface; [assembly: CommandClass(typeof(Rivilis.MyCommands))] namespace Rivilis { public class MyCommands { [CommandMethod("SplineOver")] public void CmdSimpleOverrule() { if (_overrule == null) { _overrule = new SplineOverrule(); Overrule.AddOverrule(RXClass.GetClass(typeof(Spline)), _overrule, false); } else { Overrule.RemoveOverrule(RXClass.GetClass(typeof(Spline)), _overrule); _overrule = null; } Document doc = Application.DocumentManager.MdiActiveDocument; doc.Editor.Regen(); } private static SplineOverrule _overrule = null; } public class SplineOverrule : AcGi.DrawableOverrule { const double Fuzz = 1e-4; public override bool WorldDraw(AcGi.Drawable drawable, AcGi.WorldDraw wd) { base.WorldDraw(drawable, wd); Spline spline = drawable as Spline; if (spline != null) { using (NurbCurve3d curve3d = spline.GetGeCurve() as NurbCurve3d) { BoundBlock3d blk = curve3d.BoundBlock; double minChord = blk.GetMaximumPoint().DistanceTo(blk.GetMinimumPoint()) * Fuzz; PointOnCurve3d[] ptCurvs = curve3d.GetSamplePoints(curve3d.StartParameter, curve3d.EndParameter, minChord); using (Point3dCollection pts = new Point3dCollection()) { foreach (PointOnCurve3d p in ptCurvs) pts.Add(p.GetPoint()); wd.SubEntityTraits.FillType = AcGi.FillType.FillAlways; wd.SubEntityTraits.TrueColor = spline.Color.EntityColor; wd.Geometry.Polygon(pts); } } } return true; } } }
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Thanks. Will accept as solution since it gives better results than other methods I tried.
Tried hatching the spline and zooming to see how well it followed the spline - Much the same as your code.
Tried the following code - More accurate, but very slow to zoom or pan
Using pts As New Point3dCollection For i = 0 To sp.EndParam pts.Add(sp.GetPointAtParameter(i)) Next wd.Geometry.Polygon(pts) End Using
@Anonymous wrote:
...Tried the following code - More accurate, but very slow to zoom or pan...
Using pts As New Point3dCollection For i = 0 To sp.EndParam pts.Add(sp.GetPointAtParameter(i)) Next wd.Geometry.Polygon(pts) End Using
You can change Fuzz value in my code (for example, 1e-6) in order to get more accuracy.
Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"
Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Can't find what you're looking for? Ask the community or share your knowledge.