×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Automatic Section of the Product

Automatic Section of the Product

Automatic Section of the Product

(OP)
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.

RE: Automatic Section of the Product

' 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 ,

RE: Automatic Section of the Product

(OP)
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

RE: Automatic Section of the Product

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 ,

RE: Automatic Section of the Product

I've got an error on Dim cSections As Sections.

RE: Automatic Section of the Product

CODE -->

Dim cSections 'As Sections 

______

Alex ,

RE: Automatic Section of the Product

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.

RE: Automatic Section of the Product

Quote (chantzisdim)


script for exporting sections(1mm step in Z directions) of a product.

Just to create the sections...

CODE --> catvbs

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 ,

RE: Automatic Section of the Product

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources