版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Catia 百格线生成宏你是否为在Catia 做 2D 图纸的时候,画百格线而伤脑筋呢?别担心,接下来我告诉你一个简单的方法1. 新建一个 txt 文本文档,比如Draw-Grid.txt2.把以下容复制到Draw-Grid.txt中这里开始,不要复制我Option Explicit' *'Purpose: This macro allows you to create Grid line in CATIA drawing' Author: chenqa'Languages:VBScript'Locales:English' Developing
2、 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 at each alert during its execution CATIA.DisplayFileAlert
3、s = False' Optional: allows to find the sample wherever it's installed' Variables declarationDim oDrwDocument As DrawingDocumentDim oDrwSheets As DrawingSheetsDim oDrwSheet As DrawingSheetDim oDrwView As DrawingViewDim oFactory2D AS Factory2D' The Distance between the linesDim D As I
4、ntegerDim nx As IntegerDim ny As Integer' The point coordinate select from Drawing Dim X1 As IntegerDim Y1 As IntegerDim X2 As IntegerDim Y2 As IntegerDim Pt1 As Point2DDim Pt2 As Point2D'The view scale dAngle for rotate view scale for view scale Dim dScale,dAngle As Double'The view coor
5、dinate originDim X As IntDim Y As IntDim xSelAs INFITF.SelectionD= InputBox("Please Input the Distance Value", "input box", "100")D= Cint (D)' Retrive a new drawing documentSet oDrwDocument = CATIA.ActiveDocument' Retrieve the drawing document's sheets colle
6、ction Set oDrwSheets = oDrwDocument.Sheets' Retrieve the active sheetSet oDrwSheet = oDrwSheets.ActiveSheet' Retrieve the active view of the sheet'Retrive the value of the viewX= oDrwView.xAxisDataY= oDrwView.yAxisDatadScale = oDrwView.ScaledAngle= oDrwView.AngleSet oFactory2D = oDrwView
7、.Factory2D'Get the coordinate from the select two point 'On Error Resume NextReDim sFilter(0)sFilter(0) = "Point2D"MsgBox "Please select the left-bottom point "sStatus = xSel.SelectElement2(sFilter, "Select First Point.", false)If (sStatus = "Normal")
8、ThenDim SelectedPoint1 As SelectedElementSet SelectedPoint1 = xSel.Item(1)Dim pt1Coord(2) As Int SelectedPoint1.GetCoordinates ( pt1Coord ) 'MsgBox "The frst point has been selected "Else MsgBox "Select a 2D Point 1"Exit SubEnd IfMsgBox "Please select the ritht-top point
9、 "sStatus = xSel.SelectElement2(sFilter, "Select The Second Point.", false)If (sStatus = "Normal") ThenDim SelectedPoint2 As SelectedElementSet SelectedPoint2 = xSel.Item(1)Dim pt2Coord(2) As IntSelectedPoint2.GetCoordinates ( pt2Coord )'MsgBox "The second point has
10、 been selected "Else MsgBox "Select a 2D point 1"Exit SubEnd Ifif dAngle=0 thenX1= 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 Xif dAngle>0 thenX1=Cint
11、(pt1Coord(1)-Y)/dScale)Y1=Cint (pt1Coord(0) -X)/dScale)X2= Cint (pt2Coord(1)-Y)/dScale)Y2= Cint (pt2Coord(0)-X)/dScale)end ifif dAngle<0 thenX1=Cint(pt1Coord(1)-Y)/dScale)Y1=Cint (pt1Coord(0) -X)/dScale)X2= Cint (pt2Coord(1)-Y)/dScale)Y2= Cint (pt2Coord(0)-X)/dScale)end ifX1 = D * Cint(X1/D)Y1 =
12、D * Cint (Y1/D)X2= D * Cint (X2/D)Y2 = D * Cint (Y2/D)nx = (X2-X1) D 'The number of the horizontal line ny = (Y2-Y1) D 'The number of the vertical lineDim Line2D1 As Line2DDim Circle2D1 as Circle2DDim MyText as DrawingTextDim iFontsize as DoubleDim i As IntDim j As IntDim R As Doubel 'th
13、e radius of the circleiFontSize = 3.5R=8R=R / dScale'-Dim Di_H,Di_V as intDim Text_XYZ_H as stringDim Text_XYZ_V as stringDi_H=1Di_V=1XX1,YY1,ZZ1,XX2,YY2,ZZ2if (XX1=1) thenText_XYZ_H="X"End ifif (XX1=-1) thenText_XYZ_H="X"Di_H=-1End ifif (YY1=1) thenText_XYZ_H="Y"En
14、d ifif (YY1=-1) thenText_XYZ_H="Y"Di_H=-1End ifif (ZZ1=1) thenText_XYZ_H="Z"End ifif (ZZ1=-1) thenText_XYZ_H="Z"Di_H=-1End ifif (XX2=1) thenText_XYZ_V="X"End ifif (XX2=-1) thenText_XYZ_V="X"Di_V=-1End ifif (YY2=1) thenText_XYZ_V="Y"End ifif
15、 (YY2=-1) thenText_XYZ_V="Y"Di_V=-1End ifif (ZZ2=1) thenText_XYZ_V="Z"End ifif (ZZ2=-1) thenText_XYZ_V="Z"Di_V=-1End ifif dAngle>0 thenDi_V=-Di_Vend ifif dAngle<0 thenDi_H=-Di_Hend ifDim oSel as SelectionDim oVisProps as VisPropertySetset oSel = oDrwDocument.Selec
16、tionoSel.ClearDim TextV As intTextV=R/2'Draw the horizontall linefor i=0 TO nyif dAngle=0 thenset Line2D1 = oFactory2D.CreateLine (X1-D/3,Y1+D*i,X1+nx*D+D/3,Y1+D*i)oSel.Add Line2D1set Circle2D1=oFactory2D.CreateClosedCircle(X1-D/3 -R,Y1+D*i,R)oSel.Add Circle2D1set Line2D1=oFactory2D.CreateLine(X
17、1-D/3-R*2,Y1+D*i,X1-D/3,Y1+D*i)oSel.Add Line2D1MyText.AnchorPosition = catMiddleCenter MyText.SetFontSize 0, 0, iFontSizeMyText.AnchorPosition = catMiddleCenter MyText.SetFontSize 0, 0, iFontSizeend ifif dAngle>0 thenset Line2D1 = oFactory2D.CreateLine (X1-D/3,-Y1-D*i,X1+nx*D+D/3,-Y1-D*i)oSel.Add
18、 Line2D1set Circle2D1=oFactory2D.CreateClosedCircle(X1+nx*D+D/3+R,-Y1-D*i,R)oSel.Add Circle2D1set 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 Line2D1MyText.AnchorPosition = catMiddleCenter MyText.SetFontSize 0, 0, iFontSizeMyText.AnchorPosition = catMiddleC
19、enter MyText.SetFontSize 0, 0, iFontSize end ifif dAngle<0 thenset Line2D1 = oFactory2D.CreateLine (-X1+D/3,Y1+D*i,-(X1+nx*D+D/3),Y1+D*i)oSel.Add Line2D1setCircle2D1=oFactory2D.CreateClosedCircle(-(X1+nx*D+D/3)-R,Y1+D*i,R) oSel.Add Circle2D1set Line2D1=oFactory2D.CreateLine(-X1-nx*D-D/3-R,Y1+D*i+
20、R,-X1-nx*D-D/3-R,Y1+D *i-R)oSel.Add Line2D1MyText.AnchorPosition = catMiddleCenterMyText.SetFontSize 0, 0, iFontSizeMyText.AnchorPosition = catMiddleCenter MyText.SetFontSize 0, 0, iFontSizeend ifnext'Draw the vertical linefor j=0 TO nxif dAngle=0 thenset Line2D1 = oFactory2D.CreateLine (X1+D*j,
21、Y1-D/3,X1+D*j,Y1+ny*D+D/3)oSel.Add Line2D1setCircle2D1=oFactory2D.CreateClosedCircle(X1+D*j,Y1+ny*D+D/3+R,R) oSel.Add Circle2D1set 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 Line2D1Set MyText =MyText.SetFontSize 0, 0, iFontSizeSet MyText =MyText.SetFontSiz
22、e 0, 0, iFontSizeend ifif dAngle>0 thenset Line2D1 = oFactory2D.CreateLine (X1+D*j,-Y1+D/3,X1+D*j,-Y1-ny*D-D/3)oSel.Add Line2D1setCircle2D1=oFactory2D.CreateClosedCircle(X1+D*j,-Y1+D/3+R,R) oSel.Add Circle2D1set Line2D1 =oFactory2D.CreateLine(X1+D*j,-Y1+D/3+R*2,X1+D*J,-Y1+D/3)oSel.Add Line2D1Set
23、MyText =MyText.AnchorPosition = catMiddleCenterMyText.SetFontSize 0, 0, iFontSizeSet MyText =MyText.AnchorPosition = catMiddleCenterMyText.SetFontSize 0, 0, iFontSizeend ifif dAngle<0 thenset Line2D1 = oFactory2D.CreateLine (-X1-D*j,Y1-D/3,-X1-D*j,Y1+ny*D+D/3)oSel.Add Line2D1set Circle2D1=oFactory2D.CreateClosedCircle(-X1-D*j,Y1-D/3-R,R)oSel.Add Circle2D1set Line2D1 =oFactory2D.CreateLine(-X1-D*j,Y1-D/3-R*2,-X1-D*J,Y1-D/3)oSel.Add
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中医护理在呼吸系统疾病中的护理创新
- 2023年版儿童肺炎支原体肺炎诊疗指南解读
- 八年级道德与法治上册《在社会中成长:理解个人与社会的双向建构》教学设计
- 2026医院患者氧气吸入法操作并发症的预防及处理流程
- 2026公路养护工程量清单及计量规范核心要点
- 初中八年级历史《新纪元:中华人民共和国的成立》教学设计
- 护理安全用药与管理
- COACH小红书科学种草案例
- 中央性前置胎盘的康复护理
- 初中八年级地理上册第三章第三节《中国的矿产资源》教学设计(人教版)
- 北师大版三年级下册期末检测语文试卷(A卷)
- 高效求解器设计与实现-深度研究
- 公共卫生执业医师资格考试历年真题大(含答案及详解)
- DB35-T 2198-2024 工业园区低零碳创建评估准则
- DB4210T 68-2024 马铃薯秋延后大棚生产技术规程
- (高清版)DB41∕T 2137-2021 公路隧道监控量测技术规程
- GA/T 804-2024机动车号牌专用固封装置
- 孟万金编制的中国大学生积极心理品质量表+评分方式
- 思辨与创新智慧树知到期末考试答案章节答案2024年复旦大学
- (正式版)JBT 9229-2024 剪叉式升降工作平台
- 智能工程测井系统使用说明书样本
评论
0/150
提交评论