QQ登录

只需一步,快速开始

登录 | 注册 | 找回密码

三维网

 找回密码
 注册

QQ登录

只需一步,快速开始

展开

通知     

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

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

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

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

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

x
怎样修改属性块中的属性???
" c+ j0 R- W" a8 }因工作需要, 我想在程序中修改属性块的属性,新建、删除属性,修改属性的性质为“不可见”、“预设”等,如何实现???
发表于 2008-7-7 11:14:58 | 显示全部楼层 来自: 中国浙江金华
可以选择编辑块,然后进行修改,添加,或删除
发表于 2008-7-7 15:33:19 | 显示全部楼层 来自: 中国浙江宁波
那要看你用VBA或者是lisp编程工具了,工具不同方法也不相同;
 楼主| 发表于 2008-7-7 16:13:29 | 显示全部楼层 来自: 中国辽宁鞍山
我现在想采用LISP编程, 怎样解决?' p, K# j# H/ r- J; E$ \$ f, n3 D) _
VBA在面向对象方便比LSP处理的好, 如果sealive_leafage 对此也了解,请一并告诉解决方法,谢谢
发表于 2008-7-7 22:04:08 | 显示全部楼层 来自: 中国浙江宁波
lisp可以尝试调用acad命令:-attedit来编辑属性;
. v4 w1 G6 Q: h7 E2 @可以试试下面的代码:
. S+ O6 p. S/ Q: [( m5 L8 |(defun c:test ()
1 N8 h' n9 y/ {- f(vl-load-com)+ X# ?: ~5 G. E5 z5 L5 n) ]. U
(setq att (getstring "\nChange attribute [Angle/Color/Height/Layer/Position/Style/Value/Tagstring]: "))
. A2 g" W; w# [- z5 ]) C  }9 v" F(setq obj (car (nentsel "\nSelect an Attribute: ")))
: h; H4 d3 H- c1 T(setq obj (vlax-ename->vla-object obj))1 j* @# y1 U. D, O. m3 o! A  [
(cond2 z- y4 X, g1 R3 D1 Z
((= (strcase att) "A")7 w* K8 \7 L9 f! R5 |) t1 m
(setq ang (getstring t "\nNew Angle: "))3 K8 J, v  z( A: C! J8 C
(vlax-put-property obj 'rotation ang))8 L' Z# U5 M& \, U& E% G9 {
((= (strcase att) "C")5 c* w& d7 t$ m6 Q% b# x, U
(setq col (getstring "\nNew Color Number: "))
  v* ?) I( _- c1 A(vlax-put-property obj 'color col)); [: L0 k  t1 N; L7 w; w9 ~
((= (strcase att) "H")- \, \* h: f# w6 x" K0 I  R" E( e4 _
(setq ohei (vlax-get-property obj 'height))9 n& W+ g  ?! p. _5 W1 Y2 d4 x  ^
(setq hei (getdist (strcat "\nNew Height <" (rtos oh 2 2) ">:")))
4 R- @5 a3 }8 z+ B& y0 f(if (= hei "")(setq hei ohei))
" K1 e% z4 m" M) @% Z+ @(vlax-put-property obj 'height hei))- j* \  ?9 I; G4 y2 X8 {
((= (strcase att) "L")
" w- F3 a5 g" c: f% {(setq lay (getstring "\nNew Layer:"))( a& g0 q; ]! D# e, n) M- J( s
(if (not (tblsearch "LAYER" lay))' N7 W3 {) m  p, p8 h
(alert (strcat "\nLayer " (strcase lay) " doesn't exist!"))4 g! K  u# A. {% }- b, `
(vlax-put-property obj 'layer lay)# o6 V# q2 F  t+ X( v$ ]; e  s
))
: Q/ V4 O' h% v, \((= (strcase att) "P")$ Z4 d4 \5 U2 w6 h
(setq pos (getpoint "\nNew Position:"))- O. e( i% t/ ?3 w; V" y% R1 _
(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos)))
) E3 Q3 {1 A: ?: }9 ?$ q! B((= (strcase att) "S"); e  K2 r! A7 J2 k5 Q4 ]1 c
(setq sty (getstring "\nNew Style: "))$ B+ [) j2 G. Y) z
(if (not (tblsearch "STYLE" sty))
. F$ N, ^; Y: h' m(alert (strcat "\nThe style " (strcase sty) " doesn't exist!"))) ?% y( |: B9 h3 s+ e
(vlax-put-property obj 'stylename sty)
& C; U4 u4 x/ x) d, F7 Y))5 {; \* ]* g) n$ ?' F+ M% W
((= (strcase att) "V")
4 ^* {5 u# d+ A& g, ^, t(setq val (getstring t "\nNew value: "))+ K# R6 R2 p; c1 U5 z/ H" m. @9 b2 }
(vlax-put-property obj 'textstring val))& e4 N/ G( A" ]4 N$ F3 r# X7 X
);c
7 C$ e/ z" e( [9 m3 ?(princ)
" e& f# k" F) P7 X! b6 g& });defun
5 I  `# @0 p1 y: o7 ~; h# V
VBA完成属性编辑相对来说操作更方便,VBA可以按下面的代码获得和编辑属性. q3 j) u* W- {' j% e
' Get the attributes for the block reference! Y: t/ ~; M' R  o$ f9 W0 A" |
    Dim varAttributes As Variant6 q6 c! W3 }" A% h3 D8 Y; n
    varAttributes = blockRefObj.GetAttributes7 u8 N9 ]& z1 U+ C) E
   
; f% v0 b* T- L6 c" s' r# P' ]    ' Move the attribute tags and values into a string to be displayed in a Msgbox  v/ q# L, o: C* M( x" G  f
    Dim strAttributes As String
$ _8 x, ~5 w4 T9 v    Dim I As Integer
9 M' P( |0 w) K1 Q  i    For I = LBound(varAttributes) To UBound(varAttributes)2 C0 t0 i; _+ p0 g1 w, |% `; }
        strAttributes = strAttributes & "  Tag: " & varAttributes(I).TagString & _2 a/ G. {& Z! W* K% G8 _( n
                        "   Value: " & varAttributes(I).textString & "    "
9 y! t" i( b/ ^# p% \    Next4 u) u3 t. T& P( s+ ?
    MsgBox "The attributes for blockReference " & blockRefObj.name & " are: " & strAttributes, , "GetAttributes Example"5 y8 y) l1 m8 M; ?
   
9 p6 _" d6 `/ d! T' x& J  D6 U    ' Change the value of the attribute
4 I6 M6 n+ B3 k0 \    ' Note: There is no SetAttributes. Once you have the variant array, you have the objects.7 a0 c9 X% z8 {9 ^9 x2 m  C! \
    ' Changing them changes the objects in the drawing.
5 X# P; W; Q1 j9 e, z- v    varAttributes(0).textString = "NEW VALUE!"

评分

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

查看全部评分

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

本版积分规则


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

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

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