QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
怎样修改属性块中的属性???- ^& w' T* ^0 }/ S% U. Q, j
因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?
- J# A5 w5 C9 D- qVBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;
, P% A$ \/ a: t1 Q1 b  @可以试试下面的代码:
/ ^# B( `3 r" }+ t2 l  `(defun c:test ()
% s$ B& a+ u( y(vl-load-com)8 F& [' A( _) z: l& z
(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))1 w; X/ C# i" z8 |
(setq obj (car (nentsel "\nSelect an Attribute: ")))
7 i5 e; c& }7 S. S(setq obj (vlax-ename->vla-object obj)). F$ R: O; d* D" t& O+ Y" O, }
(cond; V# T2 L0 [- J1 X4 |& V1 z
((= (strcase att) "A")3 S) B: W4 l! J* D" A5 g1 C! W2 O
(setq ang (getstring t "\nNew Angle: ")). z7 I5 G  w/ @- F
(vlax-put-property obj 'rotation ang))
% J$ c, {( {* ?, B$ p+ S((= (strcase att) "C")
3 P2 g  P+ J  {; t  [(setq col (getstring "\nNew Color Number: "))
. e+ O* Y; m: _# {  M) g3 X(vlax-put-property obj 'color col))
& ?  s, G1 T7 ?$ P1 Z5 D. C7 A+ R((= (strcase att) "H")
' Z) S' B' i* R# z# G$ P* z(setq ohei (vlax-get-property obj 'height))
4 m* i- m& s) {. H(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:")))% w2 ^* J$ S8 q* _
(if (= hei "")(setq hei ohei))
# H3 X1 b2 z0 ~$ T5 J; G9 f(vlax-put-property obj 'height hei))% _3 z3 W+ K: `9 r5 n/ P* u7 z9 t
((= (strcase att) "L")5 I+ s8 V# Q/ x* r1 s7 A) C
(setq lay (getstring "\nNew Layer:"))
8 \4 L5 {- s5 T# \0 S2 f3 {(if (not (tblsearch "LAYER" lay))
+ E6 k; }/ W( [* M(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))# [( h7 x6 O; d- \  Q
(vlax-put-property obj 'layer lay)" ]$ t8 p* y* u8 J8 R
))* C( v# }; m5 A% n  D
((= (strcase att) "P")0 I+ A' A' \! }" I
(setq pos (getpoint "\nNew Position:"))( K' \/ I- U3 b: r
(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))
7 }" v; @$ k+ f- X/ F! W((= (strcase att) "S")
# `* z" o' u! d6 _0 \; g7 g3 i, G. Y. e(setq sty (getstring "\nNew Style: "))
1 p- d7 H7 q8 b5 `(if (not (tblsearch "STYLE" sty))
+ g7 T& S4 p& I" f# B(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))& ~& S/ M8 k( w- g1 y7 S, ^  w' J: N
(vlax-put-property obj 'stylename sty). n& d6 |; I3 ^
))
- E/ b2 D3 t) Y8 }/ `- G((= (strcase att) "V")
8 Z0 h8 S1 i' ?: a; ^. |(setq val (getstring t "\nNew value: "))3 n3 x5 \6 @* w, R# h$ U) X) ]
(vlax-put-property obj 'textstring val))
2 v. Y' e7 a" T- f6 B5 V);c
0 ?0 N1 b* O) ?$ D6 h(princ) ' }# q' c7 b6 t, ]
);defun

* }  O, Q* v. ~7 XVBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性2 D8 y( Q0 U. F3 A
' Get the attributes for the block reference  Z& G2 w+ [9 y7 \% E5 v
    Dim varAttributes As Variant
! R4 A: ^7 p: v! g    varAttributes = blockRefObj.GetAttributes
5 o) e. _1 E! X    ' \; o+ }- X% t* _% g
    ' Move the attribute tags and values into a string to be displayed in a Msgbox; A, [5 v% Z/ J8 z1 q& j
    Dim strAttributes As String' O" j. s" J6 }
    Dim I As Integer( y. U. K) ~/ I) l+ D5 a
    For I = LBound(varAttributes) To UBound(varAttributes)
* c( G5 }- O/ X: F* P        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _
2 z! T* v- B9 j% D1 U. M' P                        "   Value: " & varAttributes(I).textString & "    "5 K- b+ J, j2 ]; o
    Next
( v& E: E4 q/ ~1 w0 |( [    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"3 r6 [( F  f9 v, T9 ?
   
4 i* C5 \' C% z5 z+ \    ' Change the value of the attribute
: a# x2 C$ Y. B: @* f    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.
# ~% E4 S- }, f- h8 l. {+ _    ' Changing them changes the objects in the drawing.$ n0 c" F, D0 G- w0 x) m; _* {
    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

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

本版积分规则


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

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

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