Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Section view - how to redefine section view

Status
Not open for further replies.

zoran_s

Mechanical
Aug 30, 2021
4
AT
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.
Section_view_bvpydl.jpg


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
 
Replies continue below

Recommended for you

Use X,Y, xAxisData and yAxisData properties of a DrawingView

CATIA.ActiveDocument.Sheets.ActiveSheet.Views.Item("view name").X = 42

Note however that a section view's position is most likely constrained to the front view position.
 
Sorry it seams like misunderstanding.
I don't want to reposition view on the paper/screen, I want to change position of section A-A inside Front view:

Section_A-A_pmgi1o.jpg


Thanks in advance.
 
Hi Little,
in 1st code I've listed it seams that part of code which shall replace position of section is missing...I don't know where and how to find that part.

in 2nd code I've recorded macro where I'm creating new section A-A and then instead of creating new view I've tried to use already generated section view A-A:

'Dim drawingView2 As DrawingView
'Set drawingView2 = drawingViews1.Add("AutomaticNaming") '- this code I replaced with next one
Set drawingView2 = drawingViews1.Item("A-A")
Also I've replaced array for position of section but does not work.

So don't know what is the problem, why it work when the tool create new section view but not when I try to use already existing section view A-A?

Best regards and thanks for help.
 
I did record the section cut generation, and then I replaced the values from the arrayOfVariantOfDouble1(3)--and it worked.
the values are calculated with respect to the view's origin (the blue H- and V- axis)

Dim arrayOfVariantOfDouble1(3)
arrayOfVariantOfDouble1(0) = -380
arrayOfVariantOfDouble1(1) = 60
arrayOfVariantOfDouble1(2) = -380
arrayOfVariantOfDouble1(3) = -60
Set drawingViewGenerativeBehavior2Variant = drawingViewGenerativeBehavior2
drawingViewGenerativeBehavior2Variant.DefineSectionView arrayOfVariantOfDouble1, "SectionView", "Offset", 1, drawingViewGenerativeBehavior1


regards,
LWolf
 
Hi LWolf,

It works when you exchange array values and you create the new section view.
But what I want is to redefine existing section view A-A, not create new.
So the section profile A-A to remove on other position.

Thanks,
Zoran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top