QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

全站
8天前
查看: 6348|回复: 7
收起左侧

[已解决] 怎样修改属性块中的属性???

 关闭 [复制链接]
发表于 2008-7-7 09:10:22 | 显示全部楼层 |阅读模式 来自: 中国辽宁鞍山

马上注册,结识高手,享用更多资源,轻松玩转三维网社区。

您需要 登录 才可以下载或查看,没有帐号?注册

x
怎样修改属性块中的属性???
0 ^2 Q6 @3 U+ R因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?8 D9 ?: j& P! s2 X. f( d6 \; M2 j
VBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;
" ^1 s8 ?, n' q* G3 y可以试试下面的代码:
) V7 O7 Z; w% _1 E5 ^3 b(defun c:test ()
" a7 P! D5 c$ [(vl-load-com)
' @  t0 a/ s  M( l1 e; X; U(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))# p' M$ M" Q/ Q, M, C& ~% [+ [4 f0 F
(setq obj (car (nentsel "\nSelect an Attribute: ")))
7 d; g! w" U6 L' i( j(setq obj (vlax-ename->vla-object obj))
$ h, l* E; U4 `% _(cond
/ q. j7 C9 Y5 @3 W! a((= (strcase att) "A")2 x( O$ Y' E; Y1 g- m" t/ ~3 L
(setq ang (getstring t "\nNew Angle: "))
- j1 H9 ~$ S1 h( a4 i' T( g. w& Q6 }(vlax-put-property obj 'rotation ang))
6 ]+ x% u  Y  Y" w5 ~5 }3 G((= (strcase att) "C")* o0 ~4 `; L! R& W0 ?, L
(setq col (getstring "\nNew Color Number: ")): I$ i3 z4 ?  |5 C7 l, }
(vlax-put-property obj 'color col))! h- W, @2 ~- A' }! f
((= (strcase att) "H")
* m2 f8 d/ b" j" K& O5 B. e(setq ohei (vlax-get-property obj 'height))
- k3 L7 G( L5 r6 i9 R(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:"))), R7 A3 D& C: `
(if (= hei "")(setq hei ohei))
, t& t! @, V8 ~7 J# X3 \% V(vlax-put-property obj 'height hei))) E' i6 ^2 q1 P) Q. z" {; J" x
((= (strcase att) "L")
, M/ B5 g3 A# v' k: a3 |(setq lay (getstring "\nNew Layer:"))( y3 A. w& Y  t* Z8 f, c
(if (not (tblsearch "LAYER" lay)); N4 q" L0 g6 K
(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))
3 ]! W2 h  A8 V. Z8 L0 |(vlax-put-property obj 'layer lay)
7 P* Y3 T  y! c1 I5 K# L))
: |9 i, a4 L- P; H& E2 m* R- C((= (strcase att) "P"). r/ e7 H6 k- K$ V% [/ W7 E
(setq pos (getpoint "\nNew Position:"))
; A1 E3 ~$ |9 C( u) M7 Z9 P4 B& R(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))
4 D5 S+ @6 s  t2 [& b3 D8 U0 u7 O6 t) h" A- [((= (strcase att) "S")& n2 }; s* `% Y. i: I
(setq sty (getstring "\nNew Style: "))6 c& g6 L; s' s# y, C
(if (not (tblsearch "STYLE" sty))2 u- p# I# P; t; s8 ]' [/ ~
(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))
, [% e! H+ f' K: a(vlax-put-property obj 'stylename sty)
- _% D' J) Z) ~' f* V6 D))
* K5 D! m+ Y0 ~. s- U0 ~9 ^((= (strcase att) "V")1 _0 _% @5 ?, c& a2 J) P; ?
(setq val (getstring t "\nNew value: "))0 ]7 w& h$ ]; z+ ]: X
(vlax-put-property obj 'textstring val))& F$ k/ A: Q- i9 l0 b) m
);c
- w$ u& o' k2 v: a' Y(princ)
+ q: ~+ \: ~' b% p. P7 ~9 ~& p);defun

5 o5 ^# l  R+ K9 WVBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性1 `2 c; z1 g& z
' Get the attributes for the block reference7 E0 Y' W7 j4 `! B9 E
    Dim varAttributes As Variant
! y9 e! x: J- a, q! q$ S9 L    varAttributes = blockRefObj.GetAttributes
2 x6 l! p* H# h6 g5 L' p    3 C0 M5 V) O3 T! s0 V  r
    ' Move the attribute tags and values into a string to be displayed in a Msgbox" x1 K, X# ^# D8 d9 B' x; e4 L: S
    Dim strAttributes As String
; ^+ p- c% O( G/ L9 q& L! W    Dim I As Integer7 E- w" o# a- K2 g4 @5 O
    For I = LBound(varAttributes) To UBound(varAttributes)
4 i* f- T8 x2 h  b# T- j        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _+ y6 s: x. r4 y/ ]( o1 m
                        "   Value: " & varAttributes(I).textString & "    "3 v- f7 {# H6 {7 n( `5 H/ Y+ y
    Next3 P. ^9 R  b9 v5 ?2 a! K
    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"
1 _6 g- s; q. N. z% w% r4 G% R   
. J3 t1 z4 p" l    ' Change the value of the attribute9 o  s% W, d7 j1 q  `
    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.
% z2 ~% F) S; p8 F    ' Changing them changes the objects in the drawing.; u7 S5 n& T( ?* Y$ K
    varAttributes(0).textString = "NEW VALUE!"

评分

参与人数 1三维币 +10 收起 理由
wsj249201 + 10 技术讨论

查看全部评分

 楼主| 发表于 2008-7-8 10:35:22 | 显示全部楼层 来自: 中国辽宁鞍山
如果用VBA来实现的话, 该怎样做???VBA与LISP相比,在处理这类问题上哪个更容易实现??再次感谢楼上的
7 [7 Q8 I/ E/ H/ x* e3 j  b& \/ L2 i0 ^" u$ q9 G3 b
[ 本帖最后由 maoyangmy 于 2008-7-8 10:37 编辑 ]
 楼主| 发表于 2008-7-8 11:20:45 | 显示全部楼层 来自: 中国辽宁鞍山
5楼的能不能把VBA的解决方案也分享一下, 非常感谢
发表于 2008-7-14 22:24:59 | 显示全部楼层 来自: 中国天津
建议用VB弄,可以选择的项目比较多,控制性更好些。
8 [+ v$ a, D% j2 H& c+ }3 o* W在CAD的帮助文件里有例子,可以参考,我当初就是利用那个例子实现的自动编号。
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则


Licensed Copyright © 2016-2020 http://www.3dportal.cn/ All Rights Reserved 京 ICP备13008828号

小黑屋|手机版|Archiver|三维网 ( 京ICP备2023026364号-1 )

快速回复 返回顶部 返回列表