Catia百格线生成宏doc.docx
《Catia百格线生成宏doc.docx》由会员分享,可在线阅读,更多相关《Catia百格线生成宏doc.docx(11页珍藏版)》请在冰点文库上搜索。
Catia百格线生成宏doc
Catia百格线生成宏
Catia百格线生成宏
你是否为在Catia做2D图纸的时候,画百格线而伤脑筋呢?
别担心,接下来我告诉你一个简单的方法
1.新建一个txt文本文档,比如Draw-Grid.txt
2.把以下内容复制到Draw-Grid.txt中
=========这里开始,不要复制我========
OptionExplicit
'***********************************************************************
' Purpose:
ThismacroallowsyoutocreateGridlineinCATIAdrawing
' Author:
chenqa
' Languages:
VBScript
' Locales:
English
' DevelopingCATIALevel:
V5R12
' Viewmushparalleltosystemaixes,viewangle0deg,90degand-90deg
'***********************************************************************
SubCATMain()
DimY1AsInteger
DimX2AsInteger
DimY2AsInteger
DimPt1AsPoint2D
DimPt2AsPoint2D
'TheviewscaledAngleforrotateviewscaleforviewscale
DimdScale,dAngleAsDouble
'Theviewcoordinateorigin
DimXAsInt
DimYAsInt
DimxSel AsINFITF.Selection
D=InputBox("PleaseInputtheDistanceValue","inputbox","100")
D=Cint(D)
'Retriveanewdrawingdocument
SetoDrwDocument=CATIA.ActiveDocument
'Retrievethedrawingdocument'ssheetscollection
SetoDrwSheets=oDrwDocument.Sheets
'Retrievetheactivesheet
SetoDrwSheet=oDrwSheets.ActiveSheet
'Retrievetheactiveviewofthesheet
SetoDrwView=oDrwSheet.Views.ActiveView
'Retrivethevalueoftheview
X=oDrwView.xAxisData
Y=oDrwView.yAxisData
dScale=oDrwView.Scale
dAngle=oDrwView.Angle
SetoFactory2D=oDrwView.Factory2D
'Getthecoordinatefromtheselecttwopoint
'OnErrorResumeNext
SetxSel=CATIA.ActiveDocument.Selection
xSel.clear
ReDimsFilter(0)
sFilter(0)="Point2D"
MsgBox"Pleaseselecttheleft-bottompoint"
sStatus=xSel.SelectElement2(sFilter,"SelectFirstPoint.",false)
If(sStatus="Normal")Then
DimSelectedPoint1AsSelectedElement
SetSelectedPoint1=xSel.Item
(1)
Dimpt1Coord
(2)AsInt
SelectedPoint1.GetCoordinates(pt1Coord)
'MsgBox"Thefrstpointhasbeenselected"
ElseMsgBox"Selecta2DPoint1"
ExitSub
EndIf
MsgBox"Pleaseselecttheritht-toppoint"
sStatus=xSel.SelectElement2(sFilter,"SelectTheSecondPoint.",false)
If(sStatus="Normal")Then
DimSelectedPoint2AsSelectedElement
SetSelectedPoint2=xSel.Item
(1)
Dimpt2Coord
(2)AsInt
SelectedPoint2.GetCoordinates(pt2Coord)
'MsgBox"Thesecondpointhasbeenselected"
ElseMsgBox"Selecta2Dpoint1"
ExitSub
EndIf
ifdAngle=0then
X1=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))
'MsgBoxX
ifdAngle>0then
X1=Cint((pt1Coord
(1)-Y)/dScale)
Y1=Cint((pt1Coord(0)-X)/dScale)
X2=Cint((pt2Coord
(1)-Y)/dScale)
Y2=Cint((pt2Coord(0)-X)/dScale)
endif
ifdAngle<0then
X1=Cint((pt1Coord
(1)-Y)/dScale)
Y1=Cint((pt1Coord(0)-X)/dScale)
X2=Cint((pt2Coord
(1)-Y)/dScale)
Y2=Cint((pt2Coord(0)-X)/dScale)
endif
X1=D*Cint(X1/D)
Y1=D*Cint(Y1/D)
X2=D*Cint(X2/D)
Y2=D*Cint(Y2/D)
nx=(X2-X1)\D'Thenumberofthehorizontalline
ny=(Y2-Y1)\D'Thenumberoftheverticalline
DimLine2D1AsLine2D
DimCircle2D1asCircle2D
DimMyTextasDrawingText
DimiFontsizeasDouble
DimiAsInt
DimjAsInt
DimRAsDoubel'theradiusofthecircle
iFontSize=3.5
R=8
R=R/dScale
'------------------------------------------------------
DimDi_H,Di_Vasint
DimText_XYZ_Hasstring
DimText_XYZ_Vasstring
Di_H=1
Di_V=1
'ComparethedrawingviewHVwith3DAixes
DimXX1,YY1,ZZ1,XX2,YY2,ZZ2asint
oDrwView.GenerativeBehavior.GetProjectionPlaneXX1,YY1,ZZ1,XX2,YY2,ZZ2
if(XX1=1)then
Text_XYZ_H="X"
Endif
if(XX1=-1)then
Text_XYZ_H="X"
Di_H=-1
Endif
if(YY1=1)then
Text_XYZ_H="Y"
Endif
if(YY1=-1)then
Text_XYZ_H="Y"
Di_H=-1
Endif
if(ZZ1=1)then
Text_XYZ_H="Z"
Endif
if(ZZ1=-1)then
Text_XYZ_H="Z"
Di_H=-1
Endif
if(XX2=1)then
Text_XYZ_V="X"
Endif
if(XX2=-1)then
Text_XYZ_V="X"
Di_V=-1
Endif
if(YY2=1)then
Text_XYZ_V="Y"
Endif
if(YY2=-1)then
Text_XYZ_V="Y"
Di_V=-1
Endif
if(ZZ2=1)then
Text_XYZ_V="Z"
Endif
if(ZZ2=-1)then
Text_XYZ_V="Z"
Di_V=-1
Endif
ifdAngle>0then
Di_V=-Di_V
endif
ifdAngle<0then
Di_H=-Di_H
endif
DimoSelasSelection
DimoVisPropsasVisPropertySet
setoSel=oDrwDocument.Selection
oSel.Clear
DimTextVAsint
TextV=R/2
'Drawthehorizontallline
fori=0TOny
ifdAngle=0then
setLine2D1=oFactory2D.CreateLine(X1-D/3,Y1+D*i,X1+nx*D+D/3,Y1+D*i)
oSel.AddLine2D1
setCircle2D1=oFactory2D.CreateClosedCircle(X1-D/3-R,Y1+D*i,R)
oSel.AddCircle2D1
setLine2D1=oFactory2D.CreateLine(X1-D/3-R*2,Y1+D*i,X1-D/3,Y1+D*i)
oSel.AddLine2D1
SetMyText=oDrwView.Texts.Add(Text_XYZ_V,X1-D/3-R,Y1+D*i+TextV)
MyText.AnchorPosition=catMiddleCenter
MyText.SetFontSize0,0,iFontSize
SetMyText=oDrwView.Texts.Add((Y1+D*i)*Di_V,X1-D/3-R,Y1+D*i-TextV)
MyText.AnchorPosition=catMiddleCenter
MyText.SetFontSize0,0,iFontSize
endif
ifdAngle>0then
setLine2D1=oFactory2D.CreateLine(X1-D/3,-Y1-D*i,X1+nx*D+D/3,-Y1-D*i)
oSel.AddLine2D1
setCircle2D1=oFactory2D.CreateClosedCircle(X1+nx*D+D/3+R,-Y1-D*i,R)
oSel.AddCircle2D1
setLine2D1=oFactory2D.CreateLine(X1+nx*D+D/3+R,-Y1-D*i+R,X1+nx*D+D/3+R,-Y1-D*i-R)
oSel.AddLine2D1
SetMyText=oDrwView.Texts.Add(Text_XYZ_V,X1+nx*D+D/3+R+TextV,-Y1-D*i)
MyText.AnchorPosition=catMiddleCenter
MyText.SetFontSize0,0,iFontSize
SetMyText=oDrwView.Texts.Add((Y1+D*i)*Di_V,X1+nx*D+D/3+R-TextV,-Y1-D*i)
MyText.AnchorPosition=catMiddleCenter
MyText.SetFontSize0,0,iFontSize
endif
ifdAngle<0then
setLine2D1=oFactory2D.CreateLine(-X1+D/3,Y1+D*i,-(X1+nx*D+D/3),Y1+D*i)
oSel.AddLine2D1
setCircle2D1=oFactory2D.CreateClosedCircle(-(X1+nx*D+D/3)-R,Y1+D*i,R)
oSel.AddCircle2D1
setLine2D1=oFactory2D.CreateLine(-X1-nx*D-D/3-R,Y1+D*i+R,-X1-nx*D-D/3-R,Y1+D*i-R)
oSel.AddLine2D1
SetMyText=oDrwView.Texts.Add(Text_XYZ_V,-X1-nx*D-D/3-R+TextV,Y1+D*i)
MyText.AnchorPosition=catMiddleCenter
MyText.SetFontSize0,0,iFontSize
SetMyText=oDrwView.Texts.Add((Y1+D*i)*Di_V,-X1-nx*D-D/3-R-TextV,Y1+D*i)
MyText.AnchorPosition=catMiddleCenter
MyText.SetFontSize0,0,iFontSize
endif
next
'Drawtheverticalline
forj=0TOnx
ifdAngle=0then
setLine2D1=oFactory2D.CreateLine(X1+D*j,Y1-D/3,X1+D*j,Y1+ny*D+D/3)
oSel.AddLine2D1
setCircle2D1=oFactory2D.CreateClosedCircle(X1+D*j,Y1+ny*D+D/3+R,R)
oSel.AddCircle2D1
setLine2D1=oFactory2D.CreateLine(X1+D*j-R,y1+ny*D+D/3+R,X1+D*J+R,y1+ny*D+D/3+R)
oSel.AddLine2D1
SetMyText=oDrwView.Texts.Add(Text_XYZ_H,X1+D*j,Y1+ny*D+D/3+R+TextV)
MyText.AnchorPosition=catMiddleCenter
MyText.SetFontSize0,0,iFontSize
SetMyText=oDrwView.Texts.Add((X1+D*j)*Di_H,X1+D*j,y1+ny*D+D/3+R-TextV)
MyText.AnchorPosition=catMiddleCenter
MyText.SetFontSize0,0,iFontSize
endif
ifdAngle>0then
setLine2D1=oFactory2D.CreateLine(X1+D*j,-Y1+D/3,X1+D*j,-Y1-ny*D-D/3)
oSel.AddLine2D1
setCircle2D1=oFactory2D.CreateClosedCircle(X1+D*j,-Y1+D/3+R,R)
oSel.AddCircle2D1
setLine2D1=oFactory2D.CreateLine(X1+D*j,-Y1+D/3+R*2,X1+D*J,-Y1+D/3)
oSel.AddLine2D1
SetMyText=oDrwView.Texts.Add(Text_XYZ_H,X1+D*j+TextV,-Y1+D/3+R)
MyText.AnchorPosition=catMiddleCenter
MyText.SetFontSize0,0,iFontSize
SetMyText=oDrwView.Texts.Add((X1+D*j)*Di_H,X1+D*j-TextV,-Y1+D/3+R)
MyText.AnchorPosition=catMiddleCenter
MyText.SetFontSize0,0,iFontSize
endif
ifdAngle<0then
setLine2D1=oFactory2D.CreateLine(-X1-D*j,Y1-D/3,-X1-D*j,Y1+ny*D+D/3)
oSel.AddLine2D1
setCircle2D1=oFactory2D.CreateClosedCircle(-X1-D*j,Y1-D/3-R,R)
oSel.AddCircle2D1
setLine2D1=oFactory2D.CreateLine(-X1-D*j,Y1-D/3-R*2,-X1-D*J,Y1-D/3)
oSel.AddLine2D1
SetMyText=oDrwView.Texts.Add(Text_XYZ_H,-X1-D*j+TextV,Y1-D/3-R)
MyText.AnchorPosition=catMiddleCenter
MyText.SetFontSize0,0,iFontSize
SetMyText=oDrwView.Texts.Add((X1+D*j)*Di_H,-X1-D*j-TextV,Y1-D/3-R)
MyText.AnchorPosition=catMiddleCenter
MyText.SetFontSize0,0,iFontSize
endif
next
dimoFontSizeAslong
'MyText.SetFontSize0,0,iFontSize
setoVisProps=oSel.VisProperties
oVisProps.SetRealWidth1,0'1stparameterlinewidth1-632ndparameterinheritanceflag1or0
oVisProps.SetRealColor0,255,0,1
SetoVisProps=Nothing
SetoSel=Nothing
'Updatedrawingtable