QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

全站
11天前
查看: 6310|回复: 7
收起左侧

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

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

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

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

x
怎样修改属性块中的属性???
* _# E9 I; X% z; k; c; d因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?
8 D7 J6 C. E# J, X. d% iVBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;
1 }' o0 r4 ^- s& g可以试试下面的代码:# v0 n4 g: e5 D. ^( i5 G* Y
(defun c:test ()
7 ~0 S9 T# Y3 \3 a& ~0 p3 g- `9 C(vl-load-com)
5 J3 c" M" b, ^/ F3 ?(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))
) p  S0 W& L6 k: i2 [2 ~" }, l! ]; V(setq obj (car (nentsel "\nSelect an Attribute: "))); j% Z9 D- b  Q: W
(setq obj (vlax-ename->vla-object obj))$ `+ {1 D# q# Z& Q- W9 e. X
(cond
6 e/ c1 s# s( _% W((= (strcase att) "A")
1 O+ O( F* W6 i(setq ang (getstring t "\nNew Angle: "))
2 x6 p7 [0 h  Z(vlax-put-property obj 'rotation ang))
4 H! A6 \0 q" i+ c3 C; o: I$ |((= (strcase att) "C")4 {4 e. W# @% x' O5 R% L
(setq col (getstring "\nNew Color Number: "))8 R6 L" ]# o+ W% `3 K0 a$ j0 I
(vlax-put-property obj 'color col))
! A2 z* f/ G- d1 m0 ~((= (strcase att) "H")
! b7 U, I9 i/ r0 Q$ ?(setq ohei (vlax-get-property obj 'height))9 n* s  H7 j* A3 s% h
(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:")))# A" L" [) ?# s6 d( Q
(if (= hei "")(setq hei ohei))
" V, j" A- H7 u- z& s(vlax-put-property obj 'height hei))
& _0 `; l3 M, F7 b((= (strcase att) "L")* S# a* [) M! k, O
(setq lay (getstring "\nNew Layer:"))  ]- h$ \) w( ^; b# a" S4 M$ R
(if (not (tblsearch "LAYER" lay))/ l+ S2 N1 ]" ^* W( G& ^
(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))
0 j3 m4 e/ `  e+ W(vlax-put-property obj 'layer lay)3 \4 d  I# C) o' q0 b
))
5 s" l4 W0 A; z7 _/ _. e((= (strcase att) "P")4 i% T& f5 `0 \  T
(setq pos (getpoint "\nNew Position:"))
4 o! ?$ C2 @5 P& z. n(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))
, I  X# {" J) D0 ]((= (strcase att) "S")
' j4 b' @' [, d" P- C(setq sty (getstring "\nNew Style: "))5 M- b) h; {$ t; t
(if (not (tblsearch "STYLE" sty))  i8 R9 K9 _, ^2 A' }
(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))
3 U6 {* x& C2 u( i# Y9 s(vlax-put-property obj 'stylename sty)2 w0 @" O8 g+ P' a/ u) [
))
5 M/ k$ b) H. r! e((= (strcase att) "V")' j$ N  d3 I1 s) s* [' d, `
(setq val (getstring t "\nNew value: "))# C$ e9 Q/ O, Y4 B# m% }7 R6 B% D
(vlax-put-property obj 'textstring val))
2 l% }3 }9 A7 T+ U; r& x. r  X0 J);c1 m% m, t3 D% ], N
(princ)
; S6 _9 i- x, Q: y# Q);defun

; v! I& c* B, _2 Z  I4 jVBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性
/ Z7 b/ c' l" z7 Y' Get the attributes for the block reference
! i# K3 [& b, s    Dim varAttributes As Variant
5 ~9 G0 {1 U& j% @4 Z& U( y2 S& m+ L( F    varAttributes = blockRefObj.GetAttributes7 u, {, k% \0 f7 E1 q0 S. i
   
, ^- [7 T$ P7 d9 J& L4 I' G; |! _    ' Move the attribute tags and values into a string to be displayed in a Msgbox. `7 V! ^! i0 O- G4 R3 V
    Dim strAttributes As String4 r8 y- S* v. I
    Dim I As Integer& d$ W7 Z* h% v) O% `/ }; \
    For I = LBound(varAttributes) To UBound(varAttributes)
% ^8 P% b5 }! w9 U, U        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _' |" r, G. H1 z5 F
                        "   Value: " & varAttributes(I).textString & "    "( n. f' [; z. G+ O
    Next2 Z% s$ @% D# [" B9 H
    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"
7 e8 G/ T8 |! a. C) O+ S   
( l, y% U8 ~$ @( b    ' Change the value of the attribute
7 H, @9 \6 d; S% Q) o% @) j/ M    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects." F( t) H; w! z  L' A
    ' Changing them changes the objects in the drawing.$ K' E. `" i$ i" T) v
    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

 楼主| 发表于 2008-7-8 10:35:22 | 显示全部楼层 来自: 中国辽宁鞍山
如果用VBA来实现的话, 该怎样做???VBA与LISP相比,在处理这类问题上哪个更容易实现??再次感谢楼上的, g2 P1 P, w2 u" g: b; z

  }. E. p# Z: R" M0 m[ 本帖最后由 maoyangmy 于 2008-7-8 10:37 编辑 ]
 楼主| 发表于 2008-7-8 11:20:45 | 显示全部楼层 来自: 中国辽宁鞍山
5楼的能不能把VBA的解决方案也分享一下, 非常感谢
发表于 2008-7-14 22:24:59 | 显示全部楼层 来自: 中国天津
建议用VB弄,可以选择的项目比较多,控制性更好些。$ W# s- z5 `' h' {, l/ E$ |' Z3 Z
在CAD的帮助文件里有例子,可以参考,我当初就是利用那个例子实现的自动编号。
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

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