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!

[MACRO] CATIA need for advice, please help me

Status
Not open for further replies.

scarda

Mechanical
Apr 23, 2014
14
US
Hi Guys,

I am new in this forum and first i wanna say hello to all of you!

I am a new VBA user for CATIA V5 and i need your advice. I am not looking for someone who does the project for me but just some tips, so please if you can help me.

I am developing a macro to import in excel the data from a part, geometry and specifications, basically i need to count and to assign a number to each surface of the part, and for each surface to extract the specifications if present on it.

I understood the part about how to extract the specifications but i dont know how to link every specification to its surface.

Thats what i wrote up to now:
---------------------------------------------
Sub CATMain()
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim annotationSets1 As AnnotationSets
Set annotationSets1 = part1.AnnotationSets
Dim annotationSet1 As AnnotationSet
Set annotationSet1 = annotationSets1.Item(1)
Dim annotations As annotations
Set annotations = annotationSet1.annotations

Dim IdxAnnot
Dim AnnotName
Dim AnnotSuperType
Dim AnnotType
For IdxAnnot = 1 To annotations.Count
Set Annotation = annotations.Item(IdxAnnot)
AnnotName = Annotation.Name
AnnotSuperType = Annotation.SuperType
AnnotType = Annotation.Type
'MsgBox ("Annotation: " & IdxAnnot & " " & AnnotName & " , " & AnnotSuperType & " , " & AnnotType
Select Case AnnotType
Case "FTA_DatumSimple"
Label = Annotation.DatumSimple.Label
MsgBox ("Annotation: " & IdxAnnot & " , " & AnnotSuperType & " , " & Label
Case "FTA_ReferenceFrame"
Set AllDatumsSimple = Annotation.ReferenceFrame.AllDatumsSimple (WRONG)
For DatumsCount = 1 To AllDatumsSimple.Count
Set Datum1 = AllDatumsSimple.Item(DatumsCount
'Set Label = Datum1.DatumSimple.Label
MsgBox DatumsCount
Next
'MsgBox ("Annotation: " & IdxAnnot & " , " & AnnotSuperType & " , " & Label)
........
End Select
.........
Next
...........

-------------------------------------------------

I know is nothing special and there are errors, but i dont know how to fix it.

Basically what i want to do is for each type of specification retrieve the information I need, but how to understand these specifications on which surface are applied? and for each surface i need to know on which plan is positioned (normal vector).

I hope I explained my problem clearly and that someone could help me.

Thank you guys
 
Replies continue below

Recommended for you

Hi Fernando,

First of all thank you for your reply!

Attached is the image of the part, do you also need the file?

As you can see it is a simple part with some specifications, and i need to enumerate the surfaces of the part,
and then somehow to understand for each surface if there are specifications applied, which kind and the parameters of the specification.

I am new in the forum and i dont know how to describe what i wanna do, please if you need more infortmation tell me.



8
 

From what i understood, to set a specification on a plane the procedure is:

Code:
Dim annotation As Annotation
Dim usersurface As UserSurface
Dim reference As Reference
Dim UserSurfaceList As UserSurfaces
Set UserSurfaceList = part1.UserSurfaces
set the plane As selection
set reference =selection.reference
set usersurface = UserSurfaceList.Generate(reference)

Dim annotationSet1 As AnnotationSet
Set annotationSet1 = annotationSets1.Add("Annotations.1")

Dim annotations As annotations
Set annotations = annotationSet1.annotations

Dim annotFactory
Set annotFactory = annotationSet1.AnnotationFactory

Set annotation = annotFactory.CreateSemanticDimension(usersurface......)

so catia creates a usersurface every time i add a specification on a new surface, but where are stored the geometrical data of that surface?
and what for the surfaces that are not usersurfaces?

as you can see i am "a little bit" confused.....

Thank for your help!

Regards

Sergio
 
Hi Fernando,

thank again for your reply.

i am only considering a part with planar or cylindrical external surfaces on the plans xy-yz-zx or plans parallel to them.
the information i need are:

- number of external surfaces, type of each surface (cylinder or plan )
- positioning plan for each surface: es. is the surface on the xy plane or a plane parallel to it?

- if its also possible the coordinates of the vertex points of each surface:
if its a plan the coordinates of the vertex, if its a cylinder the two extreme points of its axis.

- then for each surface the specifications applied on it (type of specification and characteristics)

Attached is my sample part, i hope this time its more clear what i wanna do

thanks again

Regards

Sergio



 
 http://files.engineering.com/getfile.aspx?folder=c2d969a5-2adc-4ab9-88b0-73bb3d68c161&file=Parte1.CATPart
Hi,

First of all I wouldn't use "Enable Hybrid Design".
In your part, what do you mean by external surfaces? Can you colour them to understand better ?
For vertex coordinates you can see this
To extract the coordinates of the ending axis of a cylinder you can extract the center of the TriDimFeatEdge
Extracting coordinates will allow you (with a little math) to find the orientation for each surface (you can also extract them first).


Regards
Fernando

 
Hi Fernando,

thank again for your reply and your patience with me!

first: thank you for your tip about the "enable hybrid design" i didnt notice it (i am not so good at CATIA, just universitary use)

second: for external surface i mean what you get when you search "Face" in the part.(if i search for surface i find only the planes, thats not clear to me why, whats the difference between face and surface?)

Basically my idea now is something like this code, but i get an error in the search a Vertex in a Face, because i guess a vertex does not belong to a face, in fact a vertex belongs to several surfaces (three in my case), so how can i get for each "Face" the vertex.

i read the post in the link you sent me, but i dont understand the solution you proposed.


Code:
Sub CATMain()

Dim objSel As Selection
Set objSel = CATIA.ActiveDocument.Selection
objSel.Search ("Type=Face,all")
objcount = objSel.Count

MsgBox objcount

For i = 1 To objcount

Set Selection = objSel.Item(i)
[COLOR=#EF2929]Selection.Search "Topology.Vertex,sel"[/color]
Y = Selection.Count
MsgBox Y

Next

Set annotation = annotations.Item(IdxAnnot)
SurfCount = annotation.GetSurfacesCount()
Dim enumValues () as Variant
ReDim enumValues (SurfCount - 1)
annotation.GetSurfaces(enumValues)
Dim Name As String

For i = LBound(enumValues) to UBound(enumValues)
    Name = enumValues(i) 
    msgBox Name
Next
End Sub

i found these two links in another forum and in one of them i guess its you who answered, basically i need to joint these two parts
Link
Link

thank you very much for your time and help

regards

sergio
 
It would be good if you will check first this link , lot of info about searching.

I would extract the faces (based on color for example) then in each extracted face I would extract vertex, eventually all this done in separate new created geometrical sets, then continue as I described in previous post.

Regards
Fernando

 
Hi Fernando,

thank you for the link and the suggestions.

Correct me if i am wrong, your suggestion is set a different color for each face and then for example search using this query?

(Color=Magenta & Topology.Vertex),all

I tried, but doesnt find anything, its like the vertex has not a color.

I also tried to set the same color for two faces with an edge in common, and search:

(Color=Magenta & Topology.Edge),all

but same result, it seems like edges and vertex have no color, so i cant relate them to the face using the color property

any other suggestion?

Regards

Sergio
 
Different kind of solutions....just some ideas...

How to select all faces based on color...

Code:
Language="VBSCRIPT"
Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim oselection1 As Selection
Set oselection1 = partDocument1.Selection

oselection1.Search "(Color='(210,210,255)' - (CATPrtSearch.GeometricFeature + CATPrtSearch.BodyFeature)),all"

CATIA.StartCommand "Extract"    
End Sub

How to select vertex in one selected face

Code:
Dim Language As String
Language="VBSCRIPT"

Sub CATMain()
Dim  colDocum        As Documents         
Dim  DocActivo       As Document          
Dim  part1              AS Part              
Dim  colBodies       As Bodies          
Dim  hSFact            As Factory           

Dim  colHBody            As HybridBodies     
Dim  OpenBody1         As HybridBody        
Dim  sStatus                As String        
Dim  mySelection        As Selection          
Dim InputObjectType(0)
InputObjectType(0) = "Face"    
Dim refBorde              As Reference  

Set DocActivo = CATIA.ActiveDocument
Set part1 = DocActivo.Part
Set mySelection = DocActivo.Selection
Set hSFact = part1.HybridShapeFactory
Set colBodies = part1.Bodies

Status = mySelection.SelectElement2(InputObjectType, "Select a Face or hit ESCAPE: ", True)
   If (Status = "Cancel") Then
	Exit Sub
   End If

Set refBorde = mySelection.Item(1).Value
Dim hybridShapeExtract1 as HybridShapeExtract 
Set hybridShapeExtract1 = hSFact.AddNewExtract(refBorde)
    hybridShapeExtract1.PropagationType = 3
    hybridShapeExtract1.ComplementaryExtract = False
    hybridShapeExtract1.IsFederated = False
Set refBorde = hybridShapeExtract1
hybridShapeExtract1.Name ="Extracted_Face"

''''' Create Open Body 
Dim HB1 As HybridBodies
Set HB1 = CATIA.ActiveDocument.Part.HybridBodies
Dim Hierarchie1, ImKoerper As HybridBody
Set Hierarchie1 = HB1.Add
Hierarchie1.Name = "Extracted_Elements"
''''''''
Set colHBody = part1.HybridBodies
Set OpenBody1 = part1.InWorkObject        
OpenBody1.AppendHybridShape hybridShapeExtract1
part1.InWorkObject = hybridShapeExtract1

part1.Update 
mySelection.Clear
mySelection.Add(hybridShapeExtract1)

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = partDocument1.Selection

selection1.Search "Topology.CGMVertex,sel"

    MsgBox selection1.Count2 & " Vertex are found from the selected face"
    
    CATIA.StartCommand "Extract"    

End Sub

Regards
Fernando

 
Hi Fernando,

i really dont know how to thank you, you did a lot for me!

Without your help for me would be impossible, i will try to use it as soon i have time, and will let you know if i succeded.

Can i ask you where did you study it so well? because i bought the only two books i found about VB programming in CATIA V5
but they are not so detailed, i understand its a too big subject but how can i study more?

Regards
Sergio

 
Hi Fernando,

the books i mean are:

CATIA V5: Macro Programming with Visual Basic Script (Dieter Ziethen)
VB Scripting for CATIA V5 ( Emmett Ross)

The first book is quite big around 700 pages, in the second i guess you cant find anything you dont yet know.

About the first I have the PDF, if you could need just ask.

Yes, I can see you have a lot of experience on it, for me its the first month in this world,
and sure i am trying to do something much bigger than i could.

Regards

Sergio
 
Hi,

You are right about both books, I really appreciate first one because is giving you much more clear and original explanations. Anyway, search also FAQ section of this forum for other resources.

About your project...is always like this, in the beginning it seems to be simple but you end with something else [smile]

Regards
Fernando

 
Hi Fernando,

I am trying to adapt the code you sent me to my part, and considering that i tried so many times but i couldnt succeed in making "selectelement2" working (windows 7 64 bit), i am trying with a loop for every face.

I modified it in this way, it extracts all the faces but then, even if it selects for each face the vertexes and tells me the numbers of them, at the end the extract command extracts only one time (the vertexes of the first face).

Sure modifying randomly i did something wrong (the level of this code is too high for me)

Code:
 Sub CATMain()

Dim DocActivo        As Document
Dim part1               As Part
Dim mySelection         As Selection
Dim hSFact             As Factory
Dim colBodies        As Bodies

Dim colHBody             As HybridBodies
Dim OpenBody1          As HybridBody
Dim refBorde              As Reference

Set DocActivo = CATIA.ActiveDocument
Set part1 = DocActivo.Part
Set mySelection = DocActivo.Selection
Set hSFact = part1.HybridShapeFactory
Set colBodies = part1.Bodies

Set mySelection = CATIA.ActiveDocument.Selection
mySelection.Search ("Type=Face,all")

Dim objcount As Integer
objcount = mySelection.Count
MsgBox objcount

For i = 1 To objcount

Set refBorde = mySelection.Item(i).Value
Dim hybridShapeExtract1(6) As hybridShapeExtract
Set hybridShapeExtract1(i) = hSFact.AddNewExtract(refBorde)
    hybridShapeExtract1(i).PropagationType = 3
    hybridShapeExtract1(i).ComplementaryExtract = False
    hybridShapeExtract1(i).IsFederated = False
Set refBorde = hybridShapeExtract1(i)
hybridShapeExtract1(i).name = "Extracted_Face" & " " & i

''''' Create Open Body
Dim HB1 As HybridBodies
Set HB1 = CATIA.ActiveDocument.Part.HybridBodies
Dim Hierarchie1, ImKoerper As HybridBody
Set Hierarchie1 = HB1.Add
Hierarchie1.name = "Extracted_Elements"
''''''''
Set colHBody = part1.HybridBodies
Set OpenBody1 = part1.InWorkObject
OpenBody1.AppendHybridShape hybridShapeExtract1(i)
part1.InWorkObject = hybridShapeExtract1(i)
part1.Update

Next

mySelection.Clear                        
For i = 1 To 6
part1.InWorkObject = hybridShapeExtract1(i)
part1.Update
mySelection.Add hybridShapeExtract1(i)

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = partDocument1.Selection

selection1.Search "Topology.CGMVertex,sel"
    MsgBox selection1.Count2 & " Vertex are found from the selected face"
    CATIA.StartCommand "Extract"
mySelection.Clear
Next
End Sub

Thanks a lot for your help

Regards

Sergio
 
Hi Fernando,

dont worry, i will find a way, you already helped me a lot and i dont wanna bother you.

Enjoy your vacation!

Regards

Sergio
 
Hi Fernando,

i am really sorry to disturb you again, but if you can i need the last advice.

I finally solved the problem i asked you in the last message, and finally i can extract the vertices for every surface,

i would like to ask you how can i convert a vertex to a point?

because i know how to get the coordinates of a point but not of a vertex

Thank you again

Regards

Sergio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top