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!

Copying multiple axis to a part file

Status
Not open for further replies.

Alan Lowbands

Aerospace
May 17, 2017
274
GB
Hi Gents,
I'm trying to find a way to copy the axis systems from each of the parts in a product and put them in a single part file and rename each with the instance name.
I haven't had a go at any batch macro's yet so any pointer would be a big help.
I'm not even sure this can be done so don't laugh :)

regards
Alan
 
Replies continue below

Recommended for you

Also, is this in VBA or CATScript? I'm getting some red word's and wondering if it's because I'm using VBA. Thanks!

code_r2lbda.gif
 
There are no error trappers, loose checks but it can be easily adjusted.
- It works in my setup (CATVBA, V5R21, Win7 64bits).
- It copies from multiple instances of the same part with respect to relative position within the assembly.
- It goes recursively to all levels of the active Product.

Code:
Dim oProdSelection As Selection
Dim oSkelDoc As PartDocument

Sub CATMain()
    
    Dim oProdDoc As ProductDocument
    Dim oProd As Product

    Set oProdDoc = CATIA.ActiveDocument
    Set oProd = oProdDoc.Product
    Set oProdSelection = oProdDoc.Selection
    oProdSelection.Clear
    
    'modify next line to make sure that this is the Axis Systems skeleton repository
    Set oSkelDoc = oProd.Products.Item("Skel.1").ReferenceProduct.Parent
    
    CATIA.HSOSynchronized = False
    Call ProcessAxisSystems(oProd)
    CATIA.HSOSynchronized = True
End Sub
Sub ProcessAxisSystems(oProd As Product)
    Dim oChildProd As Product
    For Each oChildProd In oProd.Products
        If oChildProd.HasAMasterShapeRepresentation Then
            'it is a part. you can do whatever checks you'd like to make sure that this is a Part indeed.
            'for the next line adjust the condition in order to identify the skeleton itself and
            'to avoid copying-pasting from the same part.
            If oChildProd.ReferenceProduct.PartNumber <> "Skel" Then
                oProdSelection.Clear
                oProdSelection.Add oChildProd
                oProdSelection.Search "(((FreeStyle.'Axis System' + 'Part Design'.'Axis System') + 'Generative Shape Design'.'Axis System') + 'Functional Molded Part'.'Axis System'),sel"
                oProdSelection.Copy
                oProdSelection.Clear
                oProdSelection.Add oSkelDoc.Part
                oProdSelection.PasteSpecial ("CATPrtResult")
                oProdSelection.Clear
                oSkelDoc.Part.Update
                oSkelDoc.Part.AxisSystems.Item(oSkelDoc.Part.AxisSystems.Count).Name = oChildProd.Name
            'Else
                'this is the Skel part
            End If
        Else
            Call ProcessAxisSystems(oChildProd)
        End If
    Next
End Sub
 
Hi Aaron,
It's catscript.
I cant run macros on customer sites so I have to use scripts from a usb :(
 
Well, I just put that code in a CATScript and it ran flawlessly.

Did you try it?

Calin


Oh, sorry, you were talking with Aaron. My bad [bigglasses]
 
cilici,
Don't think you could do bad even if you tried :)
going to have a play with the code you posted. thanks for sharing

alan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top