明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2074|回复: 2

求助:如何通过VBA代码访问DWG文件的图形属性

[复制链接]
发表于 2003-10-24 15:10:00 | 显示全部楼层 |阅读模式
发表于 2003-10-24 19:50:00 | 显示全部楼层
如果你是使用2004版,可以利用Thisdrawing.SummaryInfo来控制
如果你是使用以前版本,只能使用XRecord来控制了,麻烦一些
发表于 2003-10-24 20:59:00 | 显示全部楼层
给你一个参考程序,自己慢慢研究吧
  1. Sub CreateDWGPROPSXrecord()
  2.    
  3.    ' ************* DISLAIMER *************
  4.    ' This SAMPLE routine was written by
  5.    ' Autodesk Product Support
  6.    ' Use it "AT YOUR OWN RISK"
  7.    ' *************************************
  8.    
  9.    ' Define variables
  10.    Dim XRecordDataType As Variant
  11.    Dim XRecordData As Variant
  12.    Dim objDWGPROPS As AcadObject
  13.    
  14.    ' Setup error handling
  15.    On Error GoTo CreateDWGPROPSXrecord_Error
  16.    
  17.    ' Set the constant for the DWGPRPOPS XRecordData
  18.    Const XRECORD_NAME = "DWGPROPS"

  19.    ' Use AutoLISP to create the XRecord object
  20.    ThisDrawing.SendCommand ("(/ Xrec Xname) (setq Xrec '((0 . ""XRECORD"") (100 . ""AcDbXrecord"") (1 . ""DWGPROPS COOKIE"") (9 . """"))) (setq Xname (entmakex Xrec)) (dictadd (namedobjdict) ""DWGPROPS"" Xname)" & vbCr)
  21.    
  22.    ' Set the types for the DWGPROPS
  23.    ReDim XRecordDataType(0 To 22) As Integer
  24.    XRecordDataType(0) = CInt(1)
  25.    XRecordDataType(1) = CInt(2)
  26.    XRecordDataType(2) = CInt(3)
  27.    XRecordDataType(3) = CInt(4)
  28.    XRecordDataType(4) = CInt(6)
  29.    XRecordDataType(5) = CInt(7)
  30.    XRecordDataType(6) = CInt(8)
  31.    XRecordDataType(7) = CInt(9)
  32.    XRecordDataType(8) = CInt(300)
  33.    XRecordDataType(9) = CInt(301)
  34.    XRecordDataType(10) = CInt(302)
  35.    XRecordDataType(11) = CInt(303)
  36.    XRecordDataType(12) = CInt(304)
  37.    XRecordDataType(13) = CInt(305)
  38.    XRecordDataType(14) = CInt(306)
  39.    XRecordDataType(15) = CInt(307)
  40.    XRecordDataType(16) = CInt(308)
  41.    XRecordDataType(17) = CInt(309)
  42.    XRecordDataType(18) = CInt(40)
  43.    XRecordDataType(19) = CInt(41)
  44.    XRecordDataType(20) = CInt(42)
  45.    XRecordDataType(21) = CInt(1)
  46.    XRecordDataType(22) = CInt(90)
  47.    
  48.    ' Set the defaults for the DWGPROPS values
  49.    ReDim XRecordData(0 To 22)
  50.    XRecordData(0) = CStr("DWGPROPS COOKIE")
  51.    XRecordData(1) = CStr("")
  52.    XRecordData(2) = CStr("")
  53.    XRecordData(3) = CStr("")
  54.    XRecordData(4) = CStr("")
  55.    XRecordData(5) = CStr("")
  56.    XRecordData(6) = CStr("")
  57.    XRecordData(7) = CStr("")
  58.    XRecordData(8) = CStr("=")
  59.    XRecordData(9) = CStr("=")
  60.    XRecordData(10) = CStr("=")
  61.    XRecordData(11) = CStr("=")
  62.    XRecordData(12) = CStr("=")
  63.    XRecordData(13) = CStr("=")
  64.    XRecordData(14) = CStr("=")
  65.    XRecordData(15) = CStr("=")
  66.    XRecordData(16) = CStr("=")
  67.    XRecordData(17) = CStr("=")
  68.    XRecordData(18) = CDbl("0")
  69.    XRecordData(19) = CDbl(Now)
  70.    XRecordData(20) = CDbl(Now)
  71.    XRecordData(21) = CStr("")
  72.    XRecordData(22) = CLng("7")
  73.    
  74.    ' Get the DWGPROPS object
  75.    Set objDWGPROPS = ThisDrawing.Dictionaries(XRECORD_NAME)
  76.    
  77.    ' Put the data into the XRecord
  78.    objDWGPROPS.SetXRecordData XRecordDataType, XRecordData
  79.    
  80.    ' Exit if there have been no errors
  81.    Exit Sub
  82.    
  83. CreateDWGPROPSXrecord_Error:

  84.    ' If there was an error, display the error
  85.    MsgBox Err.Description, vbCritical, "There was an error"
  86.    
  87. End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-28 12:30 , Processed in 0.169485 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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