明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2266|回复: 0

[例程]对象线色

[复制链接]
发表于 2002-5-28 21:15:00 | 显示全部楼层 |阅读模式
Public Sub UseColor()

    Dim newLayer As AcadLayer
    '获得0层
    Set newLayer = ThisDrawing.Layers("0")
    '将0层设为青色
    newLayer.Color = acCyan
'--------------------------------------------------
    Dim blkObj As AcadBlock
    Dim blkinsPnt(0 To 2) As Double
    blkinsPnt(0) = 0: blkinsPnt(1) = 0: blkinsPnt(2) = 0
    '创建一个名为bk1的图块
    Set blkObj = ThisDrawing.Blocks.Add(blkinsPnt, "bk1")
'--------------------------------------------------
    Dim cirObj As AcadCircle
    Dim cen(0 To 2) As Double
    Dim radius As Double
    '创建第1个圆
    cen(0) = 0: cen(1) = 0: cen(2) = 0
    radius = 80
    Set cirObj = blkObj.AddCircle(cen, radius)
    '该圆的颜色设为随层
    cirObj.Color = acByLayer
   
    '创建第2个圆
    cen(0) = 0: cen(1) = 0: cen(2) = 0
    radius = 60
    Set cirObj = blkObj.AddCircle(cen, radius)
    '第2个圆的颜色设为随块
    cirObj.Color = acByBlock
   
    '创建第3个圆,对颜色属性不设置
    cen(0) = 0: cen(1) = 0: cen(2) = 0
    radius = 40
    Set cirObj = blkObj.AddCircle(cen, radius)
   
    '创建第4个圆
    cen(0) = 0: cen(1) = 0: cen(2) = 0
    radius = 20
    Set cirObj = blkObj.AddCircle(cen, radius)
    '该圆的颜色设为红色
    cirObj.Color = acRed
'-------------------------------------------------
    '准备将4个圆组成的图块插入模型空间
    Dim blkRefObj As AcadBlockReference
    Dim insPnt(0 To 2) As Double
    insPnt(0) = 200: insPnt(1) = 150: insPnt(2) = 0
    '将3个圆组成的块插入模型空间
    Set blkRefObj = ThisDrawing.ModelSpace.InsertBlock _
                    (insPnt, "bk1", 1#, 1#, 1#, 0#)
'-------------------------------------------------
    Dim lineObj As AcadLine
    Dim sPnt(0 To 2) As Double, ePnt(0 To 2) As Double
    '在模型空间单独创建第1条直线段
    sPnt(0) = 200: sPnt(1) = 150: sPnt(2) = 0
    ePnt(0) = 300: ePnt(1) = 186: ePnt(2) = 0
    Set lineObj = ThisDrawing.ModelSpace.AddLine(sPnt, ePnt)
   
    '在模型空间单独创建第2条直线段
    sPnt(0) = 200: sPnt(1) = 150: sPnt(2) = 0
    ePnt(0) = 100: ePnt(1) = 186: ePnt(2) = 0
    Set lineObj = ThisDrawing.ModelSpace.AddLine(sPnt, ePnt)
    '将第2条直线段的颜色设为绿色
    lineObj.Color = acGreen
   
    ThisDrawing.Regen acActiveViewport
   
    MsgBox "准备将层换色!"
    newLayer.Color = acYellow

    ThisDrawing.Regen acActiveViewport

End Sub

Public Sub lx1()

    Dim blkObj As AcadBlock
    Dim blkinsPnt(0 To 2) As Double
    blkinsPnt(0) = 0: blkinsPnt(1) = 0: blkinsPnt(2) = 0
    '创建一个名为bk1的图块
    Set blkObj = ThisDrawing.Blocks.Add(blkinsPnt, "bk1")

    Dim cirObj As AcadCircle
    Dim cen(0 To 2) As Double
    Dim radius As Double
    '创建第1个圆
    cen(0) = 0: cen(1) = 0: cen(2) = 0
    radius = 80
    Set cirObj = blkObj.AddCircle(cen, radius)

    Dim blkRefObj As AcadBlockReference
    Dim insPnt(0 To 2) As Double
    insPnt(0) = 200: insPnt(1) = 150: insPnt(2) = 0
    '将3个圆组成的块插入模型空间
    Set blkRefObj = ThisDrawing.ModelSpace.InsertBlock(insPnt, "bk1", 1#, 1#, 1#, 0#)
    blkRefObj.Color = acYellow
   
    ThisDrawing.Regen acActiveViewport
'----------------------------------------
    Dim blkObj1 As AcadBlock
    '创建一个名为bk1的图块
    Set blkObj1 = ThisDrawing.Blocks.Add(blkinsPnt, "bk2")
   
    Dim lineObj As AcadLine
    Dim sPnt(0 To 2) As Double, ePnt(0 To 2) As Double
    '在模型空间单独创建第1条直线段
    sPnt(0) = 0: sPnt(1) = 0: sPnt(2) = 0
    ePnt(0) = 100: ePnt(1) = 36: ePnt(2) = 0
    Set lineObj = blkObj1.AddLine(sPnt, ePnt)
   
    '在模型空间单独创建第1条直线段
    sPnt(0) = 0: sPnt(1) = 0: sPnt(2) = 0
    ePnt(0) = -100: ePnt(1) = 36: ePnt(2) = 0
    Set lineObj = blkObj1.AddLine(sPnt, ePnt)
   
    Dim blkRefObj1 As AcadBlockReference
    '将3个圆组成的块插入模型空间
    Set blkRefObj1 = ThisDrawing.ModelSpace.InsertBlock(insPnt, "bk2", 1#, 1#, 1#, 0#)
    blkRefObj1.Color = acByBlock
   
    ThisDrawing.Regen acActiveViewport

End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-28 23:35 , Processed in 0.161792 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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