明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4190|回复: 3

创建实体、图层和选择集

[复制链接]
发表于 2013-2-8 01:31:13 | 显示全部楼层 |阅读模式
Option Explicit
Public ms As AcadModelSpace, utiobj As Object
'提示输入点创建一个点
Private Sub Addpoint()
    Dim p1 As Variant, PointObj As AcadPoint
    Set ms = ThisDrawing.ModelSpace
    Set utiobj = ThisDrawing.Utility
    p1 = utiobj.GetPoint(, "指定点")
    Set PointObj = ms.Addpoint(p1)
End Sub
'提示输入点创建一条直线
Private Sub AddLine()
    Dim p1 As Variant, p2 As Variant, LineObj As AcadLine
    Set ms = ThisDrawing.ModelSpace
    Set utiobj = ThisDrawing.Utility
    p1 = utiobj.GetPoint(, "第一点")
    p2 = utiobj.GetPoint(p1, "第二点")
    Set LineObj = ms.AddLine(p1, p2)
End Sub
'提示输入点创建一个圆
Private Sub AddCircle()
    Dim p1 As Variant, p2 As Variant, dist As Double, CircleObj As AcadCircle
    Set ms = ThisDrawing.ModelSpace
    Set utiobj = ThisDrawing.Utility
    p1 = utiobj.GetPoint(, "第一点")
    dist = utiobj.GetDistance(p1, "输入半径")
    Set CircleObj = ms.AddCircle(p1, dist)
End Sub
'提示输入点创建一条仅2个顶点轻多段线
Private Sub AddLWPline()
    Dim p1 As Variant, p2 As Variant, points(3) As Double, objPline As AcadLWPolyline
    Set utiobj = ThisDrawing.Utility
    Set ms = ThisDrawing.ModelSpace

    On Error Resume Next
    p1 = utiobj.GetPoint(, "输入第一点:")
    If Err.Number = -2145320928 Then
        Err.Clear
        Exit Sub
    End If
    On Error Resume Next
    p2 = utiobj.GetPoint(p1, "输入下一点:")
    If Err.Number = -2145320928 Then
        Err.Clear
        Exit Sub
    End If
    points(0) = p1(0)
    points(1) = p1(1)
    points(2) = p2(0)
    points(3) = p2(1)
    Set objPline = ms.AddLightWeightPolyline(points)
End Sub
'提示输入点创建一条连续顶点轻多段线,by mjtd
Private Sub AddLWPline1()
    Dim index As Integer, p1 As Variant, ptPrevious As Variant, ptCurrent As Variant
    Dim points(0 To 3) As Double, ptVert(0 To 1) As Double
    Dim objPline As AcadLWPolyline
    Set utiobj = ThisDrawing.Utility
    Set ms = ThisDrawing.ModelSpace

    index = 2
    On Error Resume Next
    p1 = utiobj.GetPoint(, "输入第一点:")
    If Err.Number = -2145320928 Then
        Err.Clear
        Exit Sub
    End If
    ptPrevious = p1

nextpt:
    On Error Resume Next
    ptCurrent = utiobj.GetPoint(ptPrevious, "输入下一点:")
    If Err.Number = -2145320928 Then
        Err.Clear
        Exit Sub
    End If

    If index = 2 Then
        points(0) = ptPrevious(0)
        points(1) = ptPrevious(1)
        points(2) = ptCurrent(0)
        points(3) = ptCurrent(1)
        Set objPline = ms.AddLightWeightPolyline(points)
    ElseIf index > 2 Then
        ptVert(0) = ptCurrent(0)
        ptVert(1) = ptCurrent(1)
        objPline.AddVertex index - 1, ptVert
    End If
    index = index + 1
    ptPrevious = ptCurrent
    GoTo nextpt
End Sub
'提示点及各参数创建一个圆弧
Private Sub AddArc()
   Dim Center As Variant, Radius As Double, StartAngle As Double, endangle As Double, objArc As AcadArc
   Set utiobj = ThisDrawing.Utility
   Set ms = ThisDrawing.ModelSpace

   Center = utiobj.GetPoint(, "输入圆心:")
   Radius = utiobj.GetDistance(Center, "输入半径")
   StartAngle = utiobj.GetAngle(Center, "输入起始角")
   endangle = utiobj.GetAngle(Center, "输入终止角")
   Set objArc = ms.AddArc(Center, Radius, StartAngle, endangle)
End Sub
'提示点及各参数创建一个椭圆弧
Private Sub AddEllipse()
   Dim Center As Variant, p1 As Variant, Radius As Double, MajorAxis(2) As Double, RadiusRatio As Double, objEllipse As AcadEllipse
   Dim objLine As AcadLine, StartAngle As Double, endangle As Double
   Set utiobj = ThisDrawing.Utility
   Set ms = ThisDrawing.ModelSpace

   Center = utiobj.GetPoint(, "输入椭圆心:")
   Radius = utiobj.GetDistance(Center, "输入长轴半径")
   MajorAxis(0) = Radius: MajorAxis(1) = 0#: MajorAxis(2) = 0#
   On Error Resume Next
   RadiusRatio = utiobj.GetReal("输入椭圆长轴与短轴比率")
   If (RadiusRatio = 0) Then RadiusRatio = 0.75
   Set objEllipse = ms.AddEllipse(Center, MajorAxis, RadiusRatio)
   p1 = utiobj.GetPoint(Center, "输入椭圆起始角度")
   Set objLine = ms.AddLine(Center, p1)
   StartAngle = objLine.Angle
   objLine.Delete
   p1 = utiobj.GetPoint(Center, "输入椭圆终止角度")
   Set objLine = ms.AddLine(Center, p1)
   endangle = objLine.Angle
   objLine.Delete
   objEllipse.StartAngle = StartAngle
   objEllipse.endangle = endangle
   objEllipse.Update
End Sub
'创建一个新图层
Private Sub AddNewLayer()
   Dim layername As Variant, objLayer As AcadLayer, mylayer As AcadLayers
   Set utiobj = ThisDrawing.Utility
   Set mylayer = ThisDrawing.Layers

   layername = utiobj.GetString(False, "输入新图层名")
   Set objLayer = mylayer.Add(layername)
   ThisDrawing.SetVariable "clayer", layername
   objLayer.color = 1
End Sub
'创建一个新选择集,并选择对象修改颜色
Sub creatss()
    Dim ss As AcadSelectionSet, i%
    Dim FilterType(0) As Integer
    Dim FilterData(0) As Variant
    On Error Resume Next
    Set ss = ThisDrawing.SelectionSets.Add("ss1")
    If Err Then
        Err.Clear
        Set ss = ThisDrawing.SelectionSets("ss1")
        ss.Clear
    End If
    i = ss.Count
    If Err Then
        ss.Delete
        Err.Clear
        Set ss = ThisDrawing.SelectionSets.Add("ss1")
    End If
    Dim ent As AcadEntity
    FilterType(0) = 62
    FilterData(0) = 1
    ss.SelectOnScreen FilterType, FilterData
    For Each ent In ss
    ent.color = 19
    ent.Update
    Next ent
End Sub


发表于 2013-2-8 16:41:51 | 显示全部楼层
严兄,跑来这了啊。
发表于 2013-4-8 16:56:58 | 显示全部楼层
发表于 2018-8-21 19:53:48 | 显示全部楼层
提示: 该帖被管理员或版主屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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