明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1624|回复: 8

老师们,我怎么把我在cad上的vba 转成 vb6.0 代码然后生成exe 可以吗?

[复制链接]
发表于 2015-7-22 17:10:07 | 显示全部楼层 |阅读模式
Sub GetObjInSet()
  On Error Resume Next
  Dim ssetObj As AcadSelectionSet
   Dim FilterType(0) As Integer
   Dim FilterData(0) As Variant
   Dim dm As AcadRegion
   Dim drm As Variant
   Dim b As Long
   FilterType(0) = 0
   FilterData(0) = "LWPOLYLINE"
   Dim entities As Variant
   Dim mianji As Double
   Dim entt As AcadText
'-------------------------------------------------------------------------------------
Set ssetObj = ThisDrawing.SelectionSets.Add("SSET" & Time)
ssetObj.SelectOnScreen FilterType, FilterData
'--------------------------------------------------------------------------------------------
  Dim ent(0) As AcadEntity
  Dim forma As Variant
For b = 0 To ssetObj.Count - 1
   Set ent(0) = ssetObj(b)

  mianji = Round(ent(0).Area * 0.0015, 2)
forma = Format(mianji, "0.00")
   entities = ThisDrawing.ModelSpace.AddRegion(ent)
    Set dm = entities(0)
     drm = dm.Centroid
     dm.Delete
'---------------------------------------------------------------------------------------------------
     Dim porinta() As Double
     ReDim porinta(UBound(drm) + 1) As Double
   Dim i As Integer
   For i = 0 To (UBound(drm) / 2)
   porinta(3 * i) = drm(2 * i)
   porinta(3 * i + 1) = drm(2 * i + 1)
   porinta(3 * 1 + 2) = 0
   Next

entt = ThisDrawing.ModelSpace.AddText(forma & "亩", porinta, 1)
Next
End Sub

老师这是vba 代码 ,最好讲的详细一点, 对vb6.0不是太熟悉,比如 新建exe 工程 把代码复制进去,  工程引用CAD2006,然后怎么做呢?  求解





 楼主| 发表于 2015-7-22 17:32:25 | 显示全部楼层
求大神解决 帮忙 解决???  
发表于 2015-7-23 17:43:14 | 显示全部楼层
百度vb控制CAD。多几行代码
 楼主| 发表于 2015-7-23 17:51:51 | 显示全部楼层
下午有遇到了问题了, 我为什么在cass  写属性, 多段线批量转成权属线
     Dim datatype(0 To 4) As Integer
    Dim data(0 To 4) As Variant
datatype(0) = 1001: data(0) = "SOUTH"
datatype(1) = 1000: data(1) = "300000"
datatype(2) = 1000: data(2) = dn(1)
datatype(3) = 1000: data(3) = dn(0)
datatype(4) = 1000: data(4) = "072"
objSelect.SetXData datatype, data
为什么和 cass  里直接绘制的权属线, 或 复合线转成权属线 的性质, 还不一样呢?
发表于 2015-7-23 21:56:18 | 显示全部楼层
 楼主| 发表于 2015-7-24 10:50:53 | 显示全部楼层
高手来 哈, cass , 我为什么 我把 多段线 写入的属性 “SOUTH” 写进去, 变成权属线了, 但是这个权属线还是跟cass 直接画的线  不一样
发表于 2015-8-5 09:19:59 | 显示全部楼层
写入“SOUTH"是因为CASS会识别是不是用CASS生成的图元,权属不一样的原因是这个线原来就有属性了,再添加的话顺序不一样,另一个原因就是编码与CASS不一样。最好的办法就是直接生成多段线,然后按CASS写入的属性一致的方法写入属性就行了,CASS的属性可以读取CASS标准图元的属性方法:.getadata datatype, data,然后分别显示datatype,data变体中每一个值。有什么问题可以联系我:qq38968681
 楼主| 发表于 2015-8-5 23:09:59 | 显示全部楼层
