QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
怎样修改属性块中的属性???. D) r+ _7 ]" ?6 R
因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?
7 S/ m/ F# d: \; _2 j1 H& j1 u9 bVBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;" _2 A4 i6 Z( s4 ?3 W% G
可以试试下面的代码:+ y; D  F. u. y1 d7 l
(defun c:test ()
0 f$ |# Y' K  m/ }! t2 D(vl-load-com): _  o5 F9 x" L# |
(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))
0 I' W2 A0 u) r6 d0 D( R3 g; P(setq obj (car (nentsel "\nSelect an Attribute: ")))' ~# E0 n: H+ v
(setq obj (vlax-ename->vla-object obj))% |& @+ z: [- O9 k) l5 \- W4 V
(cond" x* w( [% V0 R) ^
((= (strcase att) "A")2 L5 P  W7 H8 m* v; {. |
(setq ang (getstring t "\nNew Angle: "))8 x6 ?- ?- ]; Q7 u6 G5 c# W( `
(vlax-put-property obj 'rotation ang))
$ Q0 A$ F! K( B((= (strcase att) "C")
) v' h7 P5 u$ C1 q(setq col (getstring "\nNew Color Number: "))$ |2 h) L) I: K
(vlax-put-property obj 'color col))
5 }- i8 G5 _  P3 r6 f6 o( y3 A((= (strcase att) "H")
4 [$ T- k/ Z" S* @(setq ohei (vlax-get-property obj 'height)): ~; v. F8 i* \$ O. R8 O, F5 O7 Z
(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:")))
0 q! `9 D9 |& o$ C(if (= hei "")(setq hei ohei))! T! G8 x2 X7 e7 Z% S, p
(vlax-put-property obj 'height hei))  ?& Z5 o: c$ ~: Q+ t6 i* ?! r
((= (strcase att) "L")
( C$ S! c, v# ?0 `(setq lay (getstring "\nNew Layer:"))
" P9 {  d( k7 Z(if (not (tblsearch "LAYER" lay))
; V8 _9 Y9 E- o(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))
5 E4 N! B% j7 ?8 Y(vlax-put-property obj 'layer lay)0 `( |; A0 l) j- N$ \  Y  G0 b( `
))
. f& h) b) G' R3 Y8 ~4 f' O((= (strcase att) "P")( n) s! }8 P# n7 q
(setq pos (getpoint "\nNew Position:"))
" |, k8 Y) z, n) z9 t2 Z(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))
% E0 j+ X+ ?( W& Q! K% p% b((= (strcase att) "S")( [& D2 W. }+ x8 S( l1 ~
(setq sty (getstring "\nNew Style: "))
! {0 x$ Q* e3 r( m/ Y" Q(if (not (tblsearch "STYLE" sty))
) K& D+ `0 @) g7 w7 i. a. |8 w  m(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))
* x6 @$ r4 n& S& S5 ?; o7 f0 b- w(vlax-put-property obj 'stylename sty)
* s8 j: C8 W( l: ]# \) u/ I' _))
: ^6 [/ F1 p  N((= (strcase att) "V"); a- K1 _" h% b% F5 F/ i  ]
(setq val (getstring t "\nNew value: "))- M0 p3 {: p7 Q( q
(vlax-put-property obj 'textstring val))% e: I& u5 i0 r4 }. M' ]' v, d
);c
# \" x/ f5 b; ]3 @) z& p. `: m% R(princ) * T' x. ~2 b2 o& ?. U
);defun

! j; a- P! {* K) G) @+ WVBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性
+ D. e' v' o0 p$ K: M' Get the attributes for the block reference
7 ]$ }( w! z( L9 X5 A8 m    Dim varAttributes As Variant# j; e' ^" {0 o0 a% k2 `
    varAttributes = blockRefObj.GetAttributes  h$ O) w) b5 C! ^
    : N. \9 k7 F6 T* u  V
    ' Move the attribute tags and values into a string to be displayed in a Msgbox
# k! Q2 q3 y& C# c    Dim strAttributes As String; o1 l1 P/ G2 X1 A# z1 Y
    Dim I As Integer
. @- p5 z3 m) s7 E: M    For I = LBound(varAttributes) To UBound(varAttributes)0 [* q; G" w4 y6 L& ]$ i! L* O& c
        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _" A5 i8 y) v) y$ z; b4 X& G0 Q
                        "   Value: " & varAttributes(I).textString & "    "
+ C, z$ w0 V+ `1 s0 W, N6 z    Next
) F& g6 ?( ~! @0 i    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"
" G9 f. K* _. u  u   
2 ^0 g# d/ |; @3 x5 N: Z    ' Change the value of the attribute5 J: Z$ u0 B5 N0 {
    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.* l9 }+ y9 X1 k) f. p. v
    ' Changing them changes the objects in the drawing.( V" \1 W: k5 @+ G
    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

 楼主| 发表于 2008-7-8 10:35:22 | 显示全部楼层 来自: 中国辽宁鞍山
如果用VBA来实现的话, 该怎样做???VBA与LISP相比,在处理这类问题上哪个更容易实现??再次感谢楼上的0 q8 y* P  b/ h" x9 D2 x9 j

/ m( v6 h1 `% K( r[ 本帖最后由 maoyangmy 于 2008-7-8 10:37 编辑 ]
 楼主| 发表于 2008-7-8 11:20:45 | 显示全部楼层 来自: 中国辽宁鞍山
5楼的能不能把VBA的解决方案也分享一下, 非常感谢
发表于 2008-7-14 22:24:59 | 显示全部楼层 来自: 中国天津
建议用VB弄,可以选择的项目比较多,控制性更好些。
/ F) f! c' s: k" Y8 R在CAD的帮助文件里有例子,可以参考,我当初就是利用那个例子实现的自动编号。
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则


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

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

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