等分曲线并标注 - 精华帖集合
www.dimcax.com
等分曲线并标注
, ,
高手就不用看了。呵呵。高手们不愿意指教的东西,好不容易搞懂了曲线上斜率。
<commandmethod("testcut")> _
public sub cut()
dim db as database = hostapplicationservices.workingdatabase
dim ed as editor = application.documentmanager.mdiactivedocument.editor
dim ts as string = vbcr & "请选择线条(圆弧、直线或者多义线):"
dim opt as new promptentityoptions(ts)
opt.setrejectmessage(vbcr & "只能线条")
opt.addallowedclass(gettype(polyline), true)
opt.addallowedclass(gettype(arc), true)
opt.addallowedclass(gettype(line), true)
dim res as promptentityresult = ed.getentity(opt)
if res.status <> promptstatus.ok then
ed.writemessage("用户自行退出!" & vbcr)
else
'获取等分数
dim iop as new promptintegeroptions("指定等分段的数量:")
iop.defaultvalue = 10
dim irt as promptintegerresult = ed.getinteger(iop)
dim n as integer
if irt.status <> promptstatus.ok orelse irt.value < 2 then
return
else
n = irt.value
end if
dim entid as objectid = res.objectid
using trans as transaction = db.transactionmanager.starttransaction()
'得到拾取的对象
dim ent as entity = trans.getobject(entid, openmode.forread)
dim cv as curve = directcast(trans.getobject(ent.objectid, openmode.forwrite), curve)
dim len as double = cv.getdistanceatparameter(cv.endparam)
dim i as integer
for i = 0 to n
dim p as point3d = cv.getpointatdist(i * len / n)
dim kp as object = cv.getfirstderivative(cv.getparameteratdistance(i * len / n))
dim ka as double = kp(1) / kp(0) - math.pi / 2
call addtext(p, "等分点" & cstr(i), 3, ka, 1, 1)
next
trans.commit()
end using
end if
end sub
' 由插入点、文字内容、文字高度和倾斜角度创建单行文字的函数.
public function addtext(byval position as point3d, byval textstring as string, byval height as double, byval rotate as double, byval dq as integer, byval co as integer) as objectid
'position为文字位置,textstring为文字内容,height为文字高度,rotate为文字角度,dq为对齐方式,co为颜色
try
dim ent as new dbtext()
ent.position = position
ent.textstring = textstring
ent.height = height
ent.rotation = rotate
ent.colorindex = co
select case dq
case 0
ent.horizontalmode = texthorizontalmode.textmid
case 1
ent.horizontalmode = texthorizontalmode.textleft
ent.verticalmode = textverticalmode.textverticalmid
end select
ent.alignmentpoint = position
dim entid as objectid = appendentity(ent)
return entid
catch
' 创建失败,则返回一个空的objectid.
dim nullid as objectid = objectid.null
return nullid
end try
end function
' 将图形对象加入到模型空间的函数.
public function appendentity(byval ent as entity) as objectid
dim db as database = hostapplicationservices.workingdatabase
dim entid as objectid
using trans as transaction = db.transactionmanager.starttransaction
dim bt as blocktable = trans.getobject(db.blocktableid, openmode.forread)
dim btr as blocktablerecord = trans.getobject(bt(blocktablerecord.modelspace), openmode.forwrite)
entid = btr.appendentity(ent)
trans.addnewlycreateddbobject(ent, true)
trans.commit()
end using
return entid
end function
复制代码
呵呵,,收藏了,建议加精
呵呵,,收藏了,建议加精
cloudlove 发表于 2008-12-30 05:55 pm
悠悠你可以给他好评啊
c#最适合开发autocad,因为它拥有vb容易的特点,却具有vc++的强大功能。