乐筑天下

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

[编程交流] Using VBA to change an object&

[复制链接]

13

主题

70

帖子

57

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 22:16:15 | 显示全部楼层 |阅读模式
I have found several guides for this, but they dont work
 
what am i doing wrong?
 
  1. Sub test()   Dim pt(2) As Double   Dim objText As AcadText   Dim aCol As AcadAcCmColor      ' defines insertion point   pt(0) = 0   pt(1) = 0   pt(2) = 0      ' creates the text object   Set objText = ThisDrawing.ModelSpace.AddText("test", pt, 10)      ' puts it on the right layer   objText.Layer = "0"      ' makes it the right color   aCol = New AcadAcCmColor   aCol.ColorMethod = acColorMethodByRGB   aCol.ColorIndex = 4   objText.TrueColor = aCol   End Sub
 
when it reaches this line
 
aCol = New AcadAcCmColor
 
an exception is thrown saying
 
%1 is not a valid Win32 application
 
is it because i'm running the 64 bit version of autocad?
 
if anyone knows of an easier way to change the color of an object please advise
回复

使用道具 举报

29

主题

519

帖子

477

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
163
发表于 2022-7-6 22:45:17 | 显示全部楼层
Try this
 
  1.     ' make it the right color   objText.Color = acCyan
or this
 
  1.     ' make it the right color   objText.Color = 4
Both should work.
回复

使用道具 举报

13

主题

70

帖子

57

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 23:16:17 | 显示全部楼层
 
what version of autocad are you using?
 
the AcadText object does not have a color attribute
 
i am using 2012
回复

使用道具 举报

29

主题

519

帖子

477

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
163
发表于 2022-7-6 23:20:01 | 显示全部楼层
 
I'm using all versions from 2007 to 2014. All versions up to and including 2013 use VB6 whereas 2014 uses VB7. Just because the autocomplete function does not show a 'Color' property does not meanit does not have one, some properties for some methods are missing. Color for the text object is one. Just type in Color as shown in my pevious post andit will work. Your code with my altertin works forme in AutoCAD 2012.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-4 11:08 , Processed in 0.614984 second(s), 60 queries .

© 2020-2025 乐筑天下

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