You are on page 1of 5

02/02/2016 COE 

: Forums : In a VB macro, how can I measure the area of a selected surface?

Nov 27
2006
In a VB macro, how can I measure the area of a selected surface?
Test Admin In a VB macro, how can I measure the area of a selected surface?
[Admin November 27, 2006 03:46 PM
Group]
In a VB macro I ask the user to select a surface. I want to know the area of this surface. This is the code for the surface selection.
After the selection what is the VB code to measure the surface? Is it possible for someone to give me the code?
    Dim CATIA As Object
    Call OpenCatia(CATIA)
   
    Set partDocument1 = CATIA.ActiveDocument
   
    Set part1 = partDocument1.Part
   
    Dim InputObjectType(0)
    Set partDocument1 = CATIA.ActiveDocument
   
    Set Selection = partDocument1.Selection
   
    Selection.Clear
    InputObjectType(0) = "Face"
    Status = Selection.SelectElement2(InputObjectType, "Select the surface to measure", True)
    If (Status = "cancel" Then Exit Sub
 

Thomas RE: In a VB macro, how can I measure the area of a selected surface?
Miller November 27, 2006 04:11 PM (in response to Test Admin)
[Rolls­
Might want to try doing a search. This has been covered in the past. But here is a link that talks about it.
Royce
Corporation]
http://www.coe.org/Collaboration/DiscussionForum/ActiveDiscussions/tabid/210/view/topic/forumid/10/postid/99398/Default.aspx

Tom
 

Test Admin RE: In a VB macro, how can I measure the area of a selected surface?
[Admin November 28, 2006 10:51 AM (in response to Test Admin)
Group]
Thank you Tmiller11. Your answer help me a little, but I still have a problem.

This is the VB code for the exemple. My problem is I don't know how to create the reference of the selected surface

Sub CATMain()
Dim pd As PartDocument
Dim mysurf As Object
Dim spabench As SPAWorkbench
Dim mymeas As Measurable
Dim ref1 As Reference
Dim myans As Double

Set pd = CATIA.ActiveDocument
''''''''''''''''''''''''''''''
'wath is the code to set mysurf of a selected element. I do not know the name of the hybridbody.
''''''''''''''''''''''''''''''
Set mysurf = pd.Part.HybridBodies.Item(1).HybridShapes.Item(1)
Debug.Print mysurf.Name
Set ref1 = pd.Part.CreateReferenceFromObject(mysurf)
Set spabench = pd.GetWorkbench("SPAWorkbench")
Set mymeas = spabench.GetMeasurable(ref1)
myans = mymeas.Area
Debug.Print myans
End Sub
 

http://www.coe.org/p/fo/et/thread=15466 1/5
02/02/2016 COE : Forums : In a VB macro, how can I measure the area of a selected surface?

Thomas RE: In a VB macro, how can I measure the area of a selected surface?
Miller November 28, 2006 11:01 AM (in response to Test Admin)
[Rolls­
Nancy,
Royce
Corporation]
Basically what you will be doing isntead of Set mysurf = pd.Part.HybridBodies.Item(1).HybridShapes.Item(1), you will be doing the following
'Only have to change this line. Since, it looks like you will be selecting which surface to use you will be using a selection set instead of
stepping throught each element in the hybrid bodies.
Set mysurf = Selection.SelectElement2(InputObjectType, "Select the surface to measure", True)

'Orginial Code
Set ref1 = pd.Part.CreateReferenceFromObject(mysurf)
Set spabench = pd.GetWorkbench("SPAWorkbench")
Set mymeas = spabench.GetMeasurable(ref1)
myans = mymeas.Area
Debug.Print myans
End Sub

Also, a suggestion would be to write this in VBA. They have a Code Library that you can look at to find out the exact commands.

Tom
 

Test Admin RE: In a VB macro, how can I measure the area of a selected surface?

[Admin November 30, 2006 10:16 AM (in response to Test Admin)
Group]
Hello Tom,

I still have a problem. I have a error message at the CreateReferenceFromObject. Can you help me again.

Dim CATIA As Object
Call OpenCatia(CATIA)

Dim mysurf As Object
Dim spabench As SPAWorkbench
Dim mymeas As Measurable
Dim ref1 As Reference
Dim myans As Double
Dim InputObjectType(0)

Set partDocument1 = CATIA.ActiveDocument
Set Part1 = partDocument1.Part
Set Selection = partDocument1.Selection

Selection.Clear
'The user have to select the face
InputObjectType(0) = "Face"
Status = Selection.SelectElement2(InputObjectType, "Sélectionner la face de la plaquette", True)
If (Status = "cancel") Then Exit Sub

Set mysurf = Selection.Item(1).Value
Debug.Print mysurf.Name

'***************
'The code stop at the next line. I have the message error "The method CreateReferenceFromObject fail"
'***************

Set ref1 = Part1.CreateReferenceFromObject(mysurf)
Set spabench = partDocument1.GetWorkbench("SPAWorkbench")
Set mymeas = spabench.GetMeasurable(ref1)
myans = mymeas.Area
Debug.Print myans

Thank you,
Nancy
 

http://www.coe.org/p/fo/et/thread=15466 2/5
02/02/2016 COE : Forums : In a VB macro, how can I measure the area of a selected surface?

Thomas RE: In a VB macro, how can I measure the area of a selected surface?
Miller November 30, 2006 11:14 AM (in response to Test Admin)
[Rolls­
Nancy,
Royce
Corporation]
I think you problem lies within the Set mysurf = Selection.Item(1).Value. You haven't selected anything into the selection set. So Item 1 of it
is empty. I think you are going to have to do it this way Set mysurf = Selection.SelectElement2(InputObjectType, "Sélectionner la face de la
plaquette", True). I think this will be correct. If that doesn't work try reading the user selection again. into mysurf.

Tom
 

Cliff RE: In a VB macro, how can I measure the area of a selected surface?

Johnson, November 30, 2006 11:19 AM (in response to Test Admin)
Cliff
For a selected face you do not need to make a reference. There is one already available to you.
[Tata
Technologies]
Try this:

Set ref1 = Selection.Item(1).Reference
 

Test Admin RE: In a VB macro, how can I measure the area of a selected surface?

[Admin November 30, 2006 11:43 AM (in response to Test Admin)
Group]
Hello Tom,
Hello Cliff,

Thank you for your help! My code is working now! The last solution was the good one. For a selected face I do not need to make a reference.
Can you tell me were I can find this information. I will have for the next week to write some macro to select and measure Sketch, Line,
Intersection and some other feature. For which object do I have to "CreateReferenceForObject"?

Dim CATIA As Object
Call OpenCatia(CATIA)

Dim spabench As SPAWorkbench
Dim mymeas As Measurable
Dim ref1 As Reference
Dim myans As Double
Dim InputObjectType(0)

Set partDocument1 = CATIA.ActiveDocument
Set Part1 = partDocument1.Part
Set Selection = partDocument1.Selection

Selection.Clear
'The user have to select the face
InputObjectType(0) = "Face"
Status = Selection.SelectElement2(InputObjectType, "Select the face", True)
If (Status = "cancel") Then Exit Sub

Set ref1 = Selection.Item(1).Reference
Set spabench = partDocument1.GetWorkbench("SPAWorkbench")
Set mymeas = spabench.GetMeasurable(ref1)
myans = mymeas.Area
Debug.Print myans
 

http://www.coe.org/p/fo/et/thread=15466 3/5
02/02/2016 COE : Forums : In a VB macro, how can I measure the area of a selected surface?

Cliff RE: In a VB macro, how can I measure the area of a selected surface?
Johnson, November 30, 2006 12:24 PM (in response to Test Admin)
Cliff
Where can you find this information? It's pretty much tribal knowledge so you are in the right place. It might be in the automation
[Tata
documentation but I don't think so.
Technologies]

But to explain deeper, anything you pick which is topology­; Face, Edge, Vertex; things which you select from a solid are only available by
reference. So it will not be possible to CreateReferenceFromObject on those things but you can directly use the reference from the
SelectedElement object.

Other things that are Geometry ­ Point, Line, Plane, etc. you can use CreateReferenceFromObject on. However, you may also be able to
directly use the Reference from the SelectedEntity object on those too. I am not totally sure, but I think so. You should try that first.
 

All Times America/New_York

http://www.coe.org/p/fo/et/thread=15466 4/5
02/02/2016 COE : Forums : In a VB macro, how can I measure the area of a selected surface?

Copyright © 2013 COE. All Rights Reserved
800­COE­CALL ­ 330 N. Wabash Ave, Suite 2000 ­ Chicago, IL 60611 USA 
All material, files, logos and trademarks within this site are properties of their respective organizations.
Terms of Service ­ Privacy Policy ­ Contact

http://www.coe.org/p/fo/et/thread=15466 5/5

You might also like