Вы находитесь на странице: 1из 5

(http://www.coe.

org/)
Login (http://www.coe.org/l/li/in/) Forgot Your Password? (l/li/if)

 (https://twitter.com/COEHQ )  (https://www.facebook.com/COE-110142939522/ ) 
(https://www.linkedin.com/company/10467092/)  (https://www.youtube.com/user/coeorg )

Calculate total area of selected surface


Taner Karagöz

Calculate total area of selected surface

November 11, 2013 07:40 AM

i am trying to write a macro to calculate total area of same coloured surfaces so i tried this
commands. it works but only show last area value. I want to see overall area value of
selection.i tried (i+1) vs.. but it doesnt work. How can i do that?

Sub CATMain()

Dim Selection1 As Selection

Dim spabench As SPAWorkbench

Dim mymeasure As Measurable

Dim myref As Reference

Dim myarea As Double

Dim partDocument1 As PartDocument

Dim part1 As Part

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set Selection = CATIA.ActiveDocument.Selection

Selection.ClearSelection.Search ("'Topology'.Face.Color='(175,255,175)';scr")
For i = 1 To Selection.Count2Set

myref = Selection.Item(i).Reference

Set spabench = partDocument1.GetWorkbench("SPAWorkbench")

Set mymeasure = spabench.GetMeasurable(myref)

myarea = mymeasure.Area * 1000000

AllArea = myarea

Debug.Print

Next i

MsgBox "Total_Faces_Area= " & Format(AllArea, "0.000") & ("mm2")

End Sub

thanks for your interest...

Alexandre Desaulniers

RE: Calculate total area of selected surface

November 11, 2013 08:05 AM (in response to Taner Karagöz (http://www.coe.org/p/fo/et/thread=27684#p80839))

There are a few things wrong but the main one to fix it was this

Selection.Search ("(Topology.Face & Color='(175,255,175)'),scr")

Complete Code (Modified)

Dim Selection As Selection ' Selection1 declared but Selection used ... Fixed

Dim spabench As SPAWorkbench

Dim mymeasure As Measurable

Dim myref As Reference


Dim myarea As Double

Dim partDocument1 As PartDocument

Dim part1 As Part

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set Selection = CATIA.ActiveDocument.Selection


Selection.Clear   'Seperated the clear of the selection
Selection.Search ("(Topology.Face & Color='(175,255,175)'),scr")  'Fixed the search
parameters..did a manual search then saved/copied it

For i = 1 To Selection.Count2

Set myref = Selection.Item(i).Reference

Set spabench = partDocument1.GetWorkbench("SPAWorkbench")

Set mymeasure = spabench.GetMeasurable(myref)

myarea = mymeasure.Area * 1000000

AllArea = myarea

Debug.Print

Next i

MsgBox "Total_Faces_Area= " & Format(AllArea, "0.000") & ("mm2")

End Sub

Taner Karagöz

RE: Calculate total area of selected surface

November 11, 2013 08:34 AM (in response to Alexandre Desaulniers


(http://www.coe.org/p/fo/et/thread=27684#p80840))

Thanks for fixing, Alexandre. despite the wrong things, it works but our problem still
continues.I need to calculate overall surface area after loop. I will try to do this with loop
(using i parameter) but it gives area values partially.
Ex: 

A face  area is 2000mm2

B face is 4000mm2 

i need A+B faces overall area value

but macro give me partial area. how can i do that?

Alexandre Desaulniers

RE: Calculate total area of selected surface

November 11, 2013 09:02 AM (in response to Taner Karagöz (http://www.coe.org/p/fo/et/thread=27684#p80841))

AllArea = AllArea + myarea

Taner Karagöz

RE: Calculate total area of selected surface

November 15, 2013 04:13 AM (in response to Alexandre Desaulniers


(http://www.coe.org/p/fo/et/thread=27684#p80842))

thanks alex, how i can i use this macro with 3dxml documents?

Alexandre Desaulniers

RE: Calculate total area of selected surface

November 18, 2013 08:59 AM (in response to Taner Karagöz (http://www.coe.org/p/fo/et/thread=27684#p80886))

If you are trying to get it inside a 3DXML this means V6 document.  I think the way to define
the partdocument is what changed.

I have not worked with Catia V6 so can't help you.

Sorry
Copyright © 2018 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 (http://www.coe.org/p/cm/ld/fid=2) - Privacy Policy (page/privacy-policy) - Contact
(mailto:coe@coe.org?Subject=COE%20Website%20Question)

Вам также может понравиться