QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
怎样修改属性块中的属性???
! |& D( S7 _* J5 U- r因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?$ s4 O7 u3 C7 x( W' ]( P, ~4 X+ v
VBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;5 ^/ H% O4 j" G/ \0 `; @
可以试试下面的代码:# v3 j2 b& h4 Z$ e; X7 |8 T7 T: o
(defun c:test (); d- w2 q+ Z% C9 h% b/ k4 w
(vl-load-com)
) \8 U! a/ {% g4 T& w(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))
9 T. H0 U+ F5 e) e1 V/ F(setq obj (car (nentsel "\nSelect an Attribute: ")))7 B* R) D+ r% G  B, W' Q2 P2 o
(setq obj (vlax-ename->vla-object obj))$ t* Y- H, u. a# i8 @
(cond. L* R2 w8 h( m; S- a
((= (strcase att) "A")
; h8 n$ l6 T7 {9 x(setq ang (getstring t "\nNew Angle: "))
7 A4 m. R" z+ B; t& W) X6 }$ z6 @. E(vlax-put-property obj 'rotation ang)): V& ?) p$ D! Q5 n7 c- G, l
((= (strcase att) "C")2 O: {6 {1 m7 N# Z# I3 @
(setq col (getstring "\nNew Color Number: "))+ `" U" r6 ]/ x1 v, y4 a+ T
(vlax-put-property obj 'color col))
% q0 b9 x: `& I9 \8 i((= (strcase att) "H")# W3 y  e7 {- f- u0 [6 D
(setq ohei (vlax-get-property obj 'height))
4 m3 s) ~# X9 `3 U, @* K(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:")))' W4 b2 u+ f0 C' o2 n4 W! }5 [9 K& U  ]; m
(if (= hei "")(setq hei ohei))
7 b% g/ U9 E8 k% f(vlax-put-property obj 'height hei))
, F* ~4 l9 H. Q/ H' W' I4 n) S$ b((= (strcase att) "L")) g0 e2 c. e( U# `' {( z. Z# K
(setq lay (getstring "\nNew Layer:")); R, y1 v# V6 C4 x; u, l  b& B& t
(if (not (tblsearch "LAYER" lay))4 ]; F' G( {( d: {+ a
(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))9 ^, `# O$ A0 C5 c. \8 T3 v
(vlax-put-property obj 'layer lay)4 w. n- E3 Y0 \
))! {( Q, D3 W6 E; m
((= (strcase att) "P")
8 L( r! x3 u5 n: x(setq pos (getpoint "\nNew Position:"))
! |3 U: @5 {7 l) T(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))
$ Q) J, K' S7 L4 v4 b' u((= (strcase att) "S")
: l& V+ F3 q& M( Z(setq sty (getstring "\nNew Style: "))
# ^% Q9 ]; y- v; E(if (not (tblsearch "STYLE" sty))- H7 B& U- R8 y$ _. |  A
(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))4 Z+ R2 M  m% C/ w
(vlax-put-property obj 'stylename sty)5 u+ I0 M" R0 a* H/ f  D! K% G
))  }# H9 |1 a0 Q9 E! S$ D- Q1 f5 U
((= (strcase att) "V")
  g: L6 t. Q0 K(setq val (getstring t "\nNew value: "))
7 B0 D  _1 p& j: S( l5 L. [(vlax-put-property obj 'textstring val))
/ `+ n& F0 Z# I4 P% B: W" |);c
1 X6 l' A& r% M5 B: h2 S: ](princ) . z9 j. c8 ?, ]5 i9 ?# U4 i
);defun
- n5 ^3 T* ?* q4 V9 c
VBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性
  i0 V3 h7 C  s- ^; U. \  Z* w' Get the attributes for the block reference
3 z+ @( v: ^* ]$ v8 E* x    Dim varAttributes As Variant% T" V) e3 l0 p  ?+ O! b
    varAttributes = blockRefObj.GetAttributes
  B. [4 J* a* x7 P, ?0 R' b) V    8 L5 p/ J6 _/ P( {: I" B( v; j
    ' Move the attribute tags and values into a string to be displayed in a Msgbox
8 G4 z3 e! P/ \3 b5 ~    Dim strAttributes As String; `6 g' ^) Y' N- V' g
    Dim I As Integer
4 B9 Y. J/ Y. z3 ~6 z6 j5 t    For I = LBound(varAttributes) To UBound(varAttributes), ~# r% e. F2 f( J
        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _
2 v. z9 A/ {# i                        "   Value: " & varAttributes(I).textString & "    "
5 E5 W) U# ^* x6 W4 A2 L3 L1 v5 Z    Next  T) i  i1 q2 m& r* C
    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"6 \, J9 l, Z/ z2 X+ a2 s
   
4 N) y6 B% ~8 B0 T( W( D0 z    ' Change the value of the attribute0 R1 g; p; m6 Y/ U) X/ R& P
    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.* k. a- x# A4 G1 b9 P/ w! k! S
    ' Changing them changes the objects in the drawing.
/ }2 M: M+ p* N* ~    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

 楼主| 发表于 2008-7-8 10:35:22 | 显示全部楼层 来自: 中国辽宁鞍山
如果用VBA来实现的话, 该怎样做???VBA与LISP相比,在处理这类问题上哪个更容易实现??再次感谢楼上的( W6 {% `* _4 o6 W. J

1 j" V1 S/ `  x; Q; ^6 P3 J# C[ 本帖最后由 maoyangmy 于 2008-7-8 10:37 编辑 ]
 楼主| 发表于 2008-7-8 11:20:45 | 显示全部楼层 来自: 中国辽宁鞍山
5楼的能不能把VBA的解决方案也分享一下, 非常感谢
发表于 2008-7-14 22:24:59 | 显示全部楼层 来自: 中国天津
建议用VB弄,可以选择的项目比较多,控制性更好些。
$ L9 Y8 B4 M% `  c; i6 o, i在CAD的帮助文件里有例子,可以参考,我当初就是利用那个例子实现的自动编号。
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则


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

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

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