明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4389|回复: 2

通过颜色、线型等改物体图层

[复制链接]
发表于 2003-11-26 17:53:00 | 显示全部楼层 |阅读模式
没有对话框,里面的设置是根据自己的绘图习惯定的。


源码如下:里面一些函数都是明经里面下载的。
  1. Sub changelayer()
  2.   On Error Resume Next
  3.    '新建选择集
  4.     Dim ssetObj As AcadSelectionSet
  5.     Set ssetObj = CreateSelectionSet()
  6.     ssetObj.SelectOnScreen
  7.     If ssetObj.Count = 0 Then Exit Sub
  8.   
  9.    '新建图层
  10.     Dim newlayer As AcadLayer
  11.     Set newlayer = CreateLayer("A1", acRed)
  12.       newlayer.Lineweight = acLnWt050
  13.     Set newlayer = CreateLayer("A2", acYellow)
  14.       newlayer.Lineweight = acLnWt025
  15.     Set newlayer = CreateLayer("A3", acGreen)
  16.       newlayer.Lineweight = acLnWt025
  17.     Set newlayer = CreateLayer("A4", acCyan)
  18.       newlayer.Lineweight = acLnWt035
  19.     Set newlayer = CreateLayer("A5", acBlue)
  20.       newlayer.Lineweight = acLnWt070
  21.     Set newlayer = CreateLayer("A6", acMagenta)
  22.       newlayer.Lineweight = acLnWt013
  23.     Set newlayer = CreateLayer("C6", acMagenta, "CENTER")
  24.       newlayer.Lineweight = acLnWt013
  25.     Set newlayer = CreateLayer("HATCH")
  26.       newlayer.Lineweight = acLnWt018
  27.     Set newlayer = CreateLayer("NOTE")
  28.       newlayer.Lineweight = acLnWt018
  29.     Set newlayer = CreateLayer("DIM")
  30.       newlayer.Lineweight = acLnWt018
  31.     Set newlayer = CreateLayer("钢筋编号")
  32.       newlayer.Lineweight = acLnWt018
  33.     Set newlayer = CreateLayer("标高")
  34.       newlayer.Lineweight = acLnWt018
  35.    
  36.    
  37.     Dim ent As AcadEntity
  38.     For Each ent In ssetObj
  39.       '根据颜色改变改图层
  40.       colorTolayer ent, acRed, "A1"
  41.       colorTolayer ent, acYellow, "A2"
  42.       colorTolayer ent, acGreen, "A3"
  43.       colorTolayer ent, acCyan, "A4"
  44.       colorTolayer ent, acBlue, "A5"
  45.       '所有标注变成DIM层
  46.       '所有文字变成NOTE层
  47.       '所有填充变成HATCH层
  48.       '所有钢筋编号改为钢筋编号层
  49.       If TypeOf ent Is AcadDimension Then
  50.         ent.Layer = "DIM"
  51.       ElseIf TypeOf ent Is AcadHatch Then
  52.         ent.Layer = "HATCH"
  53.       ElseIf TypeOf ent Is AcadMText Or TypeOf ent Is AcadText Then
  54.         ent.Layer = "NOTE"
  55.       ElseIf TypeOf ent Is AcadBlockReference Then
  56.         If ent.Name Like "钢筋编号*" Then
  57.           ent.Layer = "钢筋编号"
  58.         ElseIf ent.Name Like "BG??" Or ent.Name Like "*标高" Then
  59.           ent.Layer = "标高"
  60.         End If
  61.       End If
  62.     Next
  63.    
  64.     ssetObj.Clear
  65.     ssetObj.Delete
  66.     ThisDrawing.PurgeAll
  67. End Sub
  68. Sub colorTolayer(ent As AcadEntity, Color As Integer, layerName As String)
  69.   If ent.Color = Color Then
  70.     ent.Layer = layerName
  71.     ent.Color = acByLayer
  72.   End If
  73. End Sub
  74. Public Function CreateLayer(ssLayerName As String, Optional LayerColor As Integer, _
  75.                             Optional LayerLineType As String) As AcadLayer
  76. On Error Resume Next
  77.     Set CreateLayer = ThisDrawing.Layers(ssLayerName)
  78.     If Err Then
  79.         Err.Clear
  80.         Set CreateLayer = ThisDrawing.Layers.Add(ssLayerName)
  81.         If LayerColor <> 0 Then CreateLayer.Color = LayerColor
  82.         If LayerLineType <> "" Then CreateLayer.Linetype = LayerLineType
  83.     End If
  84. End Function

  85. Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet
  86.   '返回一个空白选择集
  87.   
  88.     Dim ss As AcadSelectionSet
  89.    
  90.     On Error Resume Next
  91.     Set ss = ThisDrawing.SelectionSets(ssName)
  92.     If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
  93.     ss.Clear
  94.     Set CreateSelectionSet = ss
  95. End Function


本帖子中包含更多资源

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

x
发表于 2008-6-25 16:15:00 | 显示全部楼层
好好学习,天天向上!
发表于 2013-6-27 20:26:24 | 显示全部楼层
谢谢楼主代码分享!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 13:35 , Processed in 0.168244 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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