Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Copy, Paste, and Replace Instance

Status
Not open for further replies.

jzecha

Aerospace
Jan 20, 2016
236
Does anybody have a Macro that does anything close to the following:
1.Copy specific part.
2.Paste Special (Break Link).
3.Isolate Pasted Part.
4.Replace Initial Instance of Copied Part with Paste Special Isolated Part.
5.Delete Paste Special Part That is Not Being Used.

For context, I am using this on a customer designed tool I have to add Bolt/Dowel patterns too.
The customer used the same angle in 10+ different locations, I am unable to use the same Bolt/Dowel pattern in all those locations.
So I follow the steps above to create an identical part and change the pattern.

 
Replies continue below

Recommended for you

Hi, i wrote little bit of code for ur problem but i stuck on operation how to isolate part, i cant find solution how to do it?
Is there anyone who knows how to isolate part? I tried with CATIA.command but nothing? Maybe if u have exact elements inside every part, i can isolate that, and it will be the same.

Language="VBSCRIPT"
Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim oSel
Set oSel = productDocument1.Selection
Dim strArray(0)
strArray(0) = "Product"
Dim sStatus As String
sStatus = oSel.SelectElement3(strArray, "Select main part", False, CATMultiSelectionMode.CATMultiSelTriggWhenUserValidatesSelection, False)

Dim CopyPart
Set CopyPart = oSel.item(1).value
Dim copyproduct
Set copyproduct = CopyPart.parent.parent

oSel.Add(CopyPart)
oSel.Copy()
oSel.Clear()
oSel.Add(copyproduct)
oSel.PasteSpecial("CATSpecBreakLink")

CATIA.StartCommand "Isolate"
End Sub
 
jzecha can you send example of one part, i need to see what to copy in new part?
 
With error handling in VB.NET (not vba):

Sub CopyBreakLinkReplace()

If CATIA.GetWorkbenchId = "Drw" Or CATIA.GetWorkbenchId = "DrwBG" Then
MsgBox("Not for drawings. Try again on a model.", , "Error")
Exit Sub
ElseIf CATIA.GetWorkbenchId <> "Assembly" Then
CATIA.StartWorkbench("Assembly")
End If

Dim uSel As INFITF.Selection = CATIA.ActiveDocument.Selection

If uSel.Count = 0 Then
MsgBox("Please select a product to copy and re-run this macro.", , "Error")
Exit Sub
ElseIf uSel.Count > 1 Then
MsgBox("Please select only one product to copy then re-run this macro.", , "Error")
Exit Sub
End If

If TypeName(uSel.Item2(1).Value) <> "Product" Then
MsgBox("Please select a product to copy and re-run this macro.", , "Error")
Exit Sub
End If

uSel.Copy()
Dim selProd As ProductStructureTypeLib.Product = uSel.Item2(1).Value
Dim topProd As ProductStructureTypeLib.Product = selProd.Parent.Parent

uSel.Clear()
uSel.Add(topProd)

uSel.PasteSpecial("CATSpecBreakLink")

Dim newDoc As INFITF.Document = topProd.Products.Item(topProd.Products.Count).ReferenceProduct.Parent
Dim fileType As String = IO.Path.GetExtension(newDoc.FullName)
Dim newDocPath As String = CATIA.ActiveDocument.Path & "\" & newDoc.Product.PartNumber & fileType 'ActiveDocument must already be saved so that new component can be saved there as well.

CATIA.DisplayFileAlerts = False
newDoc.SaveAs(newDocPath)
CATIA.DisplayFileAlerts = True

Dim newProd As ProductStructureTypeLib.Product = topProd.Products.ReplaceComponent(selProd, newDocPath, False)

uSel.Delete()

CATIA.ActiveDocument.Product.Update
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor