几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » ObjectARX(VB.NET/C#)
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-29, 05:36 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】曲线修剪问题 - 精华帖集合

曲线修剪问题 - 精华帖集合
www.dimcax.com
曲线修剪问题
请问怎么样对已添加到模型空间的曲线进行修剪啊
请帮忙 感激
得到曲线实体的指针,然后对曲线进行操作
我在网上找到点代码共享一下
共同学习!
using system.diagnostics;
using system.data;
using system.collections;
using microsoft.visualbasic;
using system.collections.generic;
using system;
using autodesk.autocad.runtime;
using autodesk.autocad.applicationservices;
using autodesk.autocad.geometry;
using autodesk.autocad.editorinput;
using autodesk.autocad.databaseservices;
// (c) copyright 2002-2005 by autodesk, inc.
//
// permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// autodesk provides this program "as is" and with all faults.
// autodesk specifically disclaims any implied warranty of
// merchantability or fitness for a particular use. autodesk, inc.
// does not warrant that the operation of the program will be
// uninterrupted or error free.
//
// use, duplication, or disclosure by the u.s. government is subject to
// restrictions set forth in far 52.227-19 (commercial computer
// software - restricted rights) and dfar 252.227-7013(c)(1)(ii)
// (rights in technical data and computer software), as applicable.
//
namespace vbmgdacad1
{
public class classa
{


[commandmethod("tlssb")]

public static void tlsselectionsetbreak()
{

tlsselectionset ss;
objectidcollection objids;
objectidcollection objs = new objectidcollection();
objectid i;
objectid j;
point3d k;
curve ocurve;
curve pcurve;
point3dcollection pnts;
point3dcollection dots;
tlstm ptm = new tlstm();

ptm.starttrans();
try
{
ptm.openblocktablerecord(blocktablerecord.modelspace);

ss = new tlsselectionset("tlssel");
ss.setfilter(0, "line,arc,circle,ellipse,spline,lwpolyline");
ss.selectobjectonscreen();
objids = ss.toobjectidcollection();

foreach (objectid temploopvar_i in objids)
{
i = temploopvar_i;
pnts = new point3dcollection();
ocurve = i.open(openmode.forread, false, true);

foreach (objectid temploopvar_j in objids)
{
j = temploopvar_j;
dots = new point3dcollection();
if (i.oldid != j.oldid)
{
pcurve = j.open(openmode.forread, false, true);
ocurve.intersectwith(pcurve, intersect.onbothoperands, dots, 0, 0);
foreach (point3d temploopvar_k in dots)
{
k = temploopvar_k;
pnts.add(k);
}
pcurve.close();
}
}

ptm.sortpnts(ocurve, pnts);
if (!(ocurve.closed && pnts.count == 1))
{
objs.add(i);
ptm.add(ocurve.getsplitcurves(pnts));
}
ocurve.close();
}

ptm.remove(objs);

ptm.committrans();
}
catch (exception)
{
}
finally
{
ptm.dispose();
}

}


}

}
using system.diagnostics;
using system.data;
using system.collections;
using microsoft.visualbasic;
using system.collections.generic;
using system;
using autodesk.autocad.applicationservices;
using autodesk.autocad.databaseservices;
using autodesk.autocad.runtime;
//using interop;
//using interop.common;
using autodesk.autocad.geometry;
namespace vbmgdacad1
{
public class tlsselectionset
{
private acadselectionset m_osel;
private short[] m_vfiltertype;
private object[] m_vfilterdata;
private string m_sname;
private acadapplication m_oapp;
private acaddocument m_odoc;

public void nullfilter()
{
//娓呯┖杩囨护鍣?

m_vfiltertype = null;
m_vfilterdata = null;

}

private bool isnull()
{
bool returnvalue;

if (m_osel == null)
{
returnvalue = true;
}
else if (m_osel.count == 0)
{
returnvalue = true;
}
else
{
returnvalue = false;
}

return returnvalue;
}
public tlsselectionset() : this("tlssel")
{
m_oapp = application.acadapplication;

}

public tlsselectionset(string name)
{
m_oapp = application.acadapplication;

m_odoc = m_oapp.activedocument;
init(name);
}
public void init(string name)
{
//鍒涘缓閫夋嫨闆?

nullfilter();
if (m_osel != null)
{
m_osel.delete();
}
m_sname = name;
try
{
m_odoc.selectionsets.item(m_sname).delete();
}
catch (exception)
{

}
m_osel = m_odoc.selectionsets.add(m_sname);

}

~tlsselectionset()
{
base.finalize();
if (m_osel != null)
{
m_osel.delete();
}
}

public int count
{
//鑾峰彇閫夋嫨闆嗗疄浣撲釜鏁?
get
{
int returnvalue;
returnvalue = m_osel.returnvalue;
return returnvalue;
}
}

public string name
{
//鑾峰彇閫夋嫨闆嗗悕绉?
get
{
string returnvalue;
returnvalue = m_sname;
return returnvalue;
}
}

//鑾峰彇閫夋嫨闆嗗疄浣?
public acadentity item(object index)
{
acadentity returnvalue;
returnvalue = m_osel.item(index);
return returnvalue;
}

public void additem(acadentity obj)
{
//鍚戦夋嫨闆嗗姞鍏ュ崟涓疄浣?

acadentity[] objs = new acadentity[1];

objs[0] = obj;
m_osel.additems(objs);

}

public void additem(acadentity[] objs)
{
//鍚戦夋嫨闆嗗姞鍏ュ疄浣撴暟缁?

m_osel.additems(objs);

}

public void removeitem(acadentity obj)
{
//鍦ㄩ夋嫨闆嗕腑绉婚櫎鍗曚釜瀹炰綋

acadentity[] objs = new acadentity[1];
objs[0] = obj;
m_osel.removeitems(objs);

}


public void removeitem(acadentity[] objs)
{
//鍦ㄩ夋嫨闆嗕腑绉婚櫎瀹炰綋鏁扮粍

m_osel.removeitems(objs);

}

public void clear()
{
//娓呯┖閫夋嫨闆?

switch (m_sname)
{
case "pickfirst":

getpickfirstselectionset();
break;
case "current":

getactiveselectionset();
break;
default:

init(m_sname);
break;
}

m_osel.clear();

}

public void update()
{

m_osel.update();

}

public void getpickfirstselectionset()
{
//鑾峰彇pickfirst閫夋嫨闆?

nullfilter();
if (m_osel != null)
{
m_osel.delete();
}
m_sname = "pickfirst";
m_odoc.selectionsets.item(m_sname).delete();
m_osel = m_odoc.pickfirstselectionset;

}

public void getactiveselectionset()
{
//鑾峰彇active閫夋嫨闆?
//on error resume next vbconversions warning: on error resume next not supported in c#

nullfilter();
if (m_osel != null)
{
m_osel.delete();
}
m_sname = "current";
m_odoc.selectionsets.item(m_sname).delete();
m_osel = m_odoc.activeselectionset;

}

public void setfiltertype(params object[] filtertype)
{
//璁剧疆杩囨护鍣ㄧ被鍨?

object i;
short ncount;
ncount = filtertype.length - 1;
m_vfiltertype = new short[ncount + 1];

for (i = 0; i <= ncount; i++)
{
m_vfiltertype = filtertype;
}

}

public void setfilterdata(params object[] filterdata)
{
//璁剧疆杩囨护鍣ㄦ暟鎹?

object i;
int ncount;
ncount = filterdata.length - 1;
m_vfilterdata = new object[ncount + 1];

for (i = 0; i <= ncount; i++)
{
m_vfilterdata = filterdata;
}

}
public void setfilter(params object[] filter)
{
//璁剧疆杩囨护鍣?

object i;
int n;
int ncount;
ncount = ((filter.length - 1) + 1) / 2 - 1;
m_vfiltertype = new short[ncount + 1];
m_vfilterdata = new object[ncount + 1];

for (i = 0; i <= ncount; i++)
{
n = i * 2;
m_vfiltertype = filter[n];
m_vfilterdata = filter[n + 1];
}

}


public void selectobjectonscreen()
{

if (information.isarray(m_vfiltertype))
{
m_osel.selectonscreen(m_vfiltertype, m_vfilterdata);
}
else
{
m_osel.selectonscreen();
}

}

public void selectobject(acselect mode, object point1, object point2)
{

if (information.isarray(m_vfiltertype))
{
m_osel.select(mode, point1, point2, m_vfiltertype, m_vfilterdata);
}
else
{
m_osel.select(mode, point1, point2);
}

}
public void selectobject(acselect mode)
{

if (information.isarray(m_vfiltertype))
{
m_osel.select(mode,,, m_vfiltertype, m_vfilterdata);
}
else
{
m_osel.select(mode);
}

}

public void selectobjectatpoint(object point)
{
//on error resume next vbconversions warning: on error resume next not supported in c#

if (information.isarray(m_vfiltertype))
{
m_osel.selectatpoint(point, m_vfiltertype, m_vfilterdata);
}
else
{
m_osel.selectatpoint(point);
}

}

public void selectobjectbypolygon(acselect mode, object points)
{

if (information.isarray(m_vfiltertype))
{
m_osel.selectbypolygon(mode, points, m_vfiltertype, m_vfilterdata);
}
else
{
m_osel.selectbypolygon(mode, points);
}

}

public bool visible
{
set
{
if (isnull())
{
return;
}

acadentity i;
foreach (acadentity temploopvar_i in m_osel)
{
i = temploopvar_i;
i.visible = value;
}
}
}


public string layer
{
set
{

if (isnull())
{
return;
}

acadentity i;
foreach (acadentity temploopvar_i in m_osel)
{
i = temploopvar_i;
i.layer = value;
}
}
}

public string linetype
{
set
{

if (isnull())
{
return;
}

acadentity i;
foreach (acadentity temploopvar_i in m_osel)
{
i = temploopvar_i;
i.linetype = value;
}
}
}

public acad_color color
{
set
{

if (isnull())
{
return;
}

acadentity i;
foreach (acadentity temploopvar_i in m_osel)
{
i = temploopvar_i;
i.color = value;
}
}
}

public void move(object point1, object point2)
{

if (isnull())
{
return;
}

acadentity i;
foreach (acadentity temploopvar_i in m_osel)
{
i = temploopvar_i;
i.move(point1, point2);
}

}

public acadentity[] copy(object point1, object point2)
{

if (isnull())
{
return null;
}

acadentity[] objs;
object i;
objs = new acadentity[count-1 + 1];

for (i = 0; i <= count; i++)
{
objs = m_osel.item(i).copy;
objs.move(point1, point2);
}

return objs;

}

public void rotate(object basepoint, double rotationangle)
{

if (isnull())
{
return;
}

acadentity i;
foreach (acadentity temploopvar_i in m_osel)
{
i = temploopvar_i;
i.rotate(basepoint, rotationangle);
}

}

public void rotate3d(object point1, object point2, double rotationangle)
{

if (isnull())
{
return;
}

acadentity i;
foreach (acadentity temploopvar_i in m_osel)
{
i = temploopvar_i;
i.rotate3d(point1, point2, rotationangle);
}

}

public void scaleall(object basepoint, double scalefactor)
{

if (isnull())
{
return;
}

acadentity i;
foreach (acadentity temploopvar_i in m_osel)
{
i = temploopvar_i;
i.scaleentity(basepoint, scalefactor);
}

}

public void mirror(object point1, object point2)
{

if (isnull())
{
return;
}

acadentity i;
foreach (acadentity temploopvar_i in m_osel)
{
i = temploopvar_i;
i.mirror(point1, point2);
}

}

public void mirror3d(object point1, object point2, object point3)
{

if (isnull())
{
return;
}

acadentity i;
foreach (acadentity temploopvar_i in m_osel)
{
i = temploopvar_i;
i.mirror3d(point1, point2, point3);
}

}

public void highlight(bool highlightflag)
{

acadentity i;
foreach (acadentity temploopvar_i in m_osel)
{
i = temploopvar_i;
i.highlight(highlightflag);
}

}

public void delete()
{
m_osel.erase();
}
public void copyobjects(object owner, object idpairs)
{
if (isnull())
{
return;
}
m_odoc.copyobjects(toarray(), owner, idpairs);
}
public void copyobjects(object owner)
{ if (isnull())
{
return;
}

m_odoc.copyobjects(toarray(), owner);
}
public void copyobjects()
{
if (isnull())
{
return;
}

m_odoc.copyobjects(toarray());

}
public bool getboundingbox(ref object minpoint, ref object maxpoint)
{
object i;
object d1;
object d2;
object p1;
object p2;

if (isnull())
{
return false;
}

m_osel.item(0).getboundingbox(d1, d2);

for (i = 1; i <= count - 1; i++)
{

m_osel.item(i).getboundingbox(p1, p2);

if (p1(0) < d1(0))
{
d1(0) = p1(0);
}
if (p1(1) < d1(1))
{
d1(1) = p1(1);
}
if (p2(0) > d2(0))
{
d2(0) = p2(0);
}
if (p2(1) > d2(1))
{
d2(1) = p2(1);
}

}
minpoint = d1;
maxpoint = d2;

}
public string toblock(object insertionpoint, string name)
{ if (isnull())
{
return "";
}
acadblock oblock;
oblock = m_odoc.blocks.add(insertionpoint, name);
copyobjects(oblock);

return oblock.name;

}

public acadselectionset toselectionset()
{
return m_osel;

}
public object toarray()
{ object i;
acadentity[] objs;
int ncount;
ncount = m_osel.count - 1;
objs = new acadentity[ncount + 1];

for (i = 0; i <= ncount; i++)
{
objs = m_osel.item(i);
}
return objs;
}
public objectidcollection toobjectidcollection()
{
object i;
objectid objid;
objectidcollection objs = new objectidcollection();
for (i = 0; i <= m_osel.count - 1; i++)
{
objid.oldid = m_osel.item(i).objectid;
objs.add(objid);
}
return objs;
}
}
}
using system.diagnostics;
using system.data;
using system.collections;
using microsoft.visualbasic;
using system.collections.generic;
using system;
using autodesk.autocad.applicationservices;
using autodesk.autocad.databaseservices;
using autodesk.autocad.runtime;
//using interop;
using autodesk.autocad.geometry;
using autocadtm = autodesk.autocad.databaseservices.transactionmanager;
namespace vbmgdacad1
{
public class tlstm
{

private database pdatabase;
private autodesk.autocad.databaseservices.transactionmanager ptransactionmanager;
private transaction pstarttransaction;
private blocktable pblocktable;
private blocktablerecord pblocktablerecord;

//绋嬪簭鍔熻兘锛氬悜褰撳墠鍧楄〃璁板綍涓姞鍏ュ疄浣?
public object add(dbobject tlsentity)
{

pblocktablerecord.appendentity(tlsentity);
ptransactionmanager.addnewlycreateddbobject(tlsentity, true);

}

//绋嬪簭鍔熻兘锛氬悜褰撳墠鍧楄〃璁板綍涓姞鍏ュ疄浣撴暟缁?
public object add(dbobject[] tlsentity)
{

dbobject i;
foreach (dbobject temploopvar_i in tlsentity)
{
i = temploopvar_i;
add(i);
}

}

public object add(dbobjectcollection tlsentity)
{

dbobject i;
foreach (dbobject temploopvar_i in tlsentity)
{
i = temploopvar_i;
add(i);
}

}

public void remove(objectid objid)
{

entity oentity;
oentity = objid.open(openmode.forwrite, true, true);
oentity.erase(true);
oentity.close();

}

public void remove(objectidcollection objids)
{

objectid i;
foreach (objectid temploopvar_i in objids)
{
i = temploopvar_i;
remove(i);
}

}

//绋嬪簭鍔熻兘锛氱敓鎴愪竴涓柊鍧楋紝骞跺姞鍏ュ疄浣?
public objectid addblock(string name, dbobject[] entitys)
{
dbobject i;
database pdatabase = application.documentmanager.mdiactivedocument.database;
autodesk.autocad.databaseservices.transactionmanager ptransactionmanager = pdatabase.transactionmanager;
transaction pstarttransaction = ptransactionmanager.starttransaction();
try
{

blocktable pblocktable = (blocktable) ptransactionmanager.getobject(pdatabase.blocktableid, openmode.forwrite, false);
blocktablerecord pblocktablerecord = new blocktablerecord();
pblocktablerecord.name = name;
pblocktable.add(pblocktablerecord);
objectid pid = pblocktablerecord.id;

foreach (dbobject temploopvar_i in entitys)
{
i = temploopvar_i;
pblocktablerecord.appendentity(i);
ptransactionmanager.addnewlycreateddbobject(i, true);
}

pblocktablerecord.close();
pblocktable.close();
pstarttransaction.commit();

return pid;

}
finally
{
pstarttransaction.dispose();
}

}

//寮濮嬩簨鍔?
public void starttrans()
{

pdatabase = application.documentmanager.mdiactivedocument.database;
ptransactionmanager = pdatabase.transactionmanager;
pstarttransaction = ptransactionmanager.starttransaction();

}

//鎵撳紑涓涓潡琛ㄨ褰?
public void openblocktablerecord(string str)
{

pblocktable = (blocktable) ptransactionmanager.getobject(pdatabase.blocktableid, openmode.forread, false);
pblocktablerecord = (blocktablerecord) ptransactionmanager.getobject(pblocktable[str], openmode.forwrite, false);

}

//浜嬪姟鎻愪氦
public void committrans()
{

pblocktablerecord.close();
pblocktable.close();
pstarttransaction.commit();

}

//浜嬪姟缁撴潫
public void dispose()
{

pstarttransaction.dispose();
pblocktablerecord = null;
pblocktable = null;
pstarttransaction = null;
ptransactionmanager = null;
pdatabase = null;

}


//鑾峰彇褰撳墠鐨勮緟鍔╁伐鍏?
public acadutility utility()
{

return application.acadapplication.activedocument.utility;

}

//鏇茬嚎涓婄殑鐐规帓搴?
public void sortpnts(curve tlscurve, point3dcollection tlspnts)
{

short i;
short j;
short ncount;
point3d ptmp;
ncount = tlspnts.count;
for (i = 1; i <= ncount - 1; i++)
{
for (j = 0; j <= ncount - i - 1; j++)
{
try
{
if (tlscurve.getdistatpoint(tlspnts[j]) > tlscurve.getdistatpoint(tlspnts[j + 1]))
{
ptmp = tlspnts[j];
tlspnts.removeat(j);
tlspnts.insert(j + 1, ptmp);
}
}
catch (exception)
{
}
}
}

}


public line addline(double[] pointer1, double[] pointer2)
{

line pline;
pline = new line(new point3d(pointer1[0], pointer1[1], pointer1[2]), new point3d(pointer2[0], pointer2[1], pointer2[2]));

add(pline);
return pline;

}
}



}
看不懂啊,太有才了。
把我n年前的东西翻出来了,汗,不过上面是c#的,哈
把我n年前的东西翻出来了,汗,不过上面是c#的,哈
雪山飞狐 发表于 2009-4-7 06:32 pm
高手要经常发帖啊
c#最适合开发autocad,因为它拥有vb容易的特点,却具有vc++的强大功能。
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 06:22 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多