QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
怎样修改属性块中的属性???. _3 [7 ~' ?3 x$ M1 e9 U
因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?' D4 {( |! W, }- A. f! Q1 w
VBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;
% E0 }+ ^+ q+ T8 b4 R$ f$ w可以试试下面的代码:
3 O2 ]. A+ l- W- @4 Y9 g  \(defun c:test ()
% T2 O6 L. V: k& S(vl-load-com)( q" g1 V9 N, }+ E' @. A# i
(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))4 ]. V% a! x0 F  M( r- a9 P
(setq obj (car (nentsel "\nSelect an Attribute: ")))+ w2 J. O2 s. N4 S2 P* ?3 n7 G/ X$ }
(setq obj (vlax-ename->vla-object obj))
6 }& v- H1 k' j! ]2 @(cond
8 a9 M3 P5 X5 e((= (strcase att) "A")! H- R+ ], l  _7 A. R2 g6 ?3 z
(setq ang (getstring t "\nNew Angle: "))$ Z- i% m0 B0 K/ ~* O( d/ |! r
(vlax-put-property obj 'rotation ang))& _  i. s6 M  B
((= (strcase att) "C")
% n0 k% F# I6 ]/ W: d% M(setq col (getstring "\nNew Color Number: "))
! l  J9 Q. [9 X* W0 K+ z* B; j(vlax-put-property obj 'color col))9 s4 _) O5 Q% L4 R% {2 F
((= (strcase att) "H")6 b. ?4 K0 {9 y8 w7 J
(setq ohei (vlax-get-property obj 'height))
) S( Q  V* s. _4 f: e  q(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:")))2 Z7 v' @8 {3 }
(if (= hei "")(setq hei ohei))
0 V: s% j  ?: j- D7 e/ |3 L(vlax-put-property obj 'height hei))
) W2 m1 A$ ?9 Y# P) N% m((= (strcase att) "L")& T5 M  ?; Y5 ?* \( V7 u4 M
(setq lay (getstring "\nNew Layer:"))9 O' m$ N7 ^+ A9 S! e9 e
(if (not (tblsearch "LAYER" lay))
; e7 l% |1 F4 Y( o% B: q4 e/ o(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))
3 _9 B) z  c$ \; H(vlax-put-property obj 'layer lay)5 O' H/ h7 f* y6 h( S8 }% @) k
))
$ B! `8 D" h! R  n((= (strcase att) "P")
" G: f2 g: Q; `' _( O( d8 l; b(setq pos (getpoint "\nNew Position:"))
1 b9 w: i$ Z" o4 ~1 f(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))
' b' l1 w) f! |$ U((= (strcase att) "S")
6 V' P" R5 b/ H( H) P# f(setq sty (getstring "\nNew Style: "))
2 }6 q0 f, t5 d2 L(if (not (tblsearch "STYLE" sty))
  m& h6 V+ ?% u9 ]0 I(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))+ _/ r6 I3 Q; x
(vlax-put-property obj 'stylename sty)
  }$ T$ n2 {8 [7 X$ K))
: ~9 b7 p) P5 u- B! ]: A6 B((= (strcase att) "V")
6 I% X3 X! V% z# i1 c; }(setq val (getstring t "\nNew value: "))
$ P$ Z- z6 P% b' n- y2 T(vlax-put-property obj 'textstring val))5 I7 l* F/ ]% a- N. ]
);c
0 g( e+ k4 ]: E, Q% ~1 {(princ)
8 O6 i1 [# D# [; H, C6 \);defun

# m0 a$ l. W- e6 vVBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性/ x' L1 _- K2 w4 q. ?; ~% J- G1 D
' Get the attributes for the block reference
8 @* M* {+ \: A/ O    Dim varAttributes As Variant
4 H$ c( x3 z2 T4 q) f    varAttributes = blockRefObj.GetAttributes
# a4 |  p& w$ l! Q$ B0 p% {    + u% O8 c4 V3 m. x
    ' Move the attribute tags and values into a string to be displayed in a Msgbox
, K( F& b4 h! w+ q+ ^! s    Dim strAttributes As String
, Q% a" e: M( a& @" a0 Z& g3 L: U    Dim I As Integer* P& c, q, ?0 d: I
    For I = LBound(varAttributes) To UBound(varAttributes)
+ \$ a) l7 g% Z0 X9 C( d7 ^+ k- y        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _) i3 W2 `6 [4 T, d
                        "   Value: " & varAttributes(I).textString & "    "
$ o0 w3 u1 _3 @: D4 q  W    Next2 @  h6 U. m- G2 g
    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"2 ~! \3 M0 R% d( |* s, c' Q9 V
   
0 V( M' G9 D  f' C# p    ' Change the value of the attribute1 s. b7 n+ s: d6 Z$ R
    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.
6 d* l8 m# D( [9 u, @    ' Changing them changes the objects in the drawing.
+ ~, B: m0 p2 u! Q0 c    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

 楼主| 发表于 2008-7-8 10:35:22 | 显示全部楼层 来自: 中国辽宁鞍山
如果用VBA来实现的话, 该怎样做???VBA与LISP相比,在处理这类问题上哪个更容易实现??再次感谢楼上的
. ?! b& ]: B0 K5 y& s8 G* a1 w; j% v2 m$ v2 {  Q3 x: a
[ 本帖最后由 maoyangmy 于 2008-7-8 10:37 编辑 ]
 楼主| 发表于 2008-7-8 11:20:45 | 显示全部楼层 来自: 中国辽宁鞍山
5楼的能不能把VBA的解决方案也分享一下, 非常感谢
发表于 2008-7-14 22:24:59 | 显示全部楼层 来自: 中国天津
建议用VB弄,可以选择的项目比较多,控制性更好些。
% h. U# o8 a5 p5 F* M: u/ I. `4 R5 V在CAD的帮助文件里有例子,可以参考,我当初就是利用那个例子实现的自动编号。
发表回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

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