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!

Automatic Section of the Product

Status
Not open for further replies.

chantzisdim

Aerospace
Nov 21, 2014
2
GB
Dear all

I would like to write a script for exporting sections(1mm step in Z directions) of a product. Can you please provide guidance? I can do it manually but i would like to do it automatically. I can provide the command sequence.
 
Replies continue below

Recommended for you

' COPYRIGHT DASSAULT SYSTEMES 2001
Option Explicit

' ***********************************************************************
' Purpose : Create a network of sections.
' Assumptions : A CATProduct document should be active.
' Author :
' Languages : VBScript
' Locales : English
' CATIA Level : V5R6
' ***********************************************************************
Dim iNumber ' Number of sections in the network
iNumber = 10

Sub CATMain()

' Retrieve the Sections collection
Dim cSections As Sections
Set cSections = CATIA.ActiveDocument.Product.GetTechnologicalObject("Sections")

' Create the master section
Dim oMasterSection As Section
Set oMasterSection = cSections.Add

' Retrieve data on master section
Dim Position(11)
oMasterSection.GetPosition Position
Dim dHeight As Double
dHeight = oMasterSection.Height
Dim dWidth As Double
dWidth = oMasterSection.Width
Dim dMin As Double
If (dWidth > dHeight) Then
dMin = dWeight
Else
dMin = dWidth
End If

' Remove the master section
cSections.Remove oMasterSection
Set oMasterSection = Nothing

' Create the network
Dim oSection As Section
Position(11) = Position(11) - dMin / 2
Dim I As Integer
For I = 1 To iNumber

' Create section and force type
Set oSection = cSections.Add
oSection.Type = catSectionTypePlane

' Modify position
Position(11) = Position(11) + dMin / iNumber
oSection.SetPosition Position

Set oSection = Nothing
Next

Set cSections = Nothing

End Sub


______

Alex ,
 
Thank you very max alex.

Can you please advise on the following 3 things?
1. Change the sectioning step along the Z axis.
2. Can the macro can always start in absolute co ordinates (xy,zy,xy CATIA Planes)
3. Measure the area of each section and export the number in a txt or csv or....

Thank you very much for your help.

Best Regards,
Dimitris
 
Code:
Sub CATMain()

' Retrieve the Sections collection
Dim cSections As Sections
Set cSections = CATIA.ActiveDocument.Product.GetTechnologicalObject("Sections")

' Create the master section
Dim oMasterSection As Object 'Section
Set oMasterSection = cSections.Add

' Retrieve data on master section
Dim Position(11)
oMasterSection.GetPosition Position
Dim dHeight As Double
dHeight = oMasterSection.Height
Dim dWidth As Double
dWidth = oMasterSection.Width
Dim dMin As Double
If (dWidth > dHeight) Then
dMin = dWeight
Else
dMin = dWidth
End If

' Remove the master section
cSections.Remove oMasterSection
Set oMasterSection = Nothing

' Create the network
Dim oSection As Object 'Section

Position(11) = 1

Do
' Create section and force type
Set oSection = cSections.Add
oSection.Type = catSectionTypePlane

' Modify position
Position(11) = Position(11) + 1
oSection.SetPosition Position

Indicator = oSection.IsEmpty

If Indicator = 0 Then
cSections.Remove oSection
Else
End If

Set oSection = Nothing
Loop Until Indicator = 0


Set cSections = Nothing

End Sub

______

Alex ,
 
What scripting language are you working in, VBA, catvbs or CATScript? If you are in catvbs, you need to comment out the item types, as Alex has indicated. It will also help if you post what the error actually says.
 
chantzisdim said:
script for exporting sections(1mm step in Z directions) of a product.

Just to create the sections...

Code:
Sub CATMain()

Dim cSections 
Set cSections = CATIA.ActiveDocument.Product.GetTechnologicalObject("Sections")

Dim oMasterSection 
Set oMasterSection = cSections.Add


Dim Position(11)
oMasterSection.GetPosition Position

Dim dHeight 
dHeight = oMasterSection.Height

Dim dWidth 
dWidth = oMasterSection.Width

Dim dMin
If (dWidth > dHeight) Then
dMin = dWeight
Else
dMin = dWidth
End If

cSections.Remove oMasterSection
Set oMasterSection = Nothing


Dim oSection
Position(11) = 0

Do

Set oSection = cSections.Add
oSection.Type = catSectionTypePlane

Position(11) = Position(11) + 1
oSection.SetPosition Position

Indicator = oSection.IsEmpty

If Indicator = 0 Then
cSections.Remove oSection
Else
End If

Set oSection = Nothing
Loop Until Indicator = 0

Set cSections = Nothing

End Sub




______

Alex ,
 
 http://files.engineering.com/getfile.aspx?folder=734ce449-5db3-4e07-9642-de2cffe0961f&file=movie.avi
If you are in vbs you cannot use collections...there is no collections class. If you use vba you can use collections...otherwise you will need to use arrays to collect things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top