QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

查看: 6355|回复: 7
收起左侧

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

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

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

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

x
怎样修改属性块中的属性???
2 P) \. }' T- [5 Z' B8 y8 s0 H因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?; N6 B" K# z$ `# h. j( o
VBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;
4 n$ s0 d' y7 `5 K- k8 K; E可以试试下面的代码:5 n9 E* R# ]0 A* Q
(defun c:test ()
& O$ U' e5 V- ]: ^9 m( G- A% ^(vl-load-com)/ j/ Q' X7 P& x8 ]7 M0 B7 N2 R
(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))
( q4 A# W1 I% H* z4 `(setq obj (car (nentsel "\nSelect an Attribute: ")))
6 g" {* h( h% H7 _0 C(setq obj (vlax-ename->vla-object obj)). f" Q. j1 k" s: @! l6 h
(cond3 O2 b. n( u2 z" r9 H$ G
((= (strcase att) "A")
1 g. I  U  B" F4 Q+ A5 ~(setq ang (getstring t "\nNew Angle: "))
' n4 p1 U6 D. S(vlax-put-property obj 'rotation ang))
8 G4 D; w$ V+ v5 A& X4 w((= (strcase att) "C")( V8 x0 C" h# O' p  I, D2 G! d
(setq col (getstring "\nNew Color Number: ")); h8 K- c' v* g, I  c4 f" }: b
(vlax-put-property obj 'color col))
# B0 r9 ^$ M/ T7 ]8 K; L((= (strcase att) "H")
9 o0 i& Q) d" Z& u1 J4 w(setq ohei (vlax-get-property obj 'height))
* h& p3 e" s5 H; w% O% u$ A4 E(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:")))
8 H3 n$ ?0 ]' t& B! d' y/ F' o(if (= hei "")(setq hei ohei))/ I( p/ i/ B" H% |* y
(vlax-put-property obj 'height hei))
+ v1 v/ G1 H& @  N) ~# T8 \+ _((= (strcase att) "L")
  L7 q0 p! w2 k+ v) N(setq lay (getstring "\nNew Layer:"))2 T) F. |+ e+ r  k0 X$ [" J
(if (not (tblsearch "LAYER" lay))8 b7 l. P" D7 |( j8 o3 |
(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))# e- Y3 Q3 j4 O% t( A9 {: R# o
(vlax-put-property obj 'layer lay)  J- r1 i( y; I* n
))$ Y) e$ A- I$ X8 |, I- I2 m) j
((= (strcase att) "P")4 |% H9 n2 ]7 w2 M
(setq pos (getpoint "\nNew Position:"))
, o( w! f7 n0 u(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))
2 l+ H3 n1 ?3 i, b" V((= (strcase att) "S")
6 F( `/ R) _9 s4 _9 g(setq sty (getstring "\nNew Style: "))
3 F8 a7 q' e% j: I* m6 b(if (not (tblsearch "STYLE" sty))
$ u; o( D  h% L) m9 c  ~6 |; Q(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))
. W0 R; ~4 w6 j2 N(vlax-put-property obj 'stylename sty). \# u. S: o9 D$ ^1 K
))5 Y- d) o! m: ]* ^+ O) m4 e3 n+ _: J
((= (strcase att) "V")) \0 V; t7 x/ N" a1 E8 h
(setq val (getstring t "\nNew value: "))
/ X+ K% G/ X/ P- x; B$ n% }$ @(vlax-put-property obj 'textstring val))' U6 @" d7 k/ f- H) X4 b$ n3 ]
);c
0 @7 u5 J1 c$ y' K# Z3 @2 O4 `2 ~(princ) # c8 n  c& E0 _9 s8 D6 [0 f( y- W
);defun

+ B+ ]2 O, q' m5 S+ sVBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性
8 Q# z5 c  s$ K* |4 S: l' Get the attributes for the block reference
3 R" E8 s3 r( k' ?- z4 D/ I    Dim varAttributes As Variant7 Z/ E! A+ l2 @9 V, _1 d* {
    varAttributes = blockRefObj.GetAttributes: t' F; ?: y5 y" f$ D6 E7 K
    ) G! y& e& L- Z7 ?
    ' Move the attribute tags and values into a string to be displayed in a Msgbox% p* \+ @4 @" L% [
    Dim strAttributes As String
! ?6 n" O( B( G1 s# |" r, |    Dim I As Integer$ h6 d+ p1 ^$ d, V: t
    For I = LBound(varAttributes) To UBound(varAttributes)
6 j! Z. j. G! b+ L  x' M        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _* `4 G5 C3 }3 H) e8 y
                        "   Value: " & varAttributes(I).textString & "    "
: W1 h/ A; p* J; H    Next! T8 c' d7 W$ y3 v( m$ @( X- S# N
    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"
' D4 d8 \: W/ f+ x" |' K7 F" f+ x    4 ^( [  `# E- Q( O
    ' Change the value of the attribute" r# u8 P1 O2 ~! Y- {' z+ {( a$ y1 w" K& D
    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.. D- s6 K1 `1 w; U" G
    ' Changing them changes the objects in the drawing.! W, c, q1 w' f" I/ d7 `3 d( X8 [
    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

 楼主| 发表于 2008-7-8 10:35:22 | 显示全部楼层 来自: 中国辽宁鞍山
如果用VBA来实现的话, 该怎样做???VBA与LISP相比,在处理这类问题上哪个更容易实现??再次感谢楼上的: ~5 K6 C9 R5 G$ y, P- S, T6 I2 J: \$ y
% W4 e" B( ~% O8 N# a5 X
[ 本帖最后由 maoyangmy 于 2008-7-8 10:37 编辑 ]
 楼主| 发表于 2008-7-8 11:20:45 | 显示全部楼层 来自: 中国辽宁鞍山
5楼的能不能把VBA的解决方案也分享一下, 非常感谢
发表于 2008-7-14 22:24:59 | 显示全部楼层 来自: 中国天津
建议用VB弄,可以选择的项目比较多,控制性更好些。
: P0 j! ]* `0 p$ k在CAD的帮助文件里有例子,可以参考,我当初就是利用那个例子实现的自动编号。
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则


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

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

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