Continue to Site

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!

Script toExport Properties from PRT to Parameters of corresponding DRW

Status
Not open for further replies.

vincentPLM

Computer
Jun 9, 2011
10
Hi all,

I try to make a script to extract properties like "part name" from a PRT to new parameters that i have to make in a DRW.


I know how to create parameters via a script but i need your help to extract and copy data from prt to drw.

Is somebody to help me please?

Thanks
 
You could use Text Templates for this. Have a look in the help docs. Do a search on creating text templates
This will show you how to create, catalog and reuse.


Regards,
Derek
 
Hi,

thank you derek.
However, what does Text Templates mean?
 
First, i would like to know how i can swich active document to PRT from DRW.
Then, once PRT is activated, i would like to scan and keep properties values (drwaing number, revision...) (every time there are the same).
Then switch to DRW, creation of parameters (same as properties of PRT) and filling its with PRT value.

so, it means that properties of PRT drive parameters od DRW

thanks for your help.
 
Yes, it is exactly what i mean.

Extract mapped datas (properties) from PRD or PRT to DRW parameters.

regards
 
Bellow there are few CATScripts which might help if you will "assemble" and modify them.

It would be nice if you will show us the result. Each CATScript has a short explanation (some of them can be found in CATIA Portable Script Center here on forum).

""""""""""""""""
Sub CATMain()

'Read Nomenclature CATPart Properties

nomen = CATIA.ActiveDocument.GetItem(1).Nomenclature
MsgBox nomen

End Sub

"""""""""""""""""""""""""""""""""""""""""""""""""""""""

Sub CATMain ()

'Create Parameters in an active CATIA document

Dim Params As Parameters
'~ Set Params = CATIA.ActiveDocument.Part.Parameters
Set Params = CATIA.ActiveDocument.Parameters
Dim Reell As RealParam
Set Reell = Params.CreateReal ("Pi", 3.14159)
Dim Laenge, Winkel As Dimension
Set Laenge = Params.CreateDimension ("Hoehe", "Length", 200)
Set Winkel = Params.CreateDimension ("Anschluss", "Angle", 100)

End Sub

""""""""""""""""""""""""""""""""""""""""""""""""""""""""

Sub CATMain()

'Create User Defined Properties in CATPart

Dim partDocument1 As PartDocument
Dim part1 As Part
Dim parameters1 As Parameters
Dim product1 As CATBaseDispatch
Dim relations1 As Relations
Dim StrParam1 As Parameter
Dim formula1 As Formula

Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set parameters1 = part1.Parameters
Set relations1 = part1.Relations
Set product1 = partDocument1.GetItem(part1.Name)

Set parameters2 = product1.UserRefProperties
'~ ’Create Userproperties
Set strParam1 = parameters2.CreateString("MyUserProperty", "Hello Guys")
'~ ’Recuperate el UserProperties created before
Set strParam2 = parameters1.Item("Properties\MyUserProperty")

part1.update

End Sub

****************************************************
Option Explicit
' COPYRIGHT DASSAULT SYSTEMES 2001

' *****************************************************************************
' Purpose: Open an Existing Document.
' Assumtions: Looks for CAAInfReadDocument.CATPart
' in the CATDocView
' Author:
' Languages: VBScript
' Locales: English
' CATIA Level: V5R7
' *****************************************************************************

Sub CATMain()

' -----------------------------------------------------------------------------------------------
' Optional: allows to find the sample wherever it may be installed
Dim sDocPath As String
sDocPath=CATIA.SystemService.Environ("CATDocView")
If (Not CATIA.FileSystem.FolderExists(sDocPath)) Then
Err.Raise 9999,,"No Doc Path Defined"
End If
' ------------------------------------------------------------------------------------------------

'Open the document and add it as the last item of the collection of documents.
'Create and display a new window for the document.
'Activate the document and its window.
Dim sFilePath
sFilePath = CATIA.FileSystem.ConcatenatePaths(sDocPath, _
"online\CAAScdInfUseCases\samples\CAAInfReadDocument.CATPart")
Dim iPartDoc As Document
Set iPartDoc = CATIA.Documents.Open(sFilePath)

End Sub

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

Language = "VBSCRIPT"
Sub CATMain ()

'Counts and showing opened documents in CATIA

Set windowsopen = CATIA.Windows
Msgbox (windowsopen.count)

for i = 1 to windowsopen.count
msgbox (Catia.windows.item (i). name)
NEXT

End Sub

"""""""""""""""""""""""""""""""""""""""""""""""""""""""




Regards
Fernando
cadromania.net - Romanian CAD forums
 
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
 
So, is working or not?

Regards
Fernando
cadromania.net - Romanian CAD forums
 
Hey,


Yes it works! However, i think there are a lot of useless pop up.
I ll try to modify code. thanks a lot
 
In fact, i try to test link between DRW and PRT or PRD to get off pop up about "is it the CATPRODY+UCT you want to...."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor