版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、/*使用方法*/Alt+F8弹出' 点创建微程序目录点击选择指定路径(在这里选择D盘作为路径)点回到原始界面,点击按钮 ,弹出下面界面,这时候必须选中CATScript单击按钮回到macros原始界面点击弹出把以下程序断粘贴进去即可。进入二维图界面后,做两点(将来形成的网格线就在这两个点范围内)Alt+F8出现界面,点击后,分别选择两点后,网格将自动生成!Option Explicit*' Purpose: This macro allows you to create Grid line in CATIA drawing' Author: chenqa' La
2、nguages: VBScript' Locales: English ' Developing CATIA Level: V5R12' View mush parallel to system aixes,view angle 0deg,90deg and -90deg' *Sub CATMain()CATIA.RefreshDisplay = FalseDim sStatus As String ' Set the CATIA popup file alerts to False ' It prevents to stop the macro
3、 at each alert during its execution CATIA.DisplayFileAlerts = False ' Optional: allows to find the sample wherever it's installed ' Variables declaration Dim oDrwDocument As DrawingDocument Dim oDrwSheets As DrawingSheets Dim oDrwSheet As DrawingSheet Dim oDrwView As DrawingView Dim oFac
4、tory2D AS Factory2D ' The Distance between the lines Dim D As Integer Dim nx As Integer Dim ny As Integer ' The point coordinate select from Drawing Dim X1 As Integer Dim Y1 As Integer Dim X2 As Integer Dim Y2 As Integer Dim Pt1 As Point2D Dim Pt2 As Point2D 'The view scale dAngle for ro
5、tate view scale for view scale Dim dScale,dAngle As Double 'The view coordinate origin Dim X As Int Dim Y As Int Dim xSel As INFITF.Selection D= InputBox("Please Input the Distance Value", "input box", "100") D= Cint (D)' Retrive a new drawing document Set oDrwD
6、ocument = CATIA.ActiveDocument ' Retrieve the drawing document's sheets collection Set oDrwSheets = oDrwDocument.Sheets' Retrieve the active sheet Set oDrwSheet = oDrwSheets.ActiveSheet ' Retrieve the active view of the sheet Set oDrwView = oDrwSheet.Views.ActiveView 'Retrive the
7、 value of the view X= oDrwView.xAxisData Y= oDrwView.yAxisData dScale = oDrwView.Scale dAngle= oDrwView.Angle Set oFactory2D = oDrwView.Factory2D 'Get the coordinate from the select two point 'On Error Resume Next Set xSel = CATIA.ActiveDocument.Selection xSel.clear ReDim sFilter(0) sFilter(
8、0) = "Point2D" MsgBox "Please select the left-bottom point " sStatus = xSel.SelectElement(sFilter, "Select First Point.", false) If (sStatus = "Normal") Then Dim SelectedPoint1 As SelectedElement Set SelectedPoint1 = xSel.Item(1) Dim pt1Coord(2) As Int Selecte
9、dPoint1.GetCoordinates ( pt1Coord ) 'MsgBox "The frst point has been selected " Else MsgBox "Select a 2D Point 1" Exit Sub End If MsgBox "Please select the ritht-top point " sStatus = xSel.SelectElement(sFilter, "Select The Second Point.", false) If (sStat
10、us = "Normal") Then Dim SelectedPoint2 As SelectedElement Set SelectedPoint2 = xSel.Item(1) Dim pt2Coord(2) As Int SelectedPoint2.GetCoordinates ( pt2Coord ) 'MsgBox "The second point has been selected " Else MsgBox "Select a 2D Point 1" Exit Sub End If if dAngle=0
11、then X1= Cint( (pt1Coord(0) - X)/dScale) Y1= Cint (pt1Coord(1) - Y)/dScale) X2= Cint (pt2Coord(0) - X)/dScale) Y2= Cint (pt2Coord(1) - Y)/dScale) end if 'MsgBox (pt1Coord(0) 'MsgBox X if dAngle>0 then X1=Cint(pt1Coord(1)-Y)/dScale) Y1=Cint (pt1Coord(0) -X)/dScale) X2= Cint (pt2Coord(1)-Y)
12、/dScale) Y2= Cint (pt2Coord(0)-X)/dScale) end if if dAngle<0 then X1=Cint(pt1Coord(1)-Y)/dScale) Y1=Cint (pt1Coord(0) -X)/dScale) X2= Cint (pt2Coord(1)-Y)/dScale) Y2= Cint (pt2Coord(0)-X)/dScale) end if X1 = D * Cint(X1/D) Y1 = D * Cint (Y1/D) X2= D * Cint (X2/D) Y2 = D * Cint (Y2/D) nx = (X2-X1)
13、 D 'The number of the horizontal line ny = (Y2-Y1) D 'The number of the vertical line Dim Line2D1 As Line2D Dim Circle2D1 as Circle2D Dim MyText as DrawingText Dim iFontsize as Double Dim i As Int Dim j As Int Dim R As Doubel 'the radius of the circle iFontSize = 3.5 R=5 R=R / dScale'
14、;-Dim Di_H,Di_V as intDim Text_XYZ_H as stringDim Text_XYZ_V as stringDi_H=1Di_V=1'Compare the drawing view HV with 3D Aixes Dim XX1,YY1,ZZ1,XX2,YY2,ZZ2 as intoDrwView.GenerativeBehavior.GetProjectionPlane XX1,YY1,ZZ1,XX2,YY2,ZZ2if (XX1=1) then Text_XYZ_H="X"End ifif (XX1=-1) then Text
15、_XYZ_H="X"Di_H=-1End ifif (YY1=1) then Text_XYZ_H="Y"End ifif (YY1=-1) then Text_XYZ_H="Y"Di_H=-1End ifif (ZZ1=1) then Text_XYZ_H="Z"End ifif (ZZ1=-1) then Text_XYZ_H="Z"Di_H=-1End ifif (XX2=1) then Text_XYZ_V="X"End ifif (XX1=-1) then Text
16、_XYZ_V="X"Di_V=-1End ifif (YY2=1) then Text_XYZ_V="Y"End ifif (YY2=-1) then Text_XYZ_V="Y"Di_V=-1End ifif (ZZ2=1) then Text_XYZ_V="Z"End ifif (ZZ2=-1) then Text_XYZ_V="Z"Di_V=-1End ifif dAngle>0 thenDi_V=-Di_Vend ifif dAngle<0 thenDi_H=-Di_Hend
17、 ifDim oSel as SelectionDim oVisProps as VisPropertySetset oSel = oDrwDocument.SelectionoSel.ClearDim TextV As intTextV=R/2 'Draw the horizontall line for i=0 TO ny if dAngle=0 then set Line2D1 = oFactory2D.CreateLine (X1-D/3,Y1+D*i,X1+nx*D+D/3,Y1+D*i) oSel.Add Line2D1 set Circle2D1=oFactory2D.C
18、reateClosedCircle(X1-D/3 -R,Y1+D*i,R) oSel.Add Circle2D1 set Line2D1= oFactory2D.CreateLine(X1-D/3-R*2,Y1+D*i,X1-D/3,Y1+D*i) oSel.Add Line2D1 Set MyText = oDrwView.Texts.Add(Text_XYZ_V,X1-D/3 -R,Y1+D*i+TextV) MyText.AnchorPosition = catMiddleCenter MyText.SetFontSize 0, 0, iFontSize Set MyText = oDr
19、wView.Texts.Add(Y1+D*i)*Di_V,X1-D/3 -R,Y1+D*i-TextV) MyText.AnchorPosition = catMiddleCenter MyText.SetFontSize 0, 0, iFontSize end if if dAngle>0 then set Line2D1 = oFactory2D.CreateLine (X1-D/3,-Y1-D*i,X1+nx*D+D/3,-Y1-D*i) oSel.Add Line2D1 set Circle2D1=oFactory2D.CreateClosedCircle(X1+nx*D+D/3
20、 +R,-Y1-D*i,R) oSel.Add Circle2D1 set Line2D1= oFactory2D.CreateLine(X1+nx*D+D/3+R,-Y1-D*i+R,X1+nx*D+D/3+R,-Y1-D*i-R) oSel.Add Line2D1 Set MyText = oDrwView.Texts.Add(Text_XYZ_V,X1+nx*D+D/3+R +TextV,-Y1-D*i) MyText.AnchorPosition = catMiddleCenter MyText.SetFontSize 0, 0, iFontSize Set MyText = oDrw
21、View.Texts.Add(Y1+D*i)*Di_V,X1+nx*D+D/3+R -TextV,-Y1-D*i) MyText.AnchorPosition = catMiddleCenter MyText.SetFontSize 0, 0, iFontSize end if if dAngle<0 then set Line2D1 = oFactory2D.CreateLine (-X1+D/3,Y1+D*i,-(X1+nx*D+D/3),Y1+D*i) oSel.Add Line2D1 set Circle2D1=oFactory2D.CreateClosedCircle(-(X1
22、+nx*D+D/3)-R,Y1+D*i,R) oSel.Add Circle2D1 set Line2D1= oFactory2D.CreateLine(-X1-nx*D-D/3-R,Y1+D*i+R,-X1-nx*D-D/3-R,Y1+D*i-R) oSel.Add Line2D1 Set MyText = oDrwView.Texts.Add(Text_XYZ_V,-X1-nx*D-D/3-R +TextV,Y1+D*i) MyText.AnchorPosition = catMiddleCenter MyText.SetFontSize 0, 0, iFontSize Set MyTex
23、t = oDrwView.Texts.Add(Y1+D*i)*Di_V,-X1-nx*D-D/3-R -TextV,Y1+D*i) MyText.AnchorPosition = catMiddleCenter MyText.SetFontSize 0, 0, iFontSize end if next 'Draw the vertical line for j=0 TO nx if dAngle=0 then set Line2D1 = oFactory2D.CreateLine (X1+D*j,Y1-D/3,X1+D*j,Y1+ny*D+D/3) oSel.Add Line2D1
24、set Circle2D1=oFactory2D.CreateClosedCircle(X1+D*j,Y1+ny*D+D/3+R,R) oSel.Add Circle2D1 set Line2D1 = oFactory2D.CreateLine(X1+D*j-R,y1+ny*D+D/3+R,X1+D*J+R,y1+ny*D+D/3+R) oSel.Add Line2D1 Set MyText = oDrwView.Texts.Add(Text_XYZ_H,X1+D*j,Y1+ny*D+D/3+R+TextV) MyText.AnchorPosition = catMiddleCenter My
25、Text.SetFontSize 0, 0, iFontSize Set MyText = oDrwView.Texts.Add(X1+D*j)*Di_H,X1+D*j,y1+ny*D+D/3+R-TextV) MyText.AnchorPosition = catMiddleCenter MyText.SetFontSize 0, 0, iFontSize end if if dAngle>0 then set Line2D1 = oFactory2D.CreateLine (X1+D*j,-Y1+D/3,X1+D*j,-Y1-ny*D-D/3) oSel.Add Line2D1 se
26、t Circle2D1=oFactory2D.CreateClosedCircle(X1+D*j,-Y1+D/3+R,R) oSel.Add Circle2D1 set Line2D1 = oFactory2D.CreateLine(X1+D*j,-Y1+D/3+R*2,X1+D*J,-Y1+D/3) oSel.Add Line2D1 Set MyText = oDrwView.Texts.Add(Text_XYZ_H,X1+D*j+TextV,-Y1+D/3+R) MyText.AnchorPosition = catMiddleCenter MyText.SetFontSize 0, 0, iFontSize Set MyText = oDrwView.Texts.Add(X1+D*j)*Di_H,X1+D*j-TextV,-Y1+D/3+R) MyText.AnchorPosition = catMiddleCenter MyText.SetFontSize 0, 0, iFontSize end if if dAngle<0 then set Line2D1 = oFactory2D.Creat
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 注册会计师审计中会计估计审计的风险评估程序
- 2026四川成都市新津区外国语实验小学校面向社会招聘教师18人备考题库含答案详解(黄金题型)
- 2026广西柳州融安县长安镇卫生院乡村医生招聘2人备考题库附答案详解(研优卷)
- 房地产企业账务处理实操案例(含收入核算)
- 2206江西鹰潭市邮政分公司现面向社会招聘合同用工备考题库附参考答案详解(精练)
- 2026扬州平山堂茶业发展有限公司招聘茶饮店劳务派遣人员2人备考题库及答案详解【典优】
- 2026山东济南市第一人民医院招聘卫生高级人才和博士(控制总量)18人备考题库及答案详解【历年真题】
- 2026山东济南市第五人民医院招聘卫生高级人才和博士(控制总量)8人备考题库及答案详解【典优】
- 2026新疆喀什昆仑建设有限公司招聘3人备考题库及参考答案详解(综合卷)
- 2026广东深圳高级中学集团招聘23人备考题库及答案详解【易错题】
- 四川省广元市高2026届第二次高考适应性检测数学+答案
- TSG08-2026《特种设备使用管理规则》全面解读课件
- 《2026年化学制药企业安全风险防控专项工作方案》解读
- 2026年江西赣州市高三一模高考数学试卷试题(含答案详解)
- 企业管理 华为会议接待全流程手册SOP
- 员工宿舍安全卫生检查
- 福建省莆田市2022-2023学年六年级下学期期末数学试卷
- 劳务派遣劳务外包服务方案(技术方案)
- 2023版全媒体运营师职业标准
- 护理查房早期人工流产的护理查房
- 《等腰三角形的判定与反证法》优课一等奖课件
评论
0/150
提交评论