QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
怎样修改属性块中的属性???' @# N1 _* [4 {0 ^# k7 y* L
因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?
  }( h$ w& X/ UVBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;
" A' y- U/ g8 U$ `! ^. i可以试试下面的代码:
. V, y; v' H, X! F0 w& B(defun c:test ()
' w9 t5 Q3 M4 C* B: Y(vl-load-com)- J* I: s7 H) F; A
(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))/ l. y$ M3 a# y# H) a, b
(setq obj (car (nentsel "\nSelect an Attribute: ")))
4 c. g2 H7 u1 n5 \5 M(setq obj (vlax-ename->vla-object obj))* j( C: f- K2 M1 M4 i4 @( u  O: e
(cond5 g$ a4 r  g% _" W, t- f4 J
((= (strcase att) "A")$ W0 |5 M+ [7 }3 P
(setq ang (getstring t "\nNew Angle: "))
  p9 ?' E$ s$ o1 f  o: G$ E9 i(vlax-put-property obj 'rotation ang))+ t! m; p9 w0 Z1 j! ?
((= (strcase att) "C")
% i% ^+ b. B1 I4 k(setq col (getstring "\nNew Color Number: "))
( Q$ m. X% y+ ~: e$ I# l1 x(vlax-put-property obj 'color col))
+ p5 Y* X0 ]+ |5 ]((= (strcase att) "H"). i% P4 b2 k5 l' R3 N
(setq ohei (vlax-get-property obj 'height))" x: n5 L+ r( y
(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:"))). B6 r* V" x" B/ I; s2 ^
(if (= hei "")(setq hei ohei))  j  E- ?3 Y- S
(vlax-put-property obj 'height hei))
+ W. ?, p" e0 D((= (strcase att) "L")2 T, t/ m9 D# H4 J- x
(setq lay (getstring "\nNew Layer:"))
: A- |* Y9 {$ }( n2 @1 ]$ |(if (not (tblsearch "LAYER" lay))" P' V$ a+ i7 _. q. \* A
(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))
7 ~7 D/ K* a; K2 A) l(vlax-put-property obj 'layer lay)
2 f4 Y- p: l; a3 y$ G' b))' |+ p, M8 ]. d+ [9 Q; r
((= (strcase att) "P")$ @' y' h) j0 i/ E
(setq pos (getpoint "\nNew Position:"))
) l3 D7 f& L2 k1 U8 C  R(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))
+ K4 O2 C. P. K  H2 \- W& h((= (strcase att) "S")
& `& z0 O/ ]' `# L6 _9 J' @(setq sty (getstring "\nNew Style: "))
+ R8 Z* k7 i8 F& s  a) o* h3 P; x(if (not (tblsearch "STYLE" sty))2 y; l& w# }  I8 B* K4 V
(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))
" P; m( M2 c5 x" P8 D1 |! z(vlax-put-property obj 'stylename sty)3 }" ]9 j& @6 C
)); A$ b& b- W3 J
((= (strcase att) "V")
, R" U& ~+ R8 E: O& I" [9 }(setq val (getstring t "\nNew value: "))
2 u4 T3 Z7 E& b3 f0 O5 X(vlax-put-property obj 'textstring val))
' ]" w+ u  f* e);c
$ s6 a" u9 U( h(princ)
5 o( F# @9 I+ P) `( j);defun
. l5 P( T7 F+ E9 G3 o
VBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性
) \1 |; s" r9 x3 g0 b: r' Get the attributes for the block reference
6 n3 L  m- ~3 C3 [    Dim varAttributes As Variant+ G* v: j( h" l- O: P
    varAttributes = blockRefObj.GetAttributes
; J5 |) T/ g+ w/ {8 c, G8 W   
! i& w1 [; l! C0 p; e  b+ b# b7 n    ' Move the attribute tags and values into a string to be displayed in a Msgbox
3 r3 r6 N# i% h$ m2 p6 a3 S    Dim strAttributes As String# ^3 R) |! N7 e; ?* _9 O
    Dim I As Integer/ D0 f0 x2 |, C- D1 v, X& m
    For I = LBound(varAttributes) To UBound(varAttributes): P$ o3 d' `) g: N! l! A2 W5 l+ G
        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _- f& ^7 r& d) s! h
                        "   Value: " & varAttributes(I).textString & "    "
4 Q$ ^+ ?( {( k& X    Next
0 A9 m0 n+ y/ \  j    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"
; Z% J, o7 i* Z8 V- T    ) M3 t0 e9 ~" q, M; N  z2 D  B
    ' Change the value of the attribute
* u  R* u/ N2 N$ ]" x    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.; m6 ^- ^9 i# }7 \) I4 y  \, Q: i4 s
    ' Changing them changes the objects in the drawing.
% `# X2 `8 k/ p1 r) f0 n  `    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

 楼主| 发表于 2008-7-8 10:35:22 | 显示全部楼层 来自: 中国辽宁鞍山
如果用VBA来实现的话, 该怎样做???VBA与LISP相比,在处理这类问题上哪个更容易实现??再次感谢楼上的& [& y1 _) z, A7 k* x# b

1 q+ b0 P. v* j) b) o[ 本帖最后由 maoyangmy 于 2008-7-8 10:37 编辑 ]
 楼主| 发表于 2008-7-8 11:20:45 | 显示全部楼层 来自: 中国辽宁鞍山
5楼的能不能把VBA的解决方案也分享一下, 非常感谢
发表于 2008-7-14 22:24:59 | 显示全部楼层 来自: 中国天津
建议用VB弄,可以选择的项目比较多,控制性更好些。4 y' G4 Y" {, y
在CAD的帮助文件里有例子,可以参考,我当初就是利用那个例子实现的自动编号。
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则


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

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

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