QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
怎样修改属性块中的属性???
! x- f  R8 ?/ [" f因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?' V! X; J3 K# K6 |! r1 y( x
VBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;
. A) j& P1 a9 w' x) m1 L& X; R& a可以试试下面的代码:) Z2 Y. E& _0 I& d) p; l; G
(defun c:test ()
' e8 z' ^+ \3 ?* D  n; K6 I; {(vl-load-com)
" k1 u. G% U  v5 ]# {  L(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))6 T- o& r  z7 d2 J" A
(setq obj (car (nentsel "\nSelect an Attribute: ")))
( ?  H+ k1 V% V3 c(setq obj (vlax-ename->vla-object obj))+ w4 N- x9 U7 R0 u
(cond. K% Q; Q5 D, }$ T9 B
((= (strcase att) "A")7 j" K) M' Q4 w/ h: L# @% `; o. U( j' L
(setq ang (getstring t "\nNew Angle: "))2 N. w9 L$ O( b& p. _
(vlax-put-property obj 'rotation ang))1 I% U3 Q: p0 {: u7 i% b$ c- U
((= (strcase att) "C")  }0 E  A" S+ l9 o
(setq col (getstring "\nNew Color Number: "))
( q' T9 S4 n" P, j7 J3 V  y(vlax-put-property obj 'color col))
. h( B* Q9 }( P( }8 r1 q((= (strcase att) "H")
+ b& k' [: @7 M3 v(setq ohei (vlax-get-property obj 'height))8 S( o0 q5 T; M4 H7 L
(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:")))0 Z( {9 a  Y( j5 ~% s' ^5 J% r( f7 _
(if (= hei "")(setq hei ohei))  c- K( n0 K4 f  s; U# l# g; I
(vlax-put-property obj 'height hei))- N8 u- p4 [' a5 l
((= (strcase att) "L")
4 U, g$ u/ L$ `% r9 a3 t3 @(setq lay (getstring "\nNew Layer:"))
. b0 s# z; v6 r(if (not (tblsearch "LAYER" lay))
3 d9 T* K, A  c. _' z9 ]3 i(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))
* U  b! k" U+ O) S: d  b(vlax-put-property obj 'layer lay)" G" k' z% K' |5 Q% ]1 Q9 P/ W& @
))
7 k  T& z. `( d5 U9 t8 u$ S0 b# @((= (strcase att) "P")9 x5 ~2 w7 _$ D2 h) D) s
(setq pos (getpoint "\nNew Position:"))6 _4 a5 X- w9 C+ W& V5 k
(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))
0 j9 f9 U6 c( L4 a7 K* V0 M  C((= (strcase att) "S")3 P2 D$ ?9 w! Y4 \
(setq sty (getstring "\nNew Style: "))
3 j* _, W  T9 A* \$ e  u(if (not (tblsearch "STYLE" sty))% A2 f, y( ~: K7 Z0 q
(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))
# X9 h  ~" B% y% K  |# U(vlax-put-property obj 'stylename sty)+ m0 G$ m' v' v% @0 L! q2 T
))/ H- S; T9 F& V3 ~# U+ j
((= (strcase att) "V")* @  h7 s6 \4 p& t& t6 }9 O8 X
(setq val (getstring t "\nNew value: "))" a9 S0 D" i" C+ W7 J
(vlax-put-property obj 'textstring val))
9 {% e: Y: `0 `" x);c' J) X6 ~  m( w( f$ }0 q
(princ) + m! B! Q! h  Y3 @9 X+ X0 o* z
);defun

. S3 `. s% s! h7 i! Q8 iVBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性
# y5 I" x) r2 I, |3 o6 x' Get the attributes for the block reference
9 b% d6 K) [* j8 @3 P# J  r    Dim varAttributes As Variant
: H; s% J  p/ u. k, ^    varAttributes = blockRefObj.GetAttributes# q0 _2 ]7 K- h
    4 g* H+ I8 R+ _) z! z0 f3 j2 G
    ' Move the attribute tags and values into a string to be displayed in a Msgbox' f; F0 x* P  W
    Dim strAttributes As String1 B/ L) L. E( |2 X. x* o, \
    Dim I As Integer
1 d. X5 Q) U& f: U    For I = LBound(varAttributes) To UBound(varAttributes)
' T8 L5 m! ?7 u( a2 u        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _2 ]$ y0 P/ ], b) ]: ?
                        "   Value: " & varAttributes(I).textString & "    "# V; m4 p: i6 e# i4 \" J. O& y
    Next$ @  n' _- r% P; ~! |( J4 {
    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"
1 K% a* l# t9 P    3 A; }3 J/ H% T% p% ~
    ' Change the value of the attribute* A( y1 f8 n( H6 p" k/ w
    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.8 {' ~5 c( b5 w5 d8 _. n( H
    ' Changing them changes the objects in the drawing.
6 l0 y9 U' v& Y$ E4 w; }# }    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

 楼主| 发表于 2008-7-8 10:35:22 | 显示全部楼层 来自: 中国辽宁鞍山
如果用VBA来实现的话, 该怎样做???VBA与LISP相比,在处理这类问题上哪个更容易实现??再次感谢楼上的$ X% x2 e. F( r" R$ h5 L5 ?) c$ m

9 ~6 R7 t* q! p$ @% S, x[ 本帖最后由 maoyangmy 于 2008-7-8 10:37 编辑 ]
 楼主| 发表于 2008-7-8 11:20:45 | 显示全部楼层 来自: 中国辽宁鞍山
5楼的能不能把VBA的解决方案也分享一下, 非常感谢
发表于 2008-7-14 22:24:59 | 显示全部楼层 来自: 中国天津
建议用VB弄,可以选择的项目比较多,控制性更好些。  s% T0 a/ K8 d" }! z5 U! J. f
在CAD的帮助文件里有例子,可以参考,我当初就是利用那个例子实现的自动编号。
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则


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

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

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