几何尺寸与公差论坛------致力于产品几何量公差标准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-20, 03:19 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】[原创]曲线打断于交点

[原创]曲线打断于交点
www.dimcax.com
[原创]曲线打断于交点<commandmethod("tlssb")> public shared sub tlsselectionsetbreak()
dim ss as tlsselectionset
dim objids as objectidcollection
dim objs as new objectidcollection
dim i, j as objectid
dim k as point3d
dim ocurve, pcurve as curve
dim pnts, dots as point3dcollection
dim ptm as 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
for each i in objids
pnts = new point3dcollection
ocurve = i.open(openmode.forread, false, true)
for each j in objids
dots = new point3dcollection
if i.oldid <> j.oldid then
pcurve = j.open(openmode.forread, false, true)
ocurve.intersectwith(pcurve, intersect.onbothoperands, dots, 0, 0)
for each k in dots
pnts.add(k)
next
pcurve.close()
end if
next
ptm.sortpnts(ocurve, pnts)
if not (ocurve.closed and pnts.count = 1) then
objs.add(i)
ptm.add(ocurve.getsplitcurves(pnts))
end if
ocurve.close()
next
ptm.remove(objs)
ptm.committrans()
catch ex as exception
finally
ptm.dispose()
end try
end sub
imports autodesk.autocad.applicationservices
imports autodesk.autocad.databaseservices
imports autodesk.autocad.runtime
imports autodesk.autocad.interop
imports autodesk.autocad.interop.common
imports autodesk.autocad.geometry
public class tlsselectionset
private m_osel as acadselectionset
private m_vfiltertype() as short, m_vfilterdata() as object
private m_sname as string
private m_oapp as acadapplication = application.acadapplication
private m_odoc as acaddocument
public sub nullfilter()
'清空过滤器
m_vfiltertype = nothing
m_vfilterdata = nothing
end sub
private function isnull() as boolean
if m_osel is nothing then
isnull = true
elseif m_osel.count = 0 then
isnull = true
else
isnull = false
end if
end function
public sub new()
me.new("tlssel")
end sub
public sub new(byval name as string)
m_odoc = m_oapp.activedocument
init(name)
end sub
public sub init(byval name as string)
'创建选择集
nullfilter()
if not m_osel is nothing then m_osel.delete()
m_sname = name
try
m_odoc.selectionsets.item(m_sname).delete()
catch ex as exception
end try
m_osel = m_odoc.selectionsets.add(m_sname)
end sub
protected overrides sub finalize()
mybase.finalize()
if not m_osel is nothing then m_osel.delete()
end sub
public readonly property count() as integer
'获取选择集实体个数
get
count = m_osel.count
end get
end property
public readonly property name() as string
'获取选择集名称
get
name = m_sname
end get
end property
public readonly property item(byval index) as acadentity
'获取选择集实体
get
item = m_osel.item(index)
end get
end property
public sub additem(byval obj as acadentity)
'向选择集加入单个实体
dim objs(0) as acadentity
objs(0) = obj
m_osel.additems(objs)
end sub
public sub additem(byval objs as acadentity())
'向选择集加入实体数组
m_osel.additems(objs)
end sub
public sub removeitem(byval obj as acadentity)
'在选择集中移除单个实体
dim objs(0) as acadentity
objs(0) = obj
m_osel.removeitems(objs)
end sub
public sub removeitem(byval objs as acadentity())
'在选择集中移除实体数组
m_osel.removeitems(objs)
end sub
public sub clear()
'清空选择集
select case m_sname
case "pickfirst"
getpickfirstselectionset()
case "current"
getactiveselectionset()
case else
init(m_sname)
end select
m_osel.clear()
end sub
public sub update()
m_osel.update()
end sub
public sub getpickfirstselectionset()
'获取pickfirst选择集
nullfilter()
if not m_osel is nothing then m_osel.delete()
m_sname = "pickfirst"
m_odoc.selectionsets.item(m_sname).delete()
m_osel = m_odoc.pickfirstselectionset
end sub
public sub getactiveselectionset()
'获取active选择集
on error resume next
nullfilter()
if not m_osel is nothing then m_osel.delete()
m_sname = "current"
m_odoc.selectionsets.item(m_sname).delete()
m_osel = m_odoc.activeselectionset
end sub
public sub setfiltertype(byval paramarray filtertype())
'设置过滤器类型
dim i
dim ncount as short
ncount = ubound(filtertype)
redim m_vfiltertype(ncount)
for i = 0 to ncount
m_vfiltertype(i) = filtertype(i)
next i
end sub
public sub setfilterdata(byval paramarray filterdata())
'设置过滤器数据
dim i
dim ncount as integer
ncount = ubound(filterdata)
redim m_vfilterdata(ncount)
for i = 0 to ncount
m_vfilterdata(i) = filterdata(i)
next i
end sub
public sub setfilter(byval paramarray filter())
'设置过滤器
dim i
dim n as integer
dim ncount as integer
ncount = (ubound(filter) + 1) / 2 - 1
redim m_vfiltertype(ncount), m_vfilterdata(ncount)
for i = 0 to ncount
n = i * 2
m_vfiltertype(i) = filter(n)
m_vfilterdata(i) = filter(n + 1)
next i
end sub
public sub selectobjectonscreen()
if isarray(m_vfiltertype) then
m_osel.selectonscreen(m_vfiltertype, m_vfilterdata)
else
m_osel.selectonscreen()
end if
end sub
public sub selectobject(byval mode as acselect, byval point1 as object, byval point2 as object)
if isarray(m_vfiltertype) then
m_osel.select(mode, point1, point2, m_vfiltertype, m_vfilterdata)
else
m_osel.select(mode, point1, point2)
end if
end sub
public sub selectobject(byval mode as acselect)
if isarray(m_vfiltertype) then
m_osel.select(mode, , , m_vfiltertype, m_vfilterdata)
else
m_osel.select(mode)
end if
end sub
public sub selectobjectatpoint(byval point)
on error resume next
if isarray(m_vfiltertype) then
m_osel.selectatpoint(point, m_vfiltertype, m_vfilterdata)
else
m_osel.selectatpoint(point)
end if
end sub
public sub selectobjectbypolygon(byval mode as acselect, byval points as object)
if isarray(m_vfiltertype) then
m_osel.selectbypolygon(mode, points, m_vfiltertype, m_vfilterdata)
else
m_osel.selectbypolygon(mode, points)
end if
end sub
public writeonly property visible() as boolean
set(byval value as boolean)
if isnull() then exit property
dim i as acadentity
for each i in m_osel
i.visible = value
next i
end set
end property
public writeonly property layer() as string
set(byval value as string)
if isnull() then exit property
dim i as acadentity
for each i in m_osel
i.layer = value
next i
end set
end property
public writeonly property linetype() as string
set(byval value as string)
if isnull() then exit property
dim i as acadentity
for each i in m_osel
i.linetype = value
next i
end set
end property
public writeonly property color() as acad_color
set(byval value as acad_color)
if isnull() then exit property
dim i as acadentity
for each i in m_osel
i.color = value
next i
end set
end property
public sub move(byval point1 as object, byval point2 as object)
if isnull() then exit sub
dim i as acadentity
for each i in m_osel
i.move(point1, point2)
next i
end sub
public function copy(byval point1 as object, byval point2 as object) as acadentity()
if isnull() then exit function
dim objs() as acadentity
dim i
redim objs(count - 1)
for i = 0 to count
objs(i) = m_osel.item(i).copy
objs(i).move(point1, point2)
next i
return objs
end function
public sub rotate(byval basepoint as object, optional byval rotationangle as double = 1.0#)
if isnull() then exit sub
dim i as acadentity
for each i in m_osel
i.rotate(basepoint, rotationangle)
next i
end sub
public sub rotate3d(byval point1 as object, byval point2 as object, optional byval rotationangle as double = 1.0#)
if isnull() then exit sub
dim i as acadentity
for each i in m_osel
i.rotate3d(point1, point2, rotationangle)
next i
end sub
public sub scaleall(byval basepoint as object, optional byval scalefactor as double = 1)
if isnull() then exit sub
dim i as acadentity
for each i in m_osel
i.scaleentity(basepoint, scalefactor)
next i
end sub
public sub mirror(byval point1 as object, byval point2 as object)
if isnull() then exit sub
dim i as acadentity
for each i in m_osel
i.mirror(point1, point2)
next i
end sub
public sub mirror3d(byval point1 as object, byval point2 as object, byval point3 as object)
if isnull() then exit sub
dim i as acadentity
for each i in m_osel
i.mirror3d(point1, point2, point3)
next i
end sub
public sub highlight(optional byval highlightflag as boolean = true)
dim i as acadentity
for each i in m_osel
i.highlight(highlightflag)
next i
end sub
public sub delete()
m_osel.erase()
end sub
public sub copyobjects(byval owner as object, byval idpairs as object)
if isnull() then exit sub
m_odoc.copyobjects(toarray, owner, idpairs)
end sub
public sub copyobjects(byval owner as object)
if isnull() then exit sub
m_odoc.copyobjects(toarray, owner)
end sub
public sub copyobjects()
if isnull() then exit sub
m_odoc.copyobjects(toarray)
end sub
public function getboundingbox(byref minpoint as object, byref maxpoint as object) as boolean
dim i
dim d1, d2, p1, p2
if isnull() then exit function
m_osel.item(0).getboundingbox(d1, d2)
for i = 1 to count - 1
m_osel.item(i).getboundingbox(p1, p2)
if p1(0) < d1(0) then d1(0) = p1(0)
if p1(1) < d1(1) then d1(1) = p1(1)
if p2(0) > d2(0) then d2(0) = p2(0)
if p2(1) > d2(1) then d2(1) = p2(1)
next i
minpoint = d1
maxpoint = d2
end function
public function toblock(byval insertionpoint as object, optional byval name as string = "*u") as string
if isnull() then exit function
dim oblock as acadblock
oblock = m_odoc.blocks.add(insertionpoint, name)
copyobjects(oblock)
return oblock.name
end function
public function toselectionset() as acadselectionset
'获取选择集
return m_osel
end function
public function toarray()
'转化选择集为对象数组输出
dim i
dim objs() as acadentity
dim ncount as integer
ncount = m_osel.count - 1
redim objs(ncount)
for i = 0 to ncount
objs(i) = m_osel.item(i)
next i
return objs
end function
public function toobjectidcollection() as objectidcollection
'转化选择集为对象数组输出
dim i
dim objid as objectid
dim objs as new objectidcollection
for i = 0 to m_osel.count - 1
objid.oldid = m_osel.item(i).objectid
objs.add(objid)
next i
return objs
end function
end class
imports autodesk.autocad.applicationservices
imports autodesk.autocad.databaseservices
imports autodesk.autocad.runtime
imports autodesk.autocad.interop
imports autodesk.autocad.geometry
imports autocadtm = autodesk.autocad.databaseservices.transactionmanager
public class tlstm
private pdatabase as database
private ptransactionmanager as autocadtm
private pstarttransaction as transaction
private pblocktable as blocktable
private pblocktablerecord as blocktablerecord
'程序功能:向当前块表记录中加入实体
public function add(byval tlsentity as dbobject)
pblocktablerecord.appendentity(tlsentity)
ptransactionmanager.addnewlycreateddbobject(tlsentity, true)
end function
'程序功能:向当前块表记录中加入实体数组
public function add(byval tlsentity as dbobject())
dim i as dbobject
for each i in tlsentity
add(i)
next i
end function
public function add(byval tlsentity as dbobjectcollection)
dim i as dbobject
for each i in tlsentity
add(i)
next i
end function
public sub remove(byval objid as objectid)
dim oentity as entity
oentity = objid.open(openmode.forwrite, true, true)
oentity.erase(true)
oentity.close()
end sub
public sub remove(byval objids as objectidcollection)
dim i as objectid
for each i in objids
remove(i)
next
end sub
'程序功能:生成一个新块,并加入实体
public function addblock(byval name as string, byval entitys as dbobject()) as objectid
dim i as dbobject
dim pdatabase as database = application.documentmanager.mdiactivedocument.database
dim ptransactionmanager as autocadtm = pdatabase.transactionmanager
dim pstarttransaction as transaction = ptransactionmanager.starttransaction()
try
dim pblocktable as blocktable = ctype(ptransactionmanager.getobject(pdatabase.blocktableid, openmode.forwrite, false), blocktable)
dim pblocktablerecord as new blocktablerecord
pblocktablerecord.name = name
pblocktable.add(pblocktablerecord)
dim pid as objectid = pblocktablerecord.id
for each i in entitys
pblocktablerecord.appendentity(i)
ptransactionmanager.addnewlycreateddbobject(i, true)
next i
pblocktablerecord.close()
pblocktable.close()
pstarttransaction.commit()
return pid
finally
pstarttransaction.dispose()
end try
end function
'开始事务
public sub starttrans()
pdatabase = application.documentmanager.mdiactivedocument.database
ptransactionmanager = pdatabase.transactionmanager
pstarttransaction = ptransactionmanager.starttransaction()
end sub
'打开一个块表记录
public sub openblocktablerecord(byval str as string)
pblocktable = ctype(ptransactionmanager.getobject(pdatabase.blocktableid, openmode.forread, false), blocktable)
pblocktablerecord = ctype(ptransactionmanager.getobject(pblocktable(str), openmode.forwrite, false), blocktablerecord)
end sub
'事务提交
public sub committrans()
pblocktablerecord.close()
pblocktable.close()
pstarttransaction.commit()
end sub
'事务结束
public sub dispose()
pstarttransaction.dispose()
pblocktablerecord = nothing
pblocktable = nothing
pstarttransaction = nothing
ptransactionmanager = nothing
pdatabase = nothing
end sub
'获取当前的辅助工具
public function utility() as acadutility
return application.acadapplication.activedocument.utility
end function
'曲线上的点排序
public sub sortpnts(byval tlscurve as curve, byref tlspnts as point3dcollection)
dim i, j as short
dim ncount as short
dim ptmp as point3d
ncount = tlspnts.count
for i = 1 to ncount - 1
for j = 0 to ncount - i - 1
try
if tlscurve.getdistatpoint(tlspnts(j)) > tlscurve.getdistatpoint(tlspnts(j + 1)) then
ptmp = tlspnts(j)
tlspnts.removeat(j)
tlspnts.insert(j + 1, ptmp)
end if
catch ex as exception
end try
next
next
end sub
public function addline(byval pointer1() as double, byval pointer2() as double) as line
dim pline as line
pline = new line( _
new point3d(pointer1(0), pointer1(1), pointer1(2)), _
new point3d(pointer2(0), pointer2(1), pointer2(2)))
add(pline)
return pline
end function
end class
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


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

高级搜索
显示模式

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

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



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


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