Dear user,
I'm first time using this forum.
Need help from someone who is expert or using CAT VBA in CATIA V5.
I would like to control section view position on the drawing but simply don't know how.
When I record the macro it gives "Pure sketch"
So to explain, I have "Front view" and section view "A-A" generated from "Front view" and I want to move section on some other position.
Here is code I got:
Sub CATMain()
Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument
Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets
Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.Item("Sheet.1")
Dim drawingViews1 As DrawingViews
Set drawingViews1 = drawingSheet1.Views
Dim sketch1 As Sketch
Set sketch1 = drawingViews1.Item("Front view")
sketch1.CloseEdition
Dim sketch2 As Sketch
Set sketch2 = drawingViews1.Item("Pure Sketch")
Dim factory2D1 As Factory2D
Set factory2D1 = sketch2.OpenEdition()
Dim drawingView1 As DrawingView
Set drawingView1 = drawingViews1.Item("Pure Sketch")
Dim geometricElements1 As GeometricElements
Set geometricElements1 = drawingView1.GeometricElements
Dim axis2D1 As Axis2D
Set axis2D1 = geometricElements1.Item("AbsoluteAxis")
Dim line2D1 As Line2D
Set line2D1 = axis2D1.GetItem("HDirection")
line2D1.ReportName = 1
Dim line2D2 As Line2D
Set line2D2 = axis2D1.GetItem("VDirection")
line2D2.ReportName = 2
Dim point2D1 As Point2D
Set point2D1 = factory2D1.CreatePoint(100.809265, 68.732704)
point2D1.ReportName = 3
Dim point2D2 As Point2D
Set point2D2 = factory2D1.CreatePoint(100.809265, -6.769706)
point2D2.ReportName = 4
Dim line2D3 As Line2D
Set line2D3 = factory2D1.CreateLine(100.809265, 68.732704, 100.809265, -6.769706)
line2D3.ReportName = 5
line2D3.StartPoint = point2D1
line2D3.EndPoint = point2D2
Dim constraints1 As Constraints
Set constraints1 = drawingViews1.Item("Pure Sketch")
Dim constraint1 As Constraint
Set constraint1 = constraints1.Item("Fixed.1")
constraint1.Mode = catCstModeDrivingDimension
sketch2.CloseEdition
Dim sketch3 As Sketch
' No resolution found for the object sketch3...
Dim factory2D2 As Factory2D
Set factory2D2 = sketch3.OpenEdition()
Dim drawingView2 As DrawingView
' No resolution found for the object drawingView2...
Dim geometricElements2 As GeometricElements
Set geometricElements2 = drawingView2.GeometricElements
Dim point2D3 As Point2D
Set point2D3 = geometricElements2.Item("Point.1")
point2D3.SetData 59.039795, 70.332924
Dim point2D4 As Point2D
Set point2D4 = geometricElements2.Item("Point.2")
point2D4.SetData 59.039795, -5.158927
Dim line2D4 As Line2D
Set line2D4 = geometricElements2.Item("Line.1")
line2D4.SetData 59.039795, 90.296074, 0#, -1#
sketch3.CloseEdition
Set factory2D2 = sketch3.OpenEdition()
Dim drawingView3 As DrawingView
Set drawingView3 = drawingViews1.Item("A-A")
Dim drawingViewGenerativeBehavior1 As DrawingViewGenerativeBehavior
Set drawingViewGenerativeBehavior1 = drawingView3.GenerativeBehavior
drawingViewGenerativeBehavior1.ForceUpdate
End Sub
Also I've tried to create this section A-A with code and later tried to replace in the code that instead of creating new "section view A-A"
program use existing "section view A-A" but unfortunately it does not move section profile:
Set drawingDocument1 = CATIA.ActiveDocument
Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets
Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.ActiveSheet
Set drawingDocument1 = CATIA.ActiveDocument
Set drawingSheets1 = drawingDocument1.Sheets
Set drawingSheet1 = drawingSheets1.ActiveSheet
Dim drawingViews1 As DrawingViews
Set drawingViews1 = drawingSheet1.Views
Dim drawingView1 As DrawingView
Set drawingView1 = drawingViews1.Item("Front view")
Dim drawingViewGenerativeBehavior1 As DrawingViewGenerativeBehavior
Set drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior
'Dim drawingView2 As DrawingView
'Set drawingView2 = drawingViews1.Add("AutomaticNaming") '- this was to create new view and replaced with .Item("A-A")
Dim drawingView2 As DrawingView
Set drawingView2 = drawingViews1.Item("A-A")
Dim drawingViewGenerativeBehavior2 As DrawingViewGenerativeBehavior
Set drawingViewGenerativeBehavior2 = drawingView2.GenerativeBehavior
drawingView2.X = 483.509857
drawingView2.Y = 420.5
Dim double1 As Double
double1 = drawingView1.[Scale]
drawingView2.[Scale] = 1#
Dim double2 As Double
double2 = drawingView1.Angle
drawingView2.Angle = 0#
Dim SectionProfile
ReDim SectionProfile(3)
SectionProfile(0) = 100#
SectionProfile(1) = 100#
SectionProfile(2) = 100#
SectionProfile(3) = -50#
Set drawingViewGenerativeBehavior1Variant = drawingViewGenerativeBehavior2
drawingViewGenerativeBehavior1Variant.DefineSectionView SectionProfile, SectionView, Offset, 0, drawingViewGenerativeBehavior3
Dim drawingViewGenerativeLinks1 As DrawingViewGenerativeLinks
Set drawingViewGenerativeLinks1 = drawingView2.GenerativeLinks
Dim drawingViewGenerativeLinks2 As DrawingViewGenerativeLinks
Set drawingViewGenerativeLinks2 = drawingView1.GenerativeLinks
drawingViewGenerativeLinks2.CopyLinksTo drawingViewGenerativeLinks1
drawingViewGenerativeBehavior2.SetGPSName "DefaultGenerativeStyle.xml"
Set drawingViewGenerativeBehavior2 = drawingView2.GenerativeBehavior
drawingViewGenerativeBehavior2.Update
drawingViewGenerativeBehavior1.ForceUpdate
drawingViewGenerativeBehavior1.Update
drawingViewGenerativeBehavior2.ForceUpdate
drawingViewGenerativeBehavior2.Update
drawingView2.ReferenceView = drawingView1
drawingView2.AlignedWithReferenceView
MsgBox ("Done")
End Sub
I'm first time using this forum.
Need help from someone who is expert or using CAT VBA in CATIA V5.
I would like to control section view position on the drawing but simply don't know how.
When I record the macro it gives "Pure sketch"
So to explain, I have "Front view" and section view "A-A" generated from "Front view" and I want to move section on some other position.
Here is code I got:
Sub CATMain()
Dim drawingDocument1 As DrawingDocument
Set drawingDocument1 = CATIA.ActiveDocument
Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets
Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.Item("Sheet.1")
Dim drawingViews1 As DrawingViews
Set drawingViews1 = drawingSheet1.Views
Dim sketch1 As Sketch
Set sketch1 = drawingViews1.Item("Front view")
sketch1.CloseEdition
Dim sketch2 As Sketch
Set sketch2 = drawingViews1.Item("Pure Sketch")
Dim factory2D1 As Factory2D
Set factory2D1 = sketch2.OpenEdition()
Dim drawingView1 As DrawingView
Set drawingView1 = drawingViews1.Item("Pure Sketch")
Dim geometricElements1 As GeometricElements
Set geometricElements1 = drawingView1.GeometricElements
Dim axis2D1 As Axis2D
Set axis2D1 = geometricElements1.Item("AbsoluteAxis")
Dim line2D1 As Line2D
Set line2D1 = axis2D1.GetItem("HDirection")
line2D1.ReportName = 1
Dim line2D2 As Line2D
Set line2D2 = axis2D1.GetItem("VDirection")
line2D2.ReportName = 2
Dim point2D1 As Point2D
Set point2D1 = factory2D1.CreatePoint(100.809265, 68.732704)
point2D1.ReportName = 3
Dim point2D2 As Point2D
Set point2D2 = factory2D1.CreatePoint(100.809265, -6.769706)
point2D2.ReportName = 4
Dim line2D3 As Line2D
Set line2D3 = factory2D1.CreateLine(100.809265, 68.732704, 100.809265, -6.769706)
line2D3.ReportName = 5
line2D3.StartPoint = point2D1
line2D3.EndPoint = point2D2
Dim constraints1 As Constraints
Set constraints1 = drawingViews1.Item("Pure Sketch")
Dim constraint1 As Constraint
Set constraint1 = constraints1.Item("Fixed.1")
constraint1.Mode = catCstModeDrivingDimension
sketch2.CloseEdition
Dim sketch3 As Sketch
' No resolution found for the object sketch3...
Dim factory2D2 As Factory2D
Set factory2D2 = sketch3.OpenEdition()
Dim drawingView2 As DrawingView
' No resolution found for the object drawingView2...
Dim geometricElements2 As GeometricElements
Set geometricElements2 = drawingView2.GeometricElements
Dim point2D3 As Point2D
Set point2D3 = geometricElements2.Item("Point.1")
point2D3.SetData 59.039795, 70.332924
Dim point2D4 As Point2D
Set point2D4 = geometricElements2.Item("Point.2")
point2D4.SetData 59.039795, -5.158927
Dim line2D4 As Line2D
Set line2D4 = geometricElements2.Item("Line.1")
line2D4.SetData 59.039795, 90.296074, 0#, -1#
sketch3.CloseEdition
Set factory2D2 = sketch3.OpenEdition()
Dim drawingView3 As DrawingView
Set drawingView3 = drawingViews1.Item("A-A")
Dim drawingViewGenerativeBehavior1 As DrawingViewGenerativeBehavior
Set drawingViewGenerativeBehavior1 = drawingView3.GenerativeBehavior
drawingViewGenerativeBehavior1.ForceUpdate
End Sub
Also I've tried to create this section A-A with code and later tried to replace in the code that instead of creating new "section view A-A"
program use existing "section view A-A" but unfortunately it does not move section profile:
Set drawingDocument1 = CATIA.ActiveDocument
Dim drawingSheets1 As DrawingSheets
Set drawingSheets1 = drawingDocument1.Sheets
Dim drawingSheet1 As DrawingSheet
Set drawingSheet1 = drawingSheets1.ActiveSheet
Set drawingDocument1 = CATIA.ActiveDocument
Set drawingSheets1 = drawingDocument1.Sheets
Set drawingSheet1 = drawingSheets1.ActiveSheet
Dim drawingViews1 As DrawingViews
Set drawingViews1 = drawingSheet1.Views
Dim drawingView1 As DrawingView
Set drawingView1 = drawingViews1.Item("Front view")
Dim drawingViewGenerativeBehavior1 As DrawingViewGenerativeBehavior
Set drawingViewGenerativeBehavior1 = drawingView1.GenerativeBehavior
'Dim drawingView2 As DrawingView
'Set drawingView2 = drawingViews1.Add("AutomaticNaming") '- this was to create new view and replaced with .Item("A-A")
Dim drawingView2 As DrawingView
Set drawingView2 = drawingViews1.Item("A-A")
Dim drawingViewGenerativeBehavior2 As DrawingViewGenerativeBehavior
Set drawingViewGenerativeBehavior2 = drawingView2.GenerativeBehavior
drawingView2.X = 483.509857
drawingView2.Y = 420.5
Dim double1 As Double
double1 = drawingView1.[Scale]
drawingView2.[Scale] = 1#
Dim double2 As Double
double2 = drawingView1.Angle
drawingView2.Angle = 0#
Dim SectionProfile
ReDim SectionProfile(3)
SectionProfile(0) = 100#
SectionProfile(1) = 100#
SectionProfile(2) = 100#
SectionProfile(3) = -50#
Set drawingViewGenerativeBehavior1Variant = drawingViewGenerativeBehavior2
drawingViewGenerativeBehavior1Variant.DefineSectionView SectionProfile, SectionView, Offset, 0, drawingViewGenerativeBehavior3
Dim drawingViewGenerativeLinks1 As DrawingViewGenerativeLinks
Set drawingViewGenerativeLinks1 = drawingView2.GenerativeLinks
Dim drawingViewGenerativeLinks2 As DrawingViewGenerativeLinks
Set drawingViewGenerativeLinks2 = drawingView1.GenerativeLinks
drawingViewGenerativeLinks2.CopyLinksTo drawingViewGenerativeLinks1
drawingViewGenerativeBehavior2.SetGPSName "DefaultGenerativeStyle.xml"
Set drawingViewGenerativeBehavior2 = drawingView2.GenerativeBehavior
drawingViewGenerativeBehavior2.Update
drawingViewGenerativeBehavior1.ForceUpdate
drawingViewGenerativeBehavior1.Update
drawingViewGenerativeBehavior2.ForceUpdate
drawingViewGenerativeBehavior2.Update
drawingView2.ReferenceView = drawingView1
drawingView2.AlignedWithReferenceView
MsgBox ("Done")
End Sub