制作CATIA百格线的小程序

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

20100723你是否为在Catia做2D图纸的时候,画百格线而伤脑筋呢?别担心,接下来我告诉你一个简单的方法1.新建一个txt文本文档,比如Draw-Grid.txt2.把以下内容复制到Draw-Grid.txt中=========这里开始,不要复制我========OptionExplicit'***********************************************************************'Purpose:ThismacroallowsyoutocreateGridlineinCATIAdrawing'Author:chenqa'Languages:VBScript'Locales:English'DevelopingCATIALevel:V5R12'Viewmushparalleltosystemaixes,viewangle0deg,90degand-90deg'***********************************************************************SubCATMain()CATIA.RefreshDisplay=FalseDimsStatusAsString'SettheCATIApopupfilealertstoFalse'ItpreventstostopthemacroateachalertduringitsexecutionCATIA.DisplayFileAlerts=False'Optional:allowstofindthesamplewhereverit'sinstalled'VariablesdeclarationDimoDrwDocumentAsDrawingDocumentDimoDrwSheetsAsDrawingSheetsDimoDrwSheetAsDrawingSheetDimoDrwViewAsDrawingViewDimoFactory2DASFactory2D'TheDistancebetweenthelinesDimDAsIntegerDimnxAsIntegerDimnyAsInteger'ThepointcoordinateselectfromDrawingDimX1AsIntegerDimY1AsIntegerDimX2AsIntegerDimY2AsIntegerDimPt1AsPoint2DDimPt2AsPoint2D'TheviewscaledAngleforrotateviewscaleforviewscaleDimdScale,dAngleAsDouble'TheviewcoordinateoriginDimXAsIntDimYAsIntDimxSelAsINFITF.SelectionD=InputBox(PleaseInputtheDistanceValue,inputbox,100)D=Cint(D)'RetriveanewdrawingdocumentSetoDrwDocument=CATIA.ActiveDocument'Retrievethedrawingdocument'ssheetscollectionSetoDrwSheets=oDrwDocument.Sheets'RetrievetheactivesheetSetoDrwSheet=oDrwSheets.ActiveSheet'RetrievetheactiveviewofthesheetSetoDrwView=oDrwSheet.Views.ActiveView'RetrivethevalueoftheviewX=oDrwView.xAxisDataY=oDrwView.yAxisDatadScale=oDrwView.ScaledAngle=oDrwView.AngleSetoFactory2D=oDrwView.Factory2D'Getthecoordinatefromtheselecttwopoint'OnErrorResumeNextSetxSel=CATIA.ActiveDocument.SelectionxSel.clearReDimsFilter(0)sFilter(0)=Point2DMsgBoxPleaseselecttheleft-bottompointsStatus=xSel.SelectElement2(sFilter,SelectFirstPoint.,false)If(sStatus=Normal)ThenDimSelectedPoint1AsSelectedElementSetSelectedPoint1=xSel.Item(1)Dimpt1Coord(2)AsIntSelectedPoint1.GetCoordinates(pt1Coord)'MsgBoxThefrstpointhasbeenselectedElseMsgBoxSelecta2DPoint1ExitSubEndIfMsgBoxPleaseselecttheritht-toppointsStatus=xSel.SelectElement2(sFilter,SelectTheSecondPoint.,false)If(sStatus=Normal)ThenDimSelectedPoint2AsSelectedElementSetSelectedPoint2=xSel.Item(1)Dimpt2Coord(2)AsIntSelectedPoint2.GetCoordinates(pt2Coord)'MsgBoxThesecondpointhasbeenselectedElseMsgBoxSelecta2Dpoint1ExitSubEndIfifdAngle=0thenX1=Cint((pt1Coord(0)-X)/dScale)Y1=Cint((pt1Coord(1)-Y)/dScale)X2=Cint((pt2Coord(0)-X)/dScale)Y2=Cint((pt2Coord(1)-Y)/dScale)endif'MsgBox(pt1Coord(0))'MsgBoxXifdAngle0thenX1=Cint((pt1Coord(1)-Y)/dScale)Y1=Cint((pt1Coord(0)-X)/dScale)X2=Cint((pt2Coord(1)-Y)/dScale)Y2=Cint((pt2Coord(0)-X)/dScale)endififdAngle0thenX1=Cint((pt1Coord(1)-Y)/dScale)Y1=Cint((pt1Coord(0)-X)/dScale)X2=Cint((pt2Coord(1)-Y)/dScale)Y2=Cint((pt2Coord(0)-X)/dScale)endifX1=D*Cint(X1/D)Y1=D*Cint(Y1/D)X2=D*Cint(X2/D)Y2=D*Cint(Y2/D)nx=(X2-X1)\D'Thenumberofthehorizontallineny=(Y2-Y1)\D'ThenumberoftheverticallineDimLine2D1AsLine2DDimCircle2D1asCircle2DDimMyTextasDrawingTextDimiFontsizeasDoubleDimiAsIntDimjAsIntDimRAsDoubel'theradiusofthecircleiFontSize=3.5R=8R=R/dScale'------------------------------------------------------DimDi_H,Di_VasintDimText_XYZ_HasstringDimText_XYZ_VasstringDi_H=1Di_V=1'ComparethedrawingviewHVwith3DAixesDimXX1,YY1,ZZ1,XX2,YY2,ZZ2asintoDrwView.GenerativeBehavior.GetProjectionPlaneXX1,YY1,ZZ1,XX2,YY2,ZZ2if(XX1=1)thenText_XYZ_H=XEndifif(XX1=-1)thenText_XYZ_H=XDi_H=-1Endifif(YY1=1)thenText_XYZ_H=YEndifif(YY1=-1)thenText_XYZ_H=YDi_H=-1Endifif(ZZ1=1)thenText_XYZ_H=ZEndifif(ZZ1=-1)thenText_XYZ_H=ZDi_H=-1Endifif(XX2=1)thenText_XYZ_V=XEndifif(XX2=-1)thenText_XYZ_V=XDi_V=-1Endifif(YY2=1)thenText_XYZ_V=YEndifif(YY2=-1)thenText_XYZ_V=YDi_V=-1Endifif(ZZ2=1)thenText_XYZ_V=ZEndifif(ZZ2=-1)thenText_XYZ_V=ZDi_V=-1EndififdAngle0thenDi_V=-Di_VendififdAngle0thenDi_H=-Di_HendifDimoSelasSelectionDimoVisPropsasVisPropertySetsetoSel=oDrwDocument.SelectionoSel.ClearDimTextVAsintTextV=R/2'Drawthehorizontalllinefori=0TOnyifdAngle=0thensetLine2D1=oFactory2D.CreateLine(X1-D/3,Y1+D*i,X1+nx*D+D/3,Y1+D*i)oSel.AddLine2D1setCircle2D1=oFactory2D.CreateClosedCircle(X1-D/3-R,Y1+D*i,R)oSel.AddCircle2D1setLine2D1=oFactory2D.CreateLine(X1-D/3-R*2,Y1+D*i,X1-D/3,Y1+D*i)oSel.AddLine2D1SetMyText=oDrwView.Texts.Add(Text_XYZ_V,X1-D/3-R,Y1+D*i+TextV)MyText.AnchorPosition=catMiddleCenterMyText.SetFontSize0,0,iFontSizeSetMyText=oDrwView.Texts.Add((Y1+D*i)*Di_V,X1-D/3-R,Y1+D*i-TextV)MyText.AnchorPosition=catMiddleCenterMyText.SetFontSize0,0,iFontSizeendififdAngle0thensetLine2D1=oFactory2D.CreateLine(X1-D/3,-Y1-D*i,X1+nx*D+D/3,-Y1-D*i)oSel.AddLine2D1setCircle2D1=oFactory2D.CreateClosedCircle(X1+nx*D+D/3+R,-Y1-D*i,R)oSel.AddCircle2D1setLine2D1=oFactory2D.CreateLine(X1+nx*D+D/3+R,-Y1-D*i+R,X1+nx*D+D/3+R,-Y1-D*i-R)oSel.AddLine2D1SetMyText=oDrwView.Texts.Add(Text_XYZ_V,X1+nx*D+D/3+R+TextV,-Y1-D*i)MyText.AnchorPosition=catMiddleCenterMyText.SetFontSize0,0,iFontSizeSetMyText=oDr

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功