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!

Catia macro PasteAsResult

Status
Not open for further replies.

elmundo777

Automotive
Jun 23, 2020
93
BY
Hi all. Is it possible to use a macro to copy the entire contents of an open active Product and, using a special paste, paste it into a new Part or Product as a result and ONE body/Solid?

I tried to run the following code in two versions:
Code:
         Dim activeDocument As ProductDocument = Catia.ActiveDocument

        Dim rootProduct As Product = activeDocument.Product
       
        Catia.ActiveWindow.ActiveViewer.Reframe()
        Catia.ActiveDocument.Selection.Search("Name=*,all")
      
        Catia.ActiveDocument.Selection.Copy()
      
        Dim newProductDocument As ProductStructureTypeLib.ProductDocument = Catia.Documents.Add("Product")
 
        newProductDocument.Selection.PasteSpecial("CATPrtResultWithOutLink")





Code:
        Dim productDocument As ProductStructureTypeLib.ProductDocument = Catia.ActiveDocument

       
        Dim product As ProductStructureTypeLib.Product = productDocument.Product

        
        Dim selection As INFITF.Selection = Catia.ActiveDocument.Selection

        
        selection.Clear()

      
        For Each product In product.Products
            selection.Add(product)
        Next

      
        selection.Copy()
       
    
        Dim partDocument As PartDocument = Catia.Documents.Add("Part")

       partDocument.Selection.PasteSpecial("CATPrtResultWithOutLink")





but I get the same error:
Code:
System.Runtime.InteropServices.COMException
  HResult=0x80004005
  Message=Empty CSO element. Operation cannot be performed PasteSpecial.

 
Replies continue below

Recommended for you

When I form an allcatpart, it leaves the same amount of tree products
allcatpart1_yndeb8.png
 
in CATAllPart you get the option to create only one body for each part/solid: "Merge all bodies of each part in one body" option

regards,
LWolf
 
Yes, I use this checkbox. But the result remains the same. And if I'm use allcatpart code generation, then nothing changes either
 
Make an allcatpart, then assembly all bodies in main body , copy this catpart in a product and make again an allcatpart.
 
TudorM has the solution. I have fully automated this process in the past but it requires using un-managed code to click the 'OK' button on the CATAllPart dialog, after calling CATIA.StartCommand, since there is no API for running that function (try searching pinvoke for details on this). Once that has been completed you can handle the new part that is has created, combining all of the bodies into one and then copy/paste as result that body to make a single solid. The code I originally wrote replaced the staring sub-product as well.
 
weagan22, there is a method for CATAllpart, WITHOUT running StartCommand...

regards,
LWolf
 
TudorM said:
Make an allcatpart, then assembly all bodies in main body , copy this catpart in a product and make again an allcatpart.

Catia has some cheesy workarounds and solutions but at least it has them. [sub](unlike all my previous cad systems)[/sub]
 
Wuzhee: Definitely cheesy workarounds, but it always does seem to work, somehow.

LWolf, is there an API command that runs 'Generate CATPart from Product'? I have never seen/heard of this in any of the documentation, but I also haven't worked on any new releases beyond R28. If so, what library is it in, out of curiosity? Or are you just taking about manually coding the combine by copying part bodies out of each of the sub-components without running that command at all?
 
weagan22, it is literally in elmundos777 previous thread:
[link thread560-513775]Link[/url]

Dim oBGRoot, oBGProd, sError
Dim oProd2Part As DECPartToPart
Dim oAllCatPart As part
Set oBGRoot = CATIA.ActiveDocument
Set oBGProd = oBGRoot.Product
Set oProd2Part = oBGProd.GetItem("DECPartToPart")
oProd2Part.Run
sError = oProd2Part.GetError
If sError <> "" Then
MsgBox sError, 16, "Exception DECPartToPart. Aborting."
Exit Sub
End If
Set oAllCatPart = oProd2Part.GetResult.part
actually this thread is kind of a duplicate... to that thread

regards,
LWolf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top