那老师,怎么正确的把多段线 写入宗地属性的值呢??? 我用了好多方法都不是太对???
 楼主| 发表于 2015-8-5 23:14:35 | 显示全部楼层
  1. Sub dd1223()
  2. On Error Resume Next

  3.    Dim datatype(0 To 1) As Integer
  4.    Dim data(0 To 1) As Variant
  5.    Dim xtypeOut As Variant, XDateOut As Variant
  6.    Dim objCurrent As AcadEntity
  7.    Dim basePnt As Variant
  8.    Dim ss As AcadSelectionSet
  9.    Dim minExt As Variant
  10.    Dim maxExt As Variant
  11.   '--------------------------------------------------------------------------------------------
  12.     If Not IsNull(ThisDrawing.SelectionSets.Item("11")) Then
  13.     Set ss = ThisDrawing.SelectionSets.Item("11")
  14.     ss.Delete
  15.     End If
  16.   '---------------------------------------------------------------------------------------------
  17.   Dim filtertype(0) As Integer
  18.   Dim filterdata(0) As Variant
  19.   filtertype(0) = 0
  20.   filterdata(0) = "LWPOLYLINE"
  21.    Set ss = ThisDrawing.Application.ActiveDocument.SelectionSets.Add("11")
  22.    ss.SelectOnScreen filtertype, filterdata
  23. '-----------------------------------------------------------------------------------------------
  24.   Dim datatypee(0 To 4) As Integer
  25.   Dim dataa(0 To 4) As Variant
  26. '------------------------------------------------------------------
  27. For Each objCurrent In ss

  28.    datatypee(0) = 1001: dataa(0) = "SOUTH"
  29.    datatypee(1) = 1000: dataa(1) = "300000"
  30.    datatypee(2) = 1000: dataa(2) = ""
  31.    datatypee(3) = 1000: dataa(3) = ""
  32.    datatypee(4) = 1000: dataa(4) = "072"
  33.   
  34.     objCurrent.SetXData datatypee, dataa
  35.     objCurrent.GetXData "", xtypeOut, XDateOut
  36.    
  37.     datatype(0) = 1001: data(0) = "QHDM"
  38.     datatype(1) = 1000: data(1) = ""
  39.    
  40.     objCurrent.SetXData datatype, data
  41.     objCurrent.GetXData "", xtypeOut, XDateOut
  42.    
  43.     datatype(0) = 1001: data(0) = "SJZGBM"
  44.     datatype(1) = 1000: data(1) = ""
  45.    
  46.     objCurrent.SetXData datatype, data
  47.     objCurrent.GetXData "", xtypeOut, XDateOut
  48.    
  49.     datatype(0) = 1001: data(0) = "FRDBXM"
  50.     datatype(1) = 1000: data(1) = ""
  51.    
  52.     objCurrent.SetXData datatype, data
  53.     objCurrent.GetXData "", xtypeOut, XDateOut
  54.    
  55.     datatype(0) = 1001: data(0) = "FRDBZMS"
  56.     datatype(1) = 1000: data(1) = ""
  57.     objCurrent.SetXData datatype, data
  58.     objCurrent.GetXData "", xtypeOut, XDateOut
  59.    
  60.     datatype(0) = 1001: data(0) = "FRDBDH"      '
  61.     datatype(1) = 1000: data(1) = ""
  62.     objCurrent.SetXData datatype, data
  63.     objCurrent.GetXData "", xtypeOut, XDateOut
  64.    
  65.     datatype(0) = 1001: data(0) = "DLRXM"      '
  66.     datatype(1) = 1000: data(1) = ""
  67.     objCurrent.SetXData datatype, data
  68.     objCurrent.GetXData "", xtypeOut, XDateOut
  69.    
  70.     datatype(0) = 1001: data(0) = "DLRSFZ"
  71.     datatype(1) = 1000: data(1) = ""
  72.     objCurrent.SetXData datatype, data
  73.     objCurrent.GetXData "", xtypeOut, XDateOut
  74.    
  75.     datatype(0) = 1001: data(0) = "DLRDH"
  76.     datatype(1) = 1000: data(1) = ""
  77.     objCurrent.SetXData datatype, data
  78.     objCurrent.GetXData "", xtypeOut, XDateOut
  79.    
  80.     datatype(0) = 1001: data(0) = "TXDZ"
  81.     datatype(1) = 1000: data(1) = ""
  82.     objCurrent.SetXData datatype, data
  83.     objCurrent.GetXData "", xtypeOut, XDateOut
  84.    
  85.     datatype(0) = 1001: data(0) = "TDZL"
  86.     datatype(1) = 1000: data(1) = ""
  87.     objCurrent.SetXData datatype, data
  88.     objCurrent.GetXData "", xtypeOut, XDateOut
  89.    
  90.     datatype(0) = 1001: data(0) = "DONGZHI"
  91.     datatype(1) = 1000: data(1) = ""
  92.     objCurrent.SetXData datatype, data
  93.     objCurrent.GetXData "", xtypeOut, XDateOut

  94.     datatype(0) = 1001: data(0) = "NANZHI"
  95.     datatype(1) = 1000: data(1) = ""
  96.     objCurrent.SetXData datatype, data
  97.     objCurrent.GetXData "", xtypeOut, XDateOut

  98.     datatype(0) = 1001: data(0) = "XIZHI"
  99.     datatype(1) = 1000: data(1) = ""
  100.     objCurrent.SetXData datatype, data
  101.     objCurrent.GetXData "", xtypeOut, XDateOut

  102.     datatype(0) = 1001: data(0) = "BEIZHI"
  103.     datatype(1) = 1000: data(1) = ""
  104.     objCurrent.SetXData datatype, data
  105.     objCurrent.GetXData "", xtypeOut, XDateOut

  106.     datatype(0) = 1001: data(0) = "QSLYZM"
  107.     datatype(1) = 1000: data(1) = ""
  108.     objCurrent.SetXData datatype, data
  109.     objCurrent.GetXData "", xtypeOut, XDateOut
  110.    
  111.     datatype(0) = 1001: data(0) = "PZTDYT"
  112.     datatype(1) = 1000: data(1) = ""
  113.     objCurrent.SetXData datatype, data
  114.     objCurrent.GetXData "", xtypeOut, XDateOut
  115.    
  116.     datatype(0) = 1001: data(0) = "TDSYZ"
  117.     datatype(1) = 1000: data(1) = ""
  118.     objCurrent.SetXData datatype, data
  119.     objCurrent.GetXData "", xtypeOut, XDateOut
  120.    
  121.     datatype(0) = 1001: data(0) = "SBJZWQS"
  122.     datatype(1) = 1000: data(1) = ""
  123.     objCurrent.SetXData datatype, data
  124.     objCurrent.GetXData "", xtypeOut, XDateOut
  125.    
  126.     datatype(0) = 1001: data(0) = "YBDJH"
  127.     datatype(1) = 1000: data(1) = ""
  128.         objCurrent.SetXData datatype, data
  129.     objCurrent.GetXData "", xtypeOut, XDateOut
  130.    
  131.     datatype(0) = 1001: data(0) = "TDZH"
  132.     datatype(1) = 1000: data(1) = ""
  133.         objCurrent.SetXData datatype, data
  134.     objCurrent.GetXData "", xtypeOut, XDateOut
  135.    
  136.     datatype(0) = 1001: data(0) = "SHRQ"
  137.     datatype(1) = 1000: data(1) = ""
  138.         objCurrent.SetXData datatype, data
  139.     objCurrent.GetXData "", xtypeOut, XDateOut
  140.    
  141.     datatype(0) = 1001: data(0) = "DJRQ"
  142.     datatype(1) = 1000: data(1) = ""
  143.         objCurrent.SetXData datatype, data
  144.     objCurrent.GetXData "", xtypeOut, XDateOut
  145.    
  146.     datatype(0) = 1001: data(0) = "ZZRQ"
  147.     datatype(1) = 1000: data(1) = ""
  148.         objCurrent.SetXData datatype, data
  149.     objCurrent.GetXData "", xtypeOut, XDateOut
  150.    
  151.     datatype(0) = 1001: data(0) = "DWXZ"
  152.     datatype(1) = 1000: data(1) = ""
  153.         objCurrent.SetXData datatype, data
  154.     objCurrent.GetXData "", xtypeOut, XDateOut
  155.    
  156.     datatype(0) = 1001: data(0) = "QSXZ"
  157.     datatype(1) = 1000: data(1) = ""
  158.         objCurrent.SetXData datatype, data
  159.     objCurrent.GetXData "", xtypeOut, XDateOut
  160.    
  161.     datatype(0) = 1001: data(0) = "SYQLX"
  162.     datatype(1) = 1000: data(1) = ""
  163.         objCurrent.SetXData datatype, data
  164.     objCurrent.GetXData "", xtypeOut, XDateOut
  165.    
  166.     datatype(0) = 1001: data(0) = "TDDJ"
  167.     datatype(1) = 1000: data(1) = ""
  168.         objCurrent.SetXData datatype, data
  169.     objCurrent.GetXData "", xtypeOut, XDateOut
  170.    
  171.     datatype(0) = 1001: data(0) = "MPH"
  172.     datatype(1) = 1000: data(1) = ""
  173.         objCurrent.SetXData datatype, data
  174.     objCurrent.GetXData "", xtypeOut, XDateOut
  175.    
  176.     datatype(0) = 1001: data(0) = "TUFU"
  177.     datatype(1) = 1000: data(1) = ""
  178.         objCurrent.SetXData datatype, data
  179.     objCurrent.GetXData "", xtypeOut, XDateOut
  180.    
  181.    
  182.     datatype(0) = 1001: data(0) = "JZMJ"
  183.     datatype(1) = 1000: data(1) = ""
  184.         objCurrent.SetXData datatype, data
  185.     objCurrent.GetXData "", xtypeOut, XDateOut
  186.    
  187.     datatype(0) = 1001: data(0) = "BDDJ"
  188.     datatype(1) = 1000: data(1) = ""
  189.         objCurrent.SetXData datatype, data
  190.     objCurrent.GetXData "", xtypeOut, XDateOut
  191.    
  192.     datatype(0) = 1001: data(0) = "SBDJ"
  193.     datatype(1) = 1000: data(1) = ""
  194.         objCurrent.SetXData datatype, data
  195.     objCurrent.GetXData "", xtypeOut, XDateOut
  196.     objCurrent.color = acCyan
  197.    
  198.     objCurrent.GetBoundingBox minExt, maxExt
  199.     Sleep 1
  200.     ZoomWindow minExt, maxExt
  201.     Sleep 1
  202.     Next objCurrent
  203.    ss.Delete
  204.   End Sub
老师这是我写入宗地属性的全部代码, 你帮我看看 ,对不对, 有点乱,如果有错的地方???请帮我指出来 先谢谢了 ,老师?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 10:44 , Processed in 0.185204 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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