QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
怎样修改属性块中的属性???
/ g$ d6 c( f2 W( o, B6 l+ O7 m因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?
" T) X2 Q( o; t/ M  ~! ?# aVBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;7 D9 t0 F. @5 c& m
可以试试下面的代码:, t7 U6 f; F  y( u4 Q
(defun c:test ()8 K0 Q4 C. K3 c2 ?
(vl-load-com)
, M6 g& H" q  c$ `5 n(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: ")), ^/ o4 a3 m9 @/ Y% g; m
(setq obj (car (nentsel "\nSelect an Attribute: ")))6 W: L  I6 i! y
(setq obj (vlax-ename->vla-object obj))
& N" @& ~" L+ T2 a9 R; a0 K(cond
9 [$ M* m% g" v, S) D( N((= (strcase att) "A")
" ]9 O9 h# y2 T( H8 L) h5 S* V(setq ang (getstring t "\nNew Angle: "))/ Y% Z: P' ]7 z7 p  L" A9 y
(vlax-put-property obj 'rotation ang))
$ D' A6 J# Y: n7 Y" s2 Z* |((= (strcase att) "C"), C* V6 U0 }3 D" ?, Z' d0 g
(setq col (getstring "\nNew Color Number: "))1 D9 F( _1 S, ^
(vlax-put-property obj 'color col))
3 S9 g' ^7 t+ k0 H: g; ]2 c& `((= (strcase att) "H")
( y+ R( R$ `+ `+ p5 A7 j1 o(setq ohei (vlax-get-property obj 'height))
9 F$ j. e8 j: x(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:")))
8 A# b9 f! i' ]3 n$ Q  G3 O* D  T(if (= hei "")(setq hei ohei))
5 Y% M) V% }, W4 N: a(vlax-put-property obj 'height hei))/ t3 q7 W4 x1 f+ u% m$ V
((= (strcase att) "L")
  X& q/ B# S: x/ J0 G  h$ k(setq lay (getstring "\nNew Layer:")); v5 e7 j! K/ \  @3 G
(if (not (tblsearch "LAYER" lay))
# f( m/ h. A! k+ X3 V(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))
& B5 ]' ^4 H- f- w3 M" d(vlax-put-property obj 'layer lay)3 _9 ?' C( k6 N: E: N
))
: y5 T( `) L9 x3 }((= (strcase att) "P")$ K# o9 O/ |8 \* {
(setq pos (getpoint "\nNew Position:"))( g' }0 U$ @3 X$ A6 t  w
(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))2 I8 }  d% Z9 d1 m* ~/ r
((= (strcase att) "S")
+ @, u/ i2 a3 _7 \, m9 |/ X(setq sty (getstring "\nNew Style: "))2 Y, k3 V1 S/ R6 q0 L' G: s
(if (not (tblsearch "STYLE" sty))
: G& X7 ?& S+ r(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))
! Z% h5 H7 V) j1 j! ^, p& \(vlax-put-property obj 'stylename sty)1 L. }* O1 T+ \* G0 H: f
))
. r& i/ b# l' X4 k# Q4 O$ s' r((= (strcase att) "V")# K0 ?/ m/ _9 u! w  l
(setq val (getstring t "\nNew value: "))  Y6 B6 u7 n( f$ F1 \! E
(vlax-put-property obj 'textstring val))  T& \9 D5 i6 a$ D5 V# _. j
);c  {- O. U7 d, u4 ~* s  \7 G
(princ) / L( ?& M9 v) w2 i; W' n% G
);defun

* J+ P) M) W- }7 K  W7 ?VBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性9 q% n- F- c" F6 p
' Get the attributes for the block reference1 |# x% |0 ]! H4 u
    Dim varAttributes As Variant8 W$ K( Y/ n- I9 J, Q% R
    varAttributes = blockRefObj.GetAttributes- I7 A4 b+ ^, c$ D% u0 }
   
# S: S6 _1 B. S2 P" \( S    ' Move the attribute tags and values into a string to be displayed in a Msgbox: E3 g, ]; T& N
    Dim strAttributes As String
5 F8 V4 y' J( \( O7 E    Dim I As Integer9 Y/ q* `& t; T
    For I = LBound(varAttributes) To UBound(varAttributes)8 q2 b" l9 N2 J- @9 z
        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _9 v7 }' _; Z& F8 u; U
                        "   Value: " & varAttributes(I).textString & "    "! P* k. B$ {" w0 ^! ?, @/ }
    Next& A) c: M& @9 Q+ E1 `' i
    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"
9 Z& q0 {. P5 L0 `) K   
2 k8 _" ~  O* Y: v9 d$ L    ' Change the value of the attribute/ d& u; z% A% b  b1 L3 ~0 f- I' F
    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.+ I) d; g6 i# ?  C: m7 r
    ' Changing them changes the objects in the drawing.
/ m2 @) t6 B3 j+ }: Q5 Z8 A8 W' F, }    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

 楼主| 发表于 2008-7-8 10:35:22 | 显示全部楼层 来自: 中国辽宁鞍山
如果用VBA来实现的话, 该怎样做???VBA与LISP相比,在处理这类问题上哪个更容易实现??再次感谢楼上的
% G3 S7 R& ?8 q- I/ d( ~1 ?+ X% t6 r
[ 本帖最后由 maoyangmy 于 2008-7-8 10:37 编辑 ]
 楼主| 发表于 2008-7-8 11:20:45 | 显示全部楼层 来自: 中国辽宁鞍山
5楼的能不能把VBA的解决方案也分享一下, 非常感谢
发表于 2008-7-14 22:24:59 | 显示全部楼层 来自: 中国天津
建议用VB弄,可以选择的项目比较多,控制性更好些。' U5 p4 \) Y6 H# p+ P7 R. D2 c, X
在CAD的帮助文件里有例子,可以参考,我当初就是利用那个例子实现的自动编号。
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则


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

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

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