明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1925|回复: 2

VBA创建菜单问题。请高手指导一下

[复制链接]
发表于 2005-6-10 12:25:00 | 显示全部楼层 |阅读模式
Option Explicit Sub AddASubMenu()
Dim currMenuGroup As AcadMenuGroup
Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)

Dim newMenu As AcadPopupMenu
Set newMenu = currMenuGroup.Menus.Add("自动绘图" & Chr(Asc("&")))


Dim macro As String
macro = Chr(vbKeyEscape) + Chr(vbKeyEscape) Dim menuItemDraw As AcadPopupMenu
Set menuItemDraw = newMenu.AddSubMenu(newMenu.Count + 1, Chr(Asc("画图")))
Dim subMenuItemPoint As AcadPopupMenuItem
Set subMenuItemPoint = menuItemDraw.AddMenuItem(menuItemDraw.Count + 1, Chr(Asc("&")) & "点", macro & "_point ")
Dim subMenuItemLine As AcadPopupMenuItem
Set subMenuItemLine = menuItemDraw.AddMenuItem(menuItemDraw.Count + 1, Chr(Asc("&")) & "直线", macro & "_line ")
Dim subMenuItemPolyline As AcadPopupMenuItem
Set subMenuItemPolyline = menuItemDraw.AddMenuItem(menuItemDraw.Count + 1, Chr(Asc("&")) & "多段线", macro & "_polyline ")
Dim subMenuItemEllipseRec As AcadPopupMenuItem
Set subMenuItemEllipseRec = menuItemDraw.AddMenuItem(menuItemDraw.Count + 1, Chr(Asc("&")) & "椭圆", macro & "_ellipserec ")
Dim subMenuItemSpline As AcadPopupMenuItem
Set subMenuItemSpline = menuItemDraw.AddMenuItem(menuItemDraw.Count + 1, Chr(Asc("&")) & "样条曲线", macro & "_spline ")
Dim subMenuItemArc As AcadPopupMenuItem
Set subMenuItemArc = menuItemDraw.AddMenuItem(menuItemDraw.Count + 1, Chr(Asc("&")) & "曲线", macro & "_arc ")
Dim subMenuItemCircle As AcadPopupMenuItem
Set subMenuItemCircle = menuItemDraw.AddMenuItem(menuItemDraw.Count + 0, Chr(Asc("&")) & "圆", macro & "_circle ")
Set subMenuItemCircle = menuItemDraw.AddMenuItem(menuItemDraw.Count + 1, _
Chr(Asc("&")), macro & "-vbarun" + Chr(32) + "ThisDrawing.DrawCircle" + Chr(32))
newMenu.InsertInMenuBar (ThisDrawing.Application.MenuBar.Count + 1)
End Sub End Sub
Sub drawpoint()
Dim location(0 To 2) As Double
location(0) = 200: location(1) = 200: location(2) = 0
ThisDrawing.ModelSpace.AddPoint location
End Sub Sub DrawLine()
Dim pt1(2) As Double
Dim pt2(2) As Double
pt1(0) = 100: pt1(1) = 50: pt1(2) = 0
pt2(0) = 300: pt2(1) = 100: pt2(2) = 0
ThisDrawing.ModelSpace.AddLine pt1, pt2 Sub drawCircle()
Dim ptcen(0 To 2) As Double
ptcen(0) = 200
ptcen(1) = 200
ptcen(2) = 0
ThisDrawing.ModelSpace.AddCircle ptcen, 60
ZoomExtents End Sub Sub DrawPolyline()
Dim pt1(2) As Double
Dim pt2(2) As Double
Dim pt3(2) As Double pt1(0) = 100: pt1(1) = 100: pt1(2) = 0
pt2(0) = 300: pt2(1) = 150: pt2(2) = 0
pt3(0) = 400: pt3(1) = 200: pt3(2) = 0

ThisDrawing.ModelSpace.AddPolyline pt1, pt2, pt3
End Sub
想做成在下拉菜单中点击一个基本图对象自动绘出一个相应的图。多段线,样条曲线,椭圆,圆弧代码写不出来了 恳请高手指点一下。 多段线部分也调试不出
 楼主| 发表于 2005-6-10 12:30:00 | 显示全部楼层
还有请问如何将指令对应起来? 我现在的这个程序点击圆无法输出圆形,而最下面出现空白一块点击后绘出圆
发表于 2005-6-10 17:24:00 | 显示全部楼层
Dim curMenuGroup As AcadMenuGroup
Set curMenuGroup = Application.MenuGroups.Item(0)
Dim newMenu As AcadPopupMenu
'******************************************************************************
Set newMenu = curMenuGroup.Menus.Add("标注2(&U)")
'声明菜单项
Dim userMenuItem As AcadPopupMenuItem
'定义宏变量
Dim strMacro As String
'高程 菜单
strMacro = "-vbarun SpiritVale.dvb!modSpiritVale.Biaogao "
Set userMenuItem = newMenu.AddMenuItem(newMenu.Count, "高程(&G)", strMacro)
userMenuItem.HelpString = "指定比例尺及高程点标出高程" curMenuGroup.Menus.InsertMenuInMenuBar "标注2(&U)", ""
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-27 14:37 , Processed in 0.180941 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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