Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New part creation

Status
Not open for further replies.

Sebek

Mechanical
Jan 23, 2019
6
0
0
PL
Hello

My code looks something like this i want to do a macro to making a new part in specific location and specific part name and file name i manage to make this macro by recording it in catia. Now i want to have something like a popout table where i can write the location, part name and file name. The popout table i want to be allways in the window. Can somebody help me with this i'm new in catia scripting.
Thanks

Language="VBSCRIPT"

Sub CATMain()

Set productDocument1 = CATIA.ActiveDocument
Set product1 = productDocument1.Product
Set products1 = product1.Products
Set product2 = products1.AddNewComponent("Part", "")

Set documents1 = CATIA.Documents
Set partDocument1 = documents1.Item("Part1.CATPart")
Set product1 = partDocument1.GetItem("Part1")
product1.PartNumber = "RDB-4803-0-00-00-00-00"
product1.Revision = "--"
product1.Definition = "--"
product1.Nomenclature = "Part1"
product1.DescriptionRef = "--"
Set productDocument1 = CATIA.ActiveDocument
Set product2 = productDocument1.Product
Set products1 = product2.Products

Set productDocument1 = CATIA.ActiveDocument
Set documents1 = CATIA.Documents
Set partDocument1 = documents1.Item("Part1.CATPart")
partDocument1.SaveAs "C:\Users\Sebastian\Desktop\product\Part1.CATPart"

End Sub
 
Replies continue below

Recommended for you

Hello
I know that application but i my company we using nameing like this part name RDB-4803-0-01-02-03-04 and in the nomeclature we typing what the part is like sheet of metal or screw. In that aplication i can only type 2 numbers for part name that's why i want to make my new macro to work difrently that that application. I was trying to make something by myself and it's looks like this
A made a table in visual basic

Capture_irymzx.gif



Lokalizacja = Location
Numer = Part Number
Nazwa = Name of the part Nomenclature
Zapis = Is the string to save the part in the location i want

and the code looks like this, is on the button NEW PART

Private Sub CommandButton1_Click()

Dim Lokalizacja As String
Dim Numer As String
Dim Nazwa As String
Dim Zapis As String

Lokalizacja = TextBox1.Text
Numer = TextBox2.Text
Nazwa = TextBox3.Text
Zapis = Lokalizacja + Nazwa + ".CATPart"

Set productDocument1 = CATIA.ActiveDocument
Set product1 = productDocument1.Product
Set products1 = product1.Products
Set documents1 = CATIA.Documents
Set partDocument1 = documents1.Add("Part")
Set partDocument1 = documents1.Item("Part1.CATPart")
Set product1 = partDocument1.GetItem("Part1")
product1.PartNumber = Numer
product1.Revision = "--"
product1.Definition = "--"
product1.Nomenclature = Nazwa
product1.DescriptionRef = "--"
Set partDocument1 = CATIA.ActiveDocument
partDocument1.SaveAs Zapis

End Sub

And ther is the hard part i can't figure out in the same macro i want to paste this new part to active document and don't know how to do it and what some help xd.
 
Hi,
if i got it good, you now want to add this part to the assembly??

Check this macro, it will do that,
It is last step in this code.

Addng part to the main product
ReDim Preserve arrayOfVariantOfBSTR1(0)
arrayOfVariantOfBSTR1(0) = location & "\" & InputBox_row & ".CATPart"
products1.AddComponentsFromFiles arrayOfVariantOfBSTR1, "All"


P.S This & = & some error on page :(
 
Status
Not open for further replies.
Back
Top