QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
怎样修改属性块中的属性???
7 N  h. t7 h1 N因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?) N6 B) {/ o" t0 t% y
VBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;
# q: [4 H1 b! K1 t# ]) W0 n% U  o可以试试下面的代码:
( b7 F2 H& M$ B( |# c: Z1 I' A(defun c:test ()
' \: q- D3 i( R(vl-load-com)
" B% J) N+ q0 h! v# v# i(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))6 w, ?7 B& y8 p% i
(setq obj (car (nentsel "\nSelect an Attribute: ")))
) y9 S: c1 x( |3 O$ r  q5 h(setq obj (vlax-ename->vla-object obj))
+ g1 H. u; d: f7 [4 p% j(cond
% a8 Z" w0 `' S((= (strcase att) "A"); \# ~/ D7 k! Q. c& l
(setq ang (getstring t "\nNew Angle: ")): u' A3 B* s4 s* T& }  {$ V
(vlax-put-property obj 'rotation ang))* `0 }; A# f0 L* C; _/ A3 v2 N
((= (strcase att) "C")
* T. E3 n8 N  S3 ~: G/ J(setq col (getstring "\nNew Color Number: "))0 g- [+ o4 G) q1 J
(vlax-put-property obj 'color col))
- t' I& [* y+ M- t* H6 T6 b((= (strcase att) "H"), p  u/ P* j# D# d
(setq ohei (vlax-get-property obj 'height))
/ n. Z0 U# V; f( P# w' i(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:")))6 N- @. J3 E- H; h' Z7 D
(if (= hei "")(setq hei ohei))) |# P6 H/ ]$ @6 N; ~
(vlax-put-property obj 'height hei))
8 c/ e3 c" O& y6 l5 b" u((= (strcase att) "L")9 @7 g0 i) {* X' G$ O4 I2 v# E
(setq lay (getstring "\nNew Layer:"))( C$ {' W, _; ~
(if (not (tblsearch "LAYER" lay))
9 ~3 ^  @8 T1 S, ]1 A+ P* V& |8 q- V(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))9 j9 a" S# o/ Z. y. f1 w* P
(vlax-put-property obj 'layer lay)3 b5 P( b/ o+ Q5 n: S
))
- B% y$ ?$ R( }! V0 z$ ~((= (strcase att) "P"); \# H9 d! A( }' T0 I
(setq pos (getpoint "\nNew Position:")): ^* z( o! _- q9 J1 J! Y5 O/ q
(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))
  u* D! J  s" R# u7 T((= (strcase att) "S")0 _4 S2 j# }. {/ n: Y) j
(setq sty (getstring "\nNew Style: "))
3 w# t& B) I! D7 Y" S( H(if (not (tblsearch "STYLE" sty))
9 I0 k- k  e: P(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))
) o1 q3 ^1 c$ B: {. W* H, q" g3 ^(vlax-put-property obj 'stylename sty)
6 x8 l( Z4 G2 D))8 }& ~& J7 ?. {/ M% k5 n
((= (strcase att) "V")
& C, `, }' _2 N* i2 U(setq val (getstring t "\nNew value: "))
3 z* P: `3 K, x- ~(vlax-put-property obj 'textstring val))
$ P: S$ u- `2 ^" P9 M$ ^9 u);c$ M9 ]* ?6 T) R# B- I2 z
(princ)
- q" t+ s0 d6 U* ]  k) e/ r);defun
$ _3 }7 z" T8 o' _  |" A5 L
VBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性# W' i# t5 P2 G" K* r5 C+ ^: n
' Get the attributes for the block reference
  z, W/ c* u4 N- A4 A1 b, o    Dim varAttributes As Variant0 h- {' W1 [  y" }, i6 k
    varAttributes = blockRefObj.GetAttributes/ E! m/ ?* _8 `) Y7 U+ }; l
    4 P! X# ?/ I: i( Z" x) h
    ' Move the attribute tags and values into a string to be displayed in a Msgbox4 F! ^- [" G, u4 k1 F# J
    Dim strAttributes As String
; }. W) G2 K" y% ]7 T% T6 Z    Dim I As Integer
7 X8 \8 r$ q9 l    For I = LBound(varAttributes) To UBound(varAttributes)2 O" p" r6 R, P; Z1 s0 {
        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _
& a% c5 K% O1 d0 L  r                        "   Value: " & varAttributes(I).textString & "    "2 |: @5 a, B! b. }$ W' L5 _5 u
    Next
! W! u" s: S5 Z& s5 Y  \    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"9 v2 F6 Y' A* f: H' `: w2 v
   
. V8 A8 \$ Z( {6 B/ h+ t6 k3 y    ' Change the value of the attribute; y. `) ?0 X0 r
    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.( B; r. i0 |2 d0 ~
    ' Changing them changes the objects in the drawing.
$ T$ `! P/ a2 R' {    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

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

本版积分规则


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

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

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