QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
怎样修改属性块中的属性???( L; U8 T* D: W
因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?2 @7 u. Y& |5 d5 R& N4 y
VBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;
8 C4 I) v- e& B8 J可以试试下面的代码:
3 b2 a/ ]: E/ K1 h! l" l(defun c:test ()
/ S8 Z3 d1 e# z  B1 `  x) r8 N6 T(vl-load-com)
3 C$ b$ J9 y1 Q5 d& m% r(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))7 p( e7 y- Q) j& V+ E8 s8 ^
(setq obj (car (nentsel "\nSelect an Attribute: ")))
4 |" M/ B, t: u6 o* R  [  n2 l4 i(setq obj (vlax-ename->vla-object obj))
9 e. P5 p1 J2 F; Q) S# C(cond
7 W4 N$ X) `1 K5 d# _4 ~( m((= (strcase att) "A")9 Q) o* E: d9 ]; R8 T
(setq ang (getstring t "\nNew Angle: "))" ]4 C! J9 |4 }
(vlax-put-property obj 'rotation ang))
$ N# ^$ ~7 S, Y% |9 t& I8 {((= (strcase att) "C")
( T. d5 E! O' g5 o9 b. a(setq col (getstring "\nNew Color Number: "))
' \) _6 L$ i) p6 ~(vlax-put-property obj 'color col)); M9 P+ u/ W0 a
((= (strcase att) "H")8 \3 ]' ~3 r. @# f# R+ ]% [6 X
(setq ohei (vlax-get-property obj 'height))5 [; e6 y; `& ~* S. w' i
(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:")))  d) _# v: R& `8 y
(if (= hei "")(setq hei ohei))
: b! j/ Y, H, a. y( `) H(vlax-put-property obj 'height hei))$ ~% d  T# B% n
((= (strcase att) "L")
% w) p2 R; s/ a+ ~' V; S(setq lay (getstring "\nNew Layer:"))! i! c( k' x* Z: y. o% o
(if (not (tblsearch "LAYER" lay)): i: H( }7 w( }+ B- l7 t! O
(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))
; k; j; i6 r( Y7 ~- ^% D(vlax-put-property obj 'layer lay)" [6 j" v# ?6 r! A) _
))
: b8 @$ i3 q' q7 H((= (strcase att) "P")
; f1 `' j- ~/ o2 i% \(setq pos (getpoint "\nNew Position:"))
8 X( v& h; ]7 M  r8 ~- }( A6 G(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))  W5 O* d4 Z# c
((= (strcase att) "S")& u  i1 t) u6 R9 ~) W" r) `; i% y
(setq sty (getstring "\nNew Style: ")), C5 |' [* U. [6 N
(if (not (tblsearch "STYLE" sty))
% N! h" u# x2 K# @8 b0 M(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))6 D# ~) S. ?- W5 X) K' w, Q
(vlax-put-property obj 'stylename sty)  t$ m& N  y/ Q- {( n& V3 g( M
))
2 z6 o$ ?3 z  [7 \((= (strcase att) "V")( L# r( b$ [8 d8 ?- X6 X8 C
(setq val (getstring t "\nNew value: "))
! b$ \- X6 b' E( G" p9 Q(vlax-put-property obj 'textstring val))! L# y8 _  A$ x
);c
" E+ f% I8 e8 M4 e(princ)
8 @9 w5 p* N8 d);defun

+ T6 R/ Y' J/ R3 v: \. ?* N0 zVBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性
, `) M9 V* R% u, Q3 [% }8 d4 E' Get the attributes for the block reference& v0 i+ k" p. L$ a" o9 g* U. O2 u) b
    Dim varAttributes As Variant
; ~# j8 L% \# {( d3 {! W, g) o$ K% m0 r- Q    varAttributes = blockRefObj.GetAttributes) U  k  v  @5 v+ o4 y) G
   
" {' d% x) Q) G$ l, O+ k    ' Move the attribute tags and values into a string to be displayed in a Msgbox# x# ^! y9 E$ T+ \% X! Z
    Dim strAttributes As String6 \8 y+ m$ B/ j% ]3 d" b" K
    Dim I As Integer8 g6 l6 m3 v  n& M
    For I = LBound(varAttributes) To UBound(varAttributes)
3 ^7 ]3 {" M9 d, t        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _
- ]+ b: ~: d3 r                        "   Value: " & varAttributes(I).textString & "    "
8 L* B3 n5 Y6 T9 V    Next' V7 ]0 H! g) X2 `( }
    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"; L0 x% g% C' p9 o  M. F% Y' R
   
1 w: ?5 F; t+ F, L* X    ' Change the value of the attribute+ n5 V6 O8 |  C. `- N! \5 _0 G
    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.) A* u: s0 |! U: U' K0 e7 N; `- t
    ' Changing them changes the objects in the drawing.
. ^4 Y5 g( d# {0 H    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

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

本版积分规则


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

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

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