QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
怎样修改属性块中的属性???- p6 V- q9 `" r
因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?& i; b) k' P; P. n
VBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;
+ s" }/ e5 ^. z. w, A5 P可以试试下面的代码:
* r6 ~4 K  m# w2 G! M, v(defun c:test ()
) K7 \/ c# ^  C/ L(vl-load-com)
( J- i/ n! `+ E6 \5 j(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))! q2 [, W) l' U
(setq obj (car (nentsel "\nSelect an Attribute: ")))- N' z; v9 ?- f5 A$ J+ R- ]
(setq obj (vlax-ename->vla-object obj))( ~5 e1 o9 k. B5 k' T
(cond4 A4 r  k8 ~5 l: o( d3 @
((= (strcase att) "A")
$ [' D: i" [$ [8 Z0 H3 s0 {) E(setq ang (getstring t "\nNew Angle: "))( t7 F3 y; D7 B5 f; p, q8 T
(vlax-put-property obj 'rotation ang))' }! F0 v2 N- U  A
((= (strcase att) "C")' v; h/ i4 |7 T) ^/ i
(setq col (getstring "\nNew Color Number: "))
: i8 R2 Q( \( c9 g* s(vlax-put-property obj 'color col))
0 F! ^. e+ k6 U! ?((= (strcase att) "H")
4 a9 r0 A0 T% x# ?* K: _(setq ohei (vlax-get-property obj 'height))
- c0 R9 [- ~; M2 y& y; ?(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:"))); |, A4 o) a+ K$ L' l0 V
(if (= hei "")(setq hei ohei))5 ~7 G" l9 m1 f$ \" [
(vlax-put-property obj 'height hei))9 Q$ ^- N# f" g& r7 m* _1 r
((= (strcase att) "L")  G. n. ^) t. s4 v/ o) \+ D+ `
(setq lay (getstring "\nNew Layer:"))
! g( F1 Z! v: S' }# W, N; ](if (not (tblsearch "LAYER" lay))* S: K+ X. y4 q
(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))
8 R7 o% k( q3 I- b(vlax-put-property obj 'layer lay)
! L/ K$ Z* e  c5 q9 }))9 s; K: Z! g8 @$ r3 c( @
((= (strcase att) "P")
* h$ n; E' y. w0 H5 t(setq pos (getpoint "\nNew Position:"))
& R/ r+ b. z' I* [( ?( d  Q% B(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))
2 h7 y" B0 G9 b( \" v: l; _((= (strcase att) "S"); Y# R1 c9 \  q* f' f* p# K. C
(setq sty (getstring "\nNew Style: "))
1 d4 C$ A6 X( B' e. e3 C(if (not (tblsearch "STYLE" sty))* N" L2 r/ a5 Z2 V+ e- z8 ^8 `
(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))
9 M9 Q7 b6 v  f) [(vlax-put-property obj 'stylename sty)
, s( N! }* E2 X))
. S* B: u) K- J((= (strcase att) "V")* W, G) w( B0 P$ s* g- R
(setq val (getstring t "\nNew value: "))
0 n* h$ l$ r5 m0 e; S8 e; D(vlax-put-property obj 'textstring val))
3 P* g  h, {' t2 L/ ^);c
- w) x! D9 t# f+ i- D# {8 S3 M, V' W(princ)
) @1 o$ n  o) m9 \# Z; ?; B% |);defun
! \) G  A2 }' b) f. i. q1 H, a
VBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性
1 B5 l( n- M( Z* L  E& L3 G1 c( @% F' Get the attributes for the block reference
7 s3 I, u3 Y  t% _+ N    Dim varAttributes As Variant0 w; ~% j" M6 D! l2 o0 ~9 f$ S
    varAttributes = blockRefObj.GetAttributes
5 c  I: h7 I/ X4 L   
8 ]0 v5 ]# i) d1 j9 K* }    ' Move the attribute tags and values into a string to be displayed in a Msgbox2 T* ]: }9 q4 l% m4 X
    Dim strAttributes As String
) v4 F( f1 V6 E9 T1 T    Dim I As Integer: [) z3 e" A: v( c, p+ B9 X$ w7 ^
    For I = LBound(varAttributes) To UBound(varAttributes)  h. p$ h8 L. S- l- T3 [
        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _
7 p* P1 l7 d. E                        "   Value: " & varAttributes(I).textString & "    "
% r- }2 z, {# W( H8 ^    Next: Y' U5 ?$ y( Z/ _
    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"
5 @1 ^) v! B/ Q2 q' I4 H   
" k0 d( M+ h6 a6 \# j/ f    ' Change the value of the attribute
4 U  Y- f1 q1 d    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.. h3 d/ `/ _; f0 e3 r9 p
    ' Changing them changes the objects in the drawing./ E- A8 N$ P- v( h
    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

 楼主| 发表于 2008-7-8 10:35:22 | 显示全部楼层 来自: 中国辽宁鞍山
如果用VBA来实现的话, 该怎样做???VBA与LISP相比,在处理这类问题上哪个更容易实现??再次感谢楼上的
+ _! J7 V/ O% k( k$ l" B; I# g2 l, G
[ 本帖最后由 maoyangmy 于 2008-7-8 10:37 编辑 ]
 楼主| 发表于 2008-7-8 11:20:45 | 显示全部楼层 来自: 中国辽宁鞍山
5楼的能不能把VBA的解决方案也分享一下, 非常感谢
发表于 2008-7-14 22:24:59 | 显示全部楼层 来自: 中国天津
建议用VB弄,可以选择的项目比较多,控制性更好些。
2 Y. e" i. o: T$ c7 }+ S( A3 Z在CAD的帮助文件里有例子,可以参考,我当初就是利用那个例子实现的自动编号。
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则


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

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

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