版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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河南省曲剧艺术保护传承中心招聘备考题库及完整答案详解1套
- 2026浙江台州学院后勤发展有限公司招聘6人备考题库附答案详解
- 2026广西南宁市人力资源和社会保障局招募南宁市本级第一批就业见习人员758人备考题库附答案详解(模拟题)
- 2026河南郑州国家调查队公益性岗位招聘8人备考题库及1套完整答案详解
- 2026江西吉安市泰和县新睿人力资源服务有限公司猎聘1人备考题库附答案详解(轻巧夺冠)
- 2026年吉林工程技术师范学院公开招聘工作人员备考题库(1号)含答案详解(典型题)
- 2026云南昆明市卫生健康委员会全国引才活动第二批后备人才招聘54人备考题库附答案详解(b卷)
- 2026年铁岭市教育局校园招聘143人备考题库带答案详解
- 武汉地铁集团有限公司2026届春季校园招聘备考题库含答案详解(完整版)
- 2026四川甘孜州稻城县资产投融资集团有限公司招聘集团会计人员1人备考题库含答案详解(达标题)
- 四川省广元市高2026届第二次高考适应性检测数学+答案
- TSG08-2026《特种设备使用管理规则》全面解读课件
- pe线管施工方案(3篇)
- 《2026年化学制药企业安全风险防控专项工作方案》解读
- 上海上海市农业科学院工作人员招聘35人(2025年第一批)笔试历年参考题库附带答案详解(5卷)
- 2026年江西赣州市高三一模高考数学试卷试题(含答案详解)
- 2026及未来5年中国工业旅游行业市场现状调查及未来趋势研判报告
- 企业管理 华为会议接待全流程手册SOP
- 上海国际货币经纪有限责任公司招聘笔试题库2026
- 2026年忻州职业技术学院单招职业适应性考试题库参考答案详解
- 商务英语专业人才需求市场调研报告
评论
0/150
提交评论