QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
怎样修改属性块中的属性???
% {' I* \" H) u& C0 ~因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?
, [$ r; L7 j' x( _1 ?) FVBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;. o; g8 c" ]5 W: B4 ]
可以试试下面的代码:
4 \& }9 ^- d( u! g( r(defun c:test ()$ ~2 p6 b% y, o8 v
(vl-load-com)
; w1 N, L$ A! T- J% V(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))7 n% ~) W* V) d, R; g" W
(setq obj (car (nentsel "\nSelect an Attribute: ")))4 `1 v  M5 X1 Q: G0 ^7 v
(setq obj (vlax-ename->vla-object obj))1 r9 q' I2 T& O
(cond4 `7 ~$ U" h" V( m7 X# H
((= (strcase att) "A")
9 _4 ^% h" E! C& ?, Y5 \. g, ?1 d(setq ang (getstring t "\nNew Angle: "))
& X% R1 M( q5 V8 x* m, u(vlax-put-property obj 'rotation ang))
5 e, u) O" c* V8 b1 J* z((= (strcase att) "C")
8 ~! l0 q* R4 s2 O(setq col (getstring "\nNew Color Number: "))% S$ T8 q2 Z% y# f
(vlax-put-property obj 'color col))
' q& a- B  K' X% L5 y((= (strcase att) "H")
* ]4 B& U  E+ y(setq ohei (vlax-get-property obj 'height)): a  ~. w+ q, @1 M
(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:")))4 q2 P  d9 g1 S1 ]( R" C
(if (= hei "")(setq hei ohei))
. C7 t  G/ L0 P0 M! m( O8 f(vlax-put-property obj 'height hei))
% _6 r1 z4 Y3 j9 m0 {: J+ g, x((= (strcase att) "L")3 @# {0 d7 N! d& C
(setq lay (getstring "\nNew Layer:"))' {! d" \) _" G: f- ?' a6 T) q
(if (not (tblsearch "LAYER" lay))
5 E5 O, C* R3 ]7 {0 U(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))
% \; E' W5 R$ w! \. y0 c" Q(vlax-put-property obj 'layer lay)$ G0 ~6 L8 c8 R% s% c" z  Z- d; K7 u6 i
))0 g' m% `" M* k) M/ r
((= (strcase att) "P"), v  X& w- E5 T5 ~( j8 q9 Y6 i1 v
(setq pos (getpoint "\nNew Position:"))
  T4 H! f. O/ ~0 F  t" u(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))
& J" J  z0 D# ?7 |/ O4 m" e((= (strcase att) "S")
& d/ M& |# l* R(setq sty (getstring "\nNew Style: "))/ V& d2 H  u+ V' B& H8 J
(if (not (tblsearch "STYLE" sty))* A+ S5 V. D- o2 [5 i& r; `6 x) v" {3 `
(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))
5 E1 A4 V. |3 A7 y) R(vlax-put-property obj 'stylename sty)
- w& h$ x. ~+ M- q+ E( l" }))# z3 b; I. l+ t. \- X
((= (strcase att) "V")) D: _: N1 d! d. R0 r
(setq val (getstring t "\nNew value: "))
/ [5 J1 e& d' @5 Z; C6 |(vlax-put-property obj 'textstring val))
2 T: O) u, j) j/ H7 p* m, Y);c4 y6 _; v0 }5 ~1 J" L
(princ) 7 e1 n. c6 g  G9 n
);defun
: n4 o% E2 |& M$ O6 _  ]4 }
VBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性+ E! x) K1 B; l- n9 F+ N4 O
' Get the attributes for the block reference
: [- |; y+ L4 `8 b. ~    Dim varAttributes As Variant, p, x# d+ M0 j* C; k$ ~% E% v5 ^
    varAttributes = blockRefObj.GetAttributes
8 u) A0 a" i3 K% [  j   
) \1 b' [1 o/ N7 i, }! b    ' Move the attribute tags and values into a string to be displayed in a Msgbox
( t4 ^: s8 Z- v- w) V6 b    Dim strAttributes As String; V. t! J7 z* k
    Dim I As Integer8 `7 t  c1 j# P8 E
    For I = LBound(varAttributes) To UBound(varAttributes)
- U2 Y# P3 r! U0 `! M7 N, w        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _
  D5 Y4 @! @& l% O7 I                        "   Value: " & varAttributes(I).textString & "    "  A. K- p8 k0 x2 p. ]* y" B
    Next
) S* H3 w* t" L0 ~! o- n    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"
# g4 }6 r5 v$ t0 s( f" f    / t0 C4 i6 N# G& W: |
    ' Change the value of the attribute
% {1 Z- l7 W! J) t    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.
; m8 _, A% g: D, O! _& Y    ' Changing them changes the objects in the drawing.
% t: s6 A( o3 J+ q3 f8 P2 w. ^    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

 楼主| 发表于 2008-7-8 10:35:22 | 显示全部楼层 来自: 中国辽宁鞍山
如果用VBA来实现的话, 该怎样做???VBA与LISP相比,在处理这类问题上哪个更容易实现??再次感谢楼上的
5 M6 u% u+ \* {  g6 V
: |2 ^  E% y4 E[ 本帖最后由 maoyangmy 于 2008-7-8 10:37 编辑 ]
 楼主| 发表于 2008-7-8 11:20:45 | 显示全部楼层 来自: 中国辽宁鞍山
5楼的能不能把VBA的解决方案也分享一下, 非常感谢
发表于 2008-7-14 22:24:59 | 显示全部楼层 来自: 中国天津
建议用VB弄,可以选择的项目比较多,控制性更好些。, b7 L: p, }* {' [  y+ n
在CAD的帮助文件里有例子,可以参考,我当初就是利用那个例子实现的自动编号。
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则


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

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

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