乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: Jozi68

[编程交流] 在多段线内

[复制链接]

1

主题

1069

帖子

1050

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
69
发表于 2022-7-6 13:26:21 | 显示全部楼层
Jozi,
This one has been mostly borrowed from one chinese site
and it's a bit tweaky
You can use it as a sketch
 
  1. using System;using System.Collections.Generic;using System.Text;using Autodesk.AutoCAD.ApplicationServices;using Autodesk.AutoCAD.Runtime;using System.Collections;using Autodesk.AutoCAD.Geometry;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.EditorInput;namespace Join{   public class CurveCommands   {       [CommandMethod("bins")]       public static void Try()       {           Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;           Database db = ed.Document.Database;           TypedValue[] ftype = { new TypedValue(0, "LWPOLYLINE") };           PromptSelectionOptions ppo = new PromptSelectionOptions();           ppo.MessageForRemoval = "\nSelected must be polyline only: ";           ppo.MessageForAdding = "\nSelect a contour: ";           SelectionFilter filter = new SelectionFilter(ftype);           PromptSelectionResult res = ed.GetSelection(ppo, filter);           if (res.Status != PromptStatus.OK) return;           using (Transaction tr = db.TransactionManager.StartTransaction())           {               foreach (ObjectId id in res.Value.GetObjectIds())               {                   Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead);                   Curve bcurv = (Curve)ent;                   TypedValue[] ftype2 = { new TypedValue(0, "*LINE,ARC,CIRCLE,ELLIPSE") };                   SelectionFilter filter2 = new SelectionFilter(ftype2);                   PromptSelectionResult pres = ed.SelectAll(filter2);                   DBObjectCollection objs = new DBObjectCollection();                   ObjectId[] ents = pres.Value.GetObjectIds();                   foreach (ObjectId nid in ents)                   {                       List ptlist = new List();                       List dslist = new List();                       if (nid != id)                       {                           Curve scurv = (Curve)tr.GetObject(nid, OpenMode.ForWrite);                           Point3dCollection pts = new Point3dCollection();                           scurv.IntersectWith(bcurv, Intersect.OnBothOperands, pts, 0, 0);                           foreach (Point3d p in pts)                           {                               ptlist.Add(p);                               dslist.Add(scurv.GetDistAtPoint(p));                           }                           if (ptlist.Count > 0)                           {                               Point3d[] ptarr = ptlist.ToArray();                               Array.Sort(dslist.ToArray(), ptarr);                               try                               {                                   objs = scurv.GetSplitCurves(new Point3dCollection(ptarr));                                   BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);                                   DBObjectCollection ercol = new DBObjectCollection();                                   foreach (Curve curv in objs)                                   {                                       btr.AppendEntity(curv);                                       tr.AddNewlyCreatedDBObject(curv, true);                                       Point3d npt = nearestpoint(curv);                                       if ((Fns.IsInsideCurve(bcurv, npt)) && (id != curv.ObjectId))                                           ercol.Add(curv);//Class Fns is here:http://through-the-interface.typepad.com/through_the_interface/2008/02/robotic-hatchin.html                                   }                                   foreach (DBObject eobj in ercol)                                   {                                       eobj.UpgradeOpen();                                       eobj.Erase();                                       eobj.Dispose();                                   }                                   foreach (ObjectId idx in ents)                                   {                                       if (id != idx)                                       {                                           Entity dent = (Entity)tr.GetObject(idx, OpenMode.ForRead);                                           dent.UpgradeOpen();                                           dent.Erase();                                           dent.Dispose();                                       }                                   }                               }                               catch (Autodesk.AutoCAD.Runtime.Exception ex)                               {                                   ed.WriteMessage("\n{0}", ex.Message);                               }                           }                       }                   }               }               tr.Commit();           }       }       public static Point3d nearestpoint(Curve curv)       {           return curv.GetPointAtDist(0.001);       }
 
~'J'~
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-5 06:03 , Processed in 0.648597 second(s), 63 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表