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!

PasteSpecial As Result CATVBA not working

Status
Not open for further replies.

ntweisen

Mechanical
Jul 12, 2010
94
US
Has anyone had any issues with "CATPrtResultWithOutLink" to paste "AsResult" not working? I'm trying to paste a product into a newly created product but nothing gets pasted in. Using "CATPrtCont" to paste "As Specified In Part Document" results in an error.

here is a quick example code:

Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim productDocument1 As Document
Set productDocument1 = documents1.Add("Product")

Dim product1 As Product
Set product1 = productDocument1.Product
product1.PartNumber = "MyNewProduct"


Dim oSel 'As Selection
Set oSel = CATIA.ActiveDocument.Selection

oSel.Add partCol.Item(i)
oSel.Copy

Dim newSel 'As Selection
Set newSel = productDocument1.Selection

newSel.Clear
newSel.Add product1

newSel.PasteSpecial "CATPRTResultwithoutlink"

'newSel.paste
'newSel.PasteSpecial "CATPrtResult"
'newSel.PasteSpecial "CATProdCont"
newSel.Clear
oSel.Clear
 
Replies continue below

Recommended for you

what is partCol.Item(i)?

Eric N.
indocti discant et ament meminisse periti
 
do you add osel.item(x).value to the collection and you have product in your collection or you add osel.item(x) to the collection and you have selectedelement in your collection ?

what is partCol.Item(i)?

Eric N.
indocti discant et ament meminisse periti
 
Here is the full code to show how the parts are selected by a user, added to a collection, then hopefully copied and pasted into a newly created product.

'filter what to select
Dim filter(0)
filter(0) = "Part"

'select the parts
Dim theOldPart As String

Dim partSelection
Set partSelection = CATIA.ActiveDocument.Selection
partSelection.Clear

theOldPart = partSelection.SelectElement2(filter, "Select the Old Part or hit ESC to cancel.", False)

If theOldPart <> "Normal" Then

MsgBox "ERROR: Problem with the selection. Cancelling the program.", vbCritical, "No CATPart Selected."

Exit Sub
Else
End If

'--save the old part in a collection for use later
Dim partCol As Collection
Set partCol = New VBA.Collection

partCol.Add partSelection.Item2(1).Value

'-----------create new product-------
Dim documents1 As Documents
Set documents1 = CATIA.Documents

Dim productDocument1 As Document
Set productDocument1 = documents1.Add("Product")

Dim product1 As Product
Set product1 = productDocument1.Product
product1.PartNumber = "Compare" & VBA.Format(Now(), "yyyymmddHhNnSs")

Dim OldPartData
Set OldPartData = partCol.Item(1)

Dim i As Integer

For i = 1 To partCol.Count

Dim oSel 'As Selection
Set oSel = CATIA.ActiveDocument.Selection

oSel.Add partCol.Item(i)
oSel.Copy

Dim newSel 'As Selection
Set newSel = productDocument1.Selection

newSel.Clear
newSel.Add product1
newSel.PasteSpecial "CATPrtResultWithOutLink"
newSel.Clear
oSel.Clear

Next
 
check chm file about container and PasteSpecial option.

you can't PasteSpecial "CATPrtResultWithOutLink" or PasteSpecial "CATPrtResult" in a product but in a part only.

Eric N.
indocti discant et ament meminisse periti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top