QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
怎样修改属性块中的属性???  }' t) T2 B# r5 y$ F! E) S9 {+ x
因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?
6 l% }% ~7 c! S" eVBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;
! j8 c+ E) v# |7 ^可以试试下面的代码:# m( l  Z& o  c: b& U' ?' U
(defun c:test ()7 w- Z2 v# e4 t" C& Z9 z, B7 q
(vl-load-com)
1 |) X, J* l3 P+ n" Q(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))' V: p9 E' x& G! N+ s1 H1 }
(setq obj (car (nentsel "\nSelect an Attribute: ")))
+ M" I/ r. U5 x! e/ w- n  h(setq obj (vlax-ename->vla-object obj))
  Y- i$ d" r) v: |8 e(cond
  c1 M' h! D# A) v$ V: g((= (strcase att) "A")% }( K5 M8 N9 R4 u8 ~; A+ s  j
(setq ang (getstring t "\nNew Angle: ")); b. b; G3 v1 k  y) K
(vlax-put-property obj 'rotation ang))5 [0 S9 {- U, J* m& h
((= (strcase att) "C")
5 W6 o5 y* M+ n) _) {! P+ Z(setq col (getstring "\nNew Color Number: "))
" i# ~# g+ Y' e/ y: T# J" ]" h(vlax-put-property obj 'color col))
0 R8 O$ _: @9 |* v6 y; \3 `9 r& H9 I+ v((= (strcase att) "H"). \( y  U4 S8 m' s1 H3 e) z
(setq ohei (vlax-get-property obj 'height))
- n8 w& ]5 k) K, k(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:")))
: Z; k% h! c# r& l0 F(if (= hei "")(setq hei ohei))
9 i* i+ O& v7 y$ P/ ]; C(vlax-put-property obj 'height hei))+ P- M# @8 t+ R! t' ?" a
((= (strcase att) "L")& ~# G9 X* j$ H' M
(setq lay (getstring "\nNew Layer:"))
$ y: _  _' t, ^% I. ]% c6 |(if (not (tblsearch "LAYER" lay))
5 d+ v1 T/ M/ l3 q6 J- `% b/ N(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))
3 ^& P% G. |' w. y. f. y(vlax-put-property obj 'layer lay)
' A! `! F; \: u. l/ X. n/ S))7 Q% K! \5 F# I6 _; k
((= (strcase att) "P")2 S$ s+ i# ~- E! ?. A8 M
(setq pos (getpoint "\nNew Position:"))
: V/ x, m: K! d6 c1 r(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))8 g+ u8 ^) [0 Z2 n5 [! F
((= (strcase att) "S"); {, E4 K  W9 S2 _1 y) o8 \
(setq sty (getstring "\nNew Style: "))
& m2 K4 K1 M( M8 O% m(if (not (tblsearch "STYLE" sty))
  w6 n" q9 r& f% k(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))
" }% q: N; m. m) C. h" x: a(vlax-put-property obj 'stylename sty)
) E  K$ m: B% P))1 k1 ]" W  A1 F
((= (strcase att) "V")* m: L& Y9 n( m' e! Y# L
(setq val (getstring t "\nNew value: "))
7 _1 h9 u* u# ~(vlax-put-property obj 'textstring val))
+ y! r2 k# n  S$ {$ [);c6 s: i9 S7 ?1 U3 a( R* v, J
(princ)
2 M$ X$ X1 R" Q+ I);defun

+ l1 N% V; N0 i% o, d' CVBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性
0 k5 T; V; _9 o1 [' Get the attributes for the block reference
; Q0 X( w& e- R    Dim varAttributes As Variant2 V4 G" _4 e- r5 l# E
    varAttributes = blockRefObj.GetAttributes
- e0 t5 c* R  `+ W: H   
! J5 _- k& m' o1 b5 _3 Y( _$ A9 I    ' Move the attribute tags and values into a string to be displayed in a Msgbox6 ^3 q* A7 O2 T
    Dim strAttributes As String) L, [/ \( {" v4 Z4 `
    Dim I As Integer. ~! V8 e) e% e  t0 r
    For I = LBound(varAttributes) To UBound(varAttributes)# m( \$ a) w7 T& B! \+ m
        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _
3 J" F3 S# z( |! W                        "   Value: " & varAttributes(I).textString & "    "7 g) i4 L( L% Y- {) q) T
    Next
" d4 e# q( A" e; e. h7 M) F( J9 C    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"0 j2 o1 A- X/ u. D: p. W5 A
   
9 Z* n& I! B" W5 L5 n1 b- y    ' Change the value of the attribute( w+ L  h. N8 C$ [, W: f+ O5 |3 p
    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.! b9 [7 F7 F' ]) h2 Y
    ' Changing them changes the objects in the drawing.
$ ?: j2 T& H1 S2 d( w, J. ~) N    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

 楼主| 发表于 2008-7-8 10:35:22 | 显示全部楼层 来自: 中国辽宁鞍山
如果用VBA来实现的话, 该怎样做???VBA与LISP相比,在处理这类问题上哪个更容易实现??再次感谢楼上的
4 x% q: u$ t" J7 B+ V6 P+ F
9 _* t  z) n3 ?3 D9 r[ 本帖最后由 maoyangmy 于 2008-7-8 10:37 编辑 ]
 楼主| 发表于 2008-7-8 11:20:45 | 显示全部楼层 来自: 中国辽宁鞍山
5楼的能不能把VBA的解决方案也分享一下, 非常感谢
发表于 2008-7-14 22:24:59 | 显示全部楼层 来自: 中国天津
建议用VB弄,可以选择的项目比较多,控制性更好些。1 x& L6 \: S2 H4 T) c
在CAD的帮助文件里有例子,可以参考,我当初就是利用那个例子实现的自动编号。
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则


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

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

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