Here is your solution in a CATScript
Language = "VBSCRIPT"
Sub CATMain()
'~ 'Done by Ferdo with few code lines "borrowed" and modified from other CATscripts done by CatiaFidelity and Thor Anderson
'~ ''Check if active document is a CATDrawing
'~ ' Attach to Catia
Set CatiaApp = CATIA.Application
On Error Resume Next ' Error Handler in case no file open.
Set CatiaDoc = CatiaApp.ActiveDocument
On Error GoTo 0 ' Error Handler OFF.
' Document is valid
If Not (CatiaDoc Is Nothing) Then
' Get document type
sFileType = TypeName(CatiaDoc)
' Is it a drawing ?
If sFileType = "DrawingDocument" Then
'''''''''''''''''''''''''''''''''''# here you get the name of the CATPart that you want to get the Parameters
Set windowsopen = CATIA.Windows
Dim docTargetPart as PartDocument
for i = 1 to windowsopen.count
docTargetPart = Catia.Windows.item (i). name
Dim response
response = MsgBox ("Is it the CATPart that you want to get the Parameters ? " & Chr(13) & Chr(13) & docTargetPart, vbYESNO)
If response = vbYES THEN
'''''''''''''''''''''''''''''''''''#
'''Delete first any Parameters exist in your active CATDrawing, you can write also some code to check if active document is drawing or not
Dim msg
msg =MsgBox ("Push YES and select the Parameters Collection if you want to delete All Parameters" & Chr(13) & Chr(13) & "If you will push NO, CATScript will add CATPart Parameters to those already existing" & Chr(13) & Chr(13) & "If you want to exit with no action, press first YES then ESC button from your keyboard" & Chr(13) & Chr(13) & "Always look in lower left corner of your CATIA window and read the instructions", vbYESNO)
'~ Case 1 - we delete all parameters
If msg = vbYes Then
Dim MyDoc As CATIADocument
Set MyDoc = CATIA.ActiveDocument
Set MySel = MyDoc.Selection
Dim InputType(0), Status As String
InputType(0) = "AnyObject"
Status = MySel.SelectElement2(InputType, "Select the Parameters Collection if you want to delete All Parameters", False)
If (Status = "Cancel") Then Exit Sub
Dim drawingDocument1 As Document
Set drawingDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = drawingDocument1.Selection
selection1.Delete
'--------------------------------------------------
' FIND PART TO BE USED AS REPLACEMENT
'--------------------------------------------------
' find part document among all documents in CATIA session
Dim docTarget as PartDocument
On Error Resume Next
Set docTarget = CATIA.Documents.Item(docTargetPart)
If (Err.Number<>0) Then
MsgBox "TargetPart.CATPart not loaded! Open it in CATIA first"
Exit Sub
End If
''''Get what CATPart parameters you want, bellow is just an example
nomen = docTarget.GetItem(1).Nomenclature
rev = docTarget.GetItem(1).Revision
prtno = docTarget.GetItem(1).PartNumber
''''Back in CATDrawing, write those parameters
Dim Params As Parameters
Set Params = CATIA.ActiveDocument.Parameters
Dim drw_name As String
Set drw_name = Params.CreateString ("CATDrawing _Name", nomen)
Dim drw_rev As String
Set drw_rev = Params.CreateString ("Revision_Number", rev)
Dim prt_no As String
Set prt_no = Params.CreateString ("Part_Number", prtno)
'~ Case 2 - we don't delete any parameter
Else
If msg = vbNO Then
'--------------------------------------------------
' FIND PART TO BE USED AS REPLACEMENT
'--------------------------------------------------
' find part document among all documents in CATIA session
On Error Resume Next
Set docTarget = CATIA.Documents.Item(docTargetPart)
If (Err.Number<>0) Then
MsgBox "TargetPart.CATPart not loaded! Open it in CATIA first"
Exit Sub
End If
''''Get what CATPart parameters you want
nomen = docTarget.GetItem(1).Nomenclature
rev = docTarget.GetItem(1).Revision
prtno = docTarget.GetItem(1).PartNumber
''''Back in CATDrawing, write those parameters
Set Params = CATIA.ActiveDocument.Parameters
Set drw_name = Params.CreateString ("CATDrawing _Name", nomen)
Set drw_rev = Params.CreateString ("Revision_Number", rev)
Set prt_no = Params.CreateString ("Part_Number", prtno)
End If 'End first case
End If 'End second case
'''''''''''''''''''''''''''''''''''# this belongs to the If cycle where you get the name of the CATPart
Else
End If
Next
'''''''''''''''''''''''''''''''''''#
Else 'Warning about CATIA type document
Message = MsgBox("Sorry, this script works with a CATDrawing as Active document, switch to a CATDrawing", vbCritical, "Error")
Exit Sub 'exit warning if document is not a CATDrawing
End If
End If
End Sub
Regards
Fernando
cadromania.net - Romanian CAD forums