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!

[CatiaV5 R18] Interface to fill part names

Status
Not open for further replies.

us01

New member
Oct 29, 2012
14
Hello,

First, i want to thx you for your help in the previous post. I creat a new subject.

I want to creat an interface to fill "part names". So i'll try to explain you in the following lines how my macro script should work.

After launching Catia V5, I should click on macro and launch it, the macro should like the following panel, where i'll find an interface that i had to fill the blanks. After filling the blanks, Catia will openend me a part, with the text written in the blanks.The written stuff will be replace the proprietes of the part


To understand it, i show it in a drawing.
I know who to built a userpannel in Visual Basic but i didn't know how to code it.

If you can help me !
I will be grateful


Here is the code of 4 parts
Code:
Language="VBSCRIPT"

Sub CATMain()

Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim partDocument1 As Document
Set partDocument1 = documents1.Add("Part")

Dim part1 As Part
Set part1 = partDocument1.Part

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Dim body1 As Body
Set body1 = bodies1.Add()

part1.Update 

Dim body2 As Body
Set body2 = bodies1.Add()

part1.Update 

Dim body3 As Body
Set body3 = bodies1.Add()

part1.Update 

End Sub


viewer.php
958374Forum1.jpg
 
Replies continue below

Recommended for you

Hi,

My advice is to check the net (see FAQ) to see how others are dealing with forms in vba, eventually look for manuals for programming in vba, is quite the same in CATIA.

Look also in online docs, there are also some examples there. Then try to post your code, a simple record macro is not enough, you cannot learn in this way.

I'm also learning each day something, believe me, is a never ending process.

Regards
Fernando

 
Hello sir,

Thx you, i'll try to learn the programmation in VBA, but programmaing on VBA and on CAT VBA is the same thing ?
I'll try to post my code soon !

THX
 
I didn't find it, but may be, in French version, things are differents ?
I have just a last question, how can i attribute a field (for exemple IPN-PO) a function.

And Did you think that the eaiest way to do small programm is to make "macros" ?


Thx

 
I believe v5automation.chm is same name also for french version for CATIA automation help file.

"A small programm" for CATIA can be done in different ways, combining different programming languages or methods or working with a single one.

Regards
Fernando

 
You could optimize a bit your code with a loop and doing only one update at the end.

Code:
Sub CATMain()

Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim partDocument1 As Document
Set partDocument1 = documents1.Add("Part")

Dim part1 As Part
Set part1 = partDocument1.Part

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies


For i = 1 To 3
    bodies1.Add
Next i

part1.Update

End Sub

As for programming example I will strongly suggest VBA pour les nuls, this will give you plenty to learn even if it is Excel oriented.

Do not go in this adventure without a bit of knowledge unless your job is it to have it done by someone else.

PS it is a nice adventure and VBA is not complex... you can do it, we will help you.


Eric N.
indocti discant et ament meminisse periti
 
Hello sir,

i'm late, but i'd like to thanks you for your help.
Actually, VBA isn't my job, and i begin this adventure without any knowlege and i try different "code" founded on internet. But i think i really need to learn it properly
 
Sir, can you tell me, what is the command to rename body name ?

Thx
 
Hi

here is the code (in CATScript, not catvba, you have to adapt)

Language="VBSCRIPT"

Sub CATMain()

Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Document
Set part1 = partDocument1.Part

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Set body1 = bodies1.Add()
Set body2 = bodies1.Add()
Set body3 = bodies1.Add()

Dim selection1 As Selection
Set selection1 = partDocument1.Selection

selection1.Search "CATPrtSearch.BodyFeature,all"

Set oDoc =CATIA.ActiveDocument ' Get current document
Set oPart = oDoc.Part ' Get the part
Set oPartBody = oPart.MainBody ' Grab the mainbody

oPartBody.Name = "Corps principal" ' Rename PartBody
body1.Name = "IPN-PO-XXXX-XX" ' Rename body1
body2.Name = "NIN-ø-XXXX"
body3.Name = "FICTATION"
body3.Name = "GURAGE"

part1.Update

End Sub

Regards
Fernando

 
Hi sir,

i have already my code, here it'is

Code:
Sub CATMain()

Dim giverPartName As String
givenPartName = InputBox("Type a valid part number", "Part Number Definition")

If givenPartName <> "" Then


Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument

Dim part1 As Part
Set part1 = partDocument1.Part

Dim bodies1 As Bodies
Set bodies1 = part1.Bodies

Dim body1 As Body
Set body1 = bodies1.Add()

part1.Update

Dim body2 As Body
Set body2 = bodies1.Add()

part1.Update

Dim body3 As Body
Set body3 = bodies1.Add()

part1.Update


Set oDoc = CATIA.ActiveDocument ' Get current document
Set oPart = oDoc.Part ' Get the part
Set oPartBody = oPart.MainBody ' Grab the mainbody
oPartBody.Name = "IPN-PO-XXXX-XX" ' Rename Body


Set oDoc = CATIA.ActiveDocument ' Get current document
Set oPart = oDoc.Part ' Get the part
Set oPartBody = oPart.MainBody ' Grab the mainbody
oPartBody.Name = "NIN-ø-XXXX" ' Rename Body


Set oDoc = CATIA.ActiveDocument ' Get current document
Set oPart = oDoc.Part ' Get the part
Set oPartBody = oPart.MainBody ' Grab the mainbody
oPartBody.Name = "FICTATION ' Rename Body"


Set oDoc = CATIA.ActiveDocument ' Get current document
Set oPart = oDoc.Part ' Get the part
Set oPartBody = oPart.MainBody ' Grab the mainbody
oPartBody.Name = "GURAGE" ' Rename Body



strPath = "H:\Zeeshan MOHAMMAD\VBA\Project\ProjetVBA1.catvba"
strModule = "modMain"
strProcedure = "CATMain"


UserForm1.Show 0
MsgBox ("Remplir les Champs")


If UserForm1.TextBox1.Text = "" And _
   UserForm1.TextBox2.Text = "" And _
   UserForm1.TextBox3.Text = "" And _
   UserForm1.TextBox4.Text = "" Then
   

      
Else

End If



End Sub

AND i want to fill bodies name by this interface, i just want to know who can i put what i wrote in the "userbox" to the "bodies proprietes names"

i'm very glad to see that usually you helped me sir !

 
Hi,

See attachment, this is a catvba done very quickly and without being exactly what you want (no checks, no nice interface, no complete renames for what you want, no variables convention for names respected - in other words, if you want a nice program, don't do it like me, I've done just some copy-paste exactly how I've done also the CATScript), just to give you an idea of how many things you have to learn. Try to look here , Mark done a nice example how to use an interface in catvba.

Now you can see the differences and see why your code is not working.

Regards
Fernando

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor