永发信息网

AUTOCAD二次开发 VB、 VBA 的疑问

答案:2  悬赏:0  手机版
解决时间 2021-02-02 11:36
我找到了一个让我钻牛角尖的问题:
举例:添加一个图层名字叫ABC的图层,并定义他的颜色:
Dim obj As AcadLayer
Set obj = ThisDrawing.Layers.Add(ABC)
obj.color = acBlue

那么问题来了,为什么我不能在这里用ABC.color = acBlue
而必须用变量obj.color = acBlue呢?
对ABC直接操作为什么不行,非得通过变量obj呢?

对不起,没财富值了,我去挣,采纳后一定追加!
最佳答案
您好,这样的:
VB,VBA或其它工具如c#,C++等都是利用AutoCAD提供的ARX接口进行开发
VB开发的程序相对独立,不能查看源码;运行速度一般;可能会因为CAD正在运行的命令或其它冲突!
VBA必需集成于CAD之下,源代码可以被看到,运行速度快;运行错误率更低!
AutoCAD 64版本,在安装使用VBA后(CAD2010及以后版本需单独安装);保存低版本会很慢;需要等上约30秒左右!
如果你是初学开发,个人建议学习VBA(就是学习CAD的ARX接口用法),不用引用,调试很快;在CAD开发人员帮助文件中有很详细的帮助说明!学会VBA后,可以很轻松的转到VB,c#等其它工具进行开发!
全部回答
dim blocknamest as string sub dimdimaligned() on error goto err dim po(0 to 2) as double dim pr(0 to 2) as double dim var as variant dim dimdimalign as acaddimrotated dim blokname as string dim ang as double dim ldob as double dim xdob as double dim pth as string var = thisdrawing.utility.getpoint(, vbcr & "指定第一条尺寸界线原点:") po(0) = var(0): po(1) = var(1): po(2) = var(2) var = thisdrawing.utility.getpoint(po, vbcr & "指定第二条尺寸界线原点:") pr(0) = var(0): pr(1) = var(1): pr(2) = var(2) xdob = pr(0) - po(0) ldob = sqr(((pr(0) - po(0)) * (pr(0) - po(0))) + ((pr(1) - po(1)) * (pr(1) - po(1)))) ang = xdob / ldob if pr(1) > po(1) then ang = atn(-ang / sqr(-ang * ang + 1)) + 2 * atn(1) end if if pr(1) < po(1) then ang = -atn(-ang / sqr(-ang * ang + 1)) + 2 * atn(1) - 180 * 3.1415926 / 180 end if if pr(1) = po(1) and pr(0) < po(0) then ang = 180 * 3.1415926 / 180 end if if pr(1) = po(1) and pr(0) > po(0) then ang = 0 end if set dimdimalign = thisdrawing.modelspace.adddimrotated(po, pr, pr, ang) err: end sub sub linkblok() on error goto err dim po(0 to 2) as double dim pr(0 to 2) as double dim var as variant dim blokin as acadblockreference dim blokname as string dim ang as double dim ldob as double dim xdob as double dim pth as string dim ucsobj as acaducs dim origin(0 to 2) as double dim xaxispo(0 to 2) as double dim yaxispo(0 to 2) as double origin(0) = 0#: origin(1) = 0#: origin(2) = 0# xaxispo(0) = 3: xaxispo(1) = 0: xaxispo(2) = 0 yaxispo(0) = 0: yaxispo(1) = 3: yaxispo(2) = 0 set ucsobj = thisdrawing.usercoordinatesystems.add(origin, xaxispo, yaxispo, "wucs") thisdrawing.activeucs = ucsobj blokname = thisdrawing.utility.getstring(false, vbcr & "输入的块名<" + blocknamest + ">: ") if blokname = "" then blokname = blocknamest pth = "d:\cad块\" + blokname + ".dwg" if dir(pth) <> "" then blocknamest = blokname do var = thisdrawing.utility.getpoint(, vbcr & "选取图块放置点:") po(0) = var(0): po(1) = var(1): po(2) = var(2) set blokin = thisdrawing.modelspace.insertblock(po, pth, 1, 1, 1, 0) var = thisdrawing.utility.getpoint(po, vbcr & "指定图块方向:") pr(0) = var(0): pr(1) = var(1): pr(2) = var(2) xdob = pr(0) - po(0) ldob = sqr(((pr(0) - po(0)) * (pr(0) - po(0))) + ((pr(1) - po(1)) * (pr(1) - po(1)))) ang = xdob / ldob if pr(1) > po(1) then ang = atn(-ang / sqr(-ang * ang + 1)) + 2 * atn(1) end if if pr(1) < po(1) then ang = -atn(-ang / sqr(-ang * ang + 1)) + 2 * atn(1) - 180 * 3.1415926 / 180 end if if pr(1) = po(1) and pr(0) < po(0) then ang = 180 * 3.1415926 / 180 end if if pr(1) = po(1) and pr(0) > po(0) then ang = 0 end if blokin.rotate po, ang loop else thisdrawing.utility.prompt vbcr & pth + "的文件路径不存在!" end if err: end sub sub linkblokr0() on error goto err dim po(0 to 2) as double dim pr(0 to 2) as double dim var as variant dim blokin as acadblockreference dim blokname as string dim ang as double dim ldob as double dim xdob as double dim pth as string dim ucsobj as acaducs dim origin(0 to 2) as double dim xaxispo(0 to 2) as double dim yaxispo(0 to 2) as double origin(0) = 0#: origin(1) = 0#: origin(2) = 0# xaxispo(0) = 3: xaxispo(1) = 0: xaxispo(2) = 0 yaxispo(0) = 0: yaxispo(1) = 3: yaxispo(2) = 0 set ucsobj = thisdrawing.usercoordinatesystems.add(origin, xaxispo, yaxispo, "wucs") thisdrawing.activeucs = ucsobj blokname = thisdrawing.utility.getstring(false, vbcr & "输入的块名<" + blocknamest + ">: ") if blokname = "" then blokname = blocknamest pth = "d:\cad块\" + blokname + ".dwg" if dir(pth) <> "" then blocknamest = blokname do var = thisdrawing.utility.getpoint(, vbcr & "选取图块放置点:") po(0) = var(0): po(1) = var(1): po(2) = var(2) set blokin = thisdrawing.modelspace.insertblock(po, pth, 1, 1, 1, 0) 'var = thisdrawing.utility.getpoint(po, vbcr & "指定图块方向:") 'pr(0) = var(0): pr(1) = var(1): pr(2) = var(2) pr(0) = 0#: pr(1) = 0#: pr(2) = 0# xdob = pr(0) - po(0) ldob = sqr(((pr(0) - po(0)) * (pr(0) - po(0))) + ((pr(1) - po(1)) * (pr(1) - po(1)))) ang = xdob / ldob if pr(1) > po(1) then ang = atn(-ang / sqr(-ang * ang + 1)) + 2 * atn(1) end if if pr(1) < po(1) then ang = -atn(-ang / sqr(-ang * ang + 1)) + 2 * atn(1) - 180 * 3.1415926 / 180 end if if pr(1) = po(1) and pr(0) < po(0) then ang = 180 * 3.1415926 / 180 end if if pr(1) = po(1) and pr(0) > po(0) then ang = 0 end if blokin.rotate po, ang loop else thisdrawing.utility.prompt vbcr & pth + "的文件路径不存在!" end if err: end sub sub plinelenx() on error goto err dim plx as string dim obj as acadentity dim lentxt as acadtext dim po(0 to 2) as double dim var as variant thisdrawing.utility.getentity obj, var, vbcr & "选取polyline对象:" if obj.objectname = "acdbpolyline" then plx = cstr(int(obj.length * 100) / 100) var = thisdrawing.utility.getpoint(, vbcr & "选取文字放置点:") po(0) = var(0): po(1) = var(1): po(2) = var(2) set lentxt = thisdrawing.modelspace.addtext("heater len", po, 4) lentxt.stylename = "heatertxt": lentxt.layer = "3" po(0) = po(0): po(1) = po(1) - 6: po(2) = po(2) set lentxt = thisdrawing.modelspace.addtext(plx, po, 4) lentxt.stylename = "heatertxt": lentxt.layer = "3" else thisdrawing.utility.prompt vbcr & "选取对象无效!" end if err: end sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
有一箱图书,小明拿走了一半多1本,小强拿走了
诚字有以工夫说者.诚是心之本体,求复其本位
海棠花什么季节插枝
琪雅美容健康万店连锁NO.06291在哪里啊,我有
美栗人生,健康生活地址在什么地方,我要处理
904的63倍比36个904多多少
大连长青岛八岔沟有多远
善意的谎言例子
形容奇山的成语
连云港牌照车在高速南通段有违章,可以在苏州
东大山口在什么地方啊,我要过去处理事情
阿芙就是精油地址在什么地方,想过去办事
定制衣柜交了定金不想做了怎么处理
大富豪门业我想知道这个在什么地方
华为手机4AE4FEF38B9D46C是什么文件夹
推荐资讯
中江县普兴镇中学校清凉分校地址有知道的么?
必须采用订本式账簿的是
长江穿过的地形区有哪些?
红杜鹃家纺地址好找么,我有些事要过去
腾依格企业美容美体养身会所地址在什么地方,
找一些冰释前嫌的词句
某企业为开发新产品,从市场部、生产部、研发
润姿美健康美容养生馆怎么去啊,我要去那办事
笔记本电脑密码忘记维修要多少钱
16岁矫正牙齿大概需要多少钱
浦东国际机场安检进入后如何出来。
关于鹿晗的QQ手势密码
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?