Distributive Systems |
Querying Properties and Object ID |
![]() |
This use case is intended to show you how to access properties and ID data using a macro. This macro opens the document CAAPspEduIn.CATProduct. Using the root node of the document, it obtains a physical object. It then gets PspID and PspAttribute interface handle on the physical object to obtain ID and attribute information. |
![]() |
CAAPspQueryProperties is launched in CATIA [1]. No open document is needed. CAAPspQueryProperties.CATScript is located in the CAAScdPspUseCases module. Execute macro (windows only). |
![]() |
CAAPspQueryProperties includes the following steps:
PrologThe macro first loads Distributive System document CAAPspEduIn.CATProduct containing Equipment and Piping Design objects. Note: To open a different document, modify the variable sDocPath to point to the directory and sDocFullPath to point to full path name of the document. ... ' ------------------------------------------------------------------------- ' Open the Distributive system document Dim objPspDoc As Document sDocFullPath = CATIA.FileSystem.ConcatenatePaths(sDocPath, _ "\online\CAAScdPspUseCases\samples\CAAPspEduIn.CATProduct" ) Set objPspDoc = CATIA.Documents.Open(sDocFullPath) ... Next, the macro acquires the PspWorkbench object from the document using the top node of the object tree in a Distributive System document ... ' --------------- ' Find the top node of the Distribute System object tree - . If ( Not ( objPspDoc Is Nothing ) ) Then Set objPrdRoot = objPspDoc.Product If ( Not ( objPrdRoot Is Nothing ) ) Then Set objPspWorkbench = objPrdRoot.GetTechnologicalObject ("PspWorkbench") End If End If ... Next, the macro acquires the PspApplication object corresponding to Piping application and initializes the data. ... If ( Not ( objPspWorkbench Is Nothing ) ) Then Set objPspApplication = objPspWorkbench.GetApplication(catPspIDLCATPiping) If ( Not(objPspApplication Is Nothing ) ) Then objPspApplication.Initialization() End If ... Next, the macro acquires the PspAppFactory object on the application object. ... If ( Not ( objPspWorkbench Is Nothing ) And _ Not ( objPspApplication Is Nothing ) ) Then Set objPspAppFactory = objPspWorkbench.GetInterface("CATIAPspAppFactory",objPspApplication ) ... Get a PspID ObjectUsing the ListPhysicals method of PspAppFactory it obtains a list of physical objects in the Piping domain under the root product. Note that the output of this method is a list of objects. The member of this list can be retrieved using the Item method. The second argument of this method specifies a particular interface to be returned on this object. It then uses the first physical object and obtains a PspID interface handle on the object. ... Set objLPhysicals = objPspAppFactory.ListPhysicals ( objPrdRoot , catPspIDLCATPIP) If ( Not ( objLPhysicals Is Nothing ) And _ ( objLPhysicals.Count > 0 ) ) Then Set objPspPhysical = objLPhysicals.Item( 1, "CATIAPspPhysical" ) End If End If End If '--- If ( Not ( objPspWorkbench Is Nothing ) and objPspApplication '----------------------------------------------------------------------- ' Get PspID object and query ID information '----------------------------------------------------------------------- If ( Not ( objPspWorkbench Is Nothing ) And _ Not ( objPspPhysical Is Nothing ) ) Then Set objPspID = objPspWorkbench.GetInterface("CATIAPspID",objPspPhysical ) ... Query ID InformationIt then calls local Subroutine QueryPspID to query ID information. ... If( Not ( objPspID Is Nothing )) Then QueryPspID objPspID End if ... The PspID interface is used to obtain the following information:
... Private Sub QueryPspID (objPspIDArg As PspID) Dim strID As String Dim str2ID As String Dim strGenIDNoSeq As String Dim strGenAndPutID As String Dim strNewID As String Dim bIsIDGenerated As Boolean strMessage_g = strMessage_g & _ " --------Display ID information ----- " & vbCrLf If ( Not ( objPspIDArg Is Nothing ) ) Then strID = objPspIDArg.GetID strMessage_g = strMessage_g & "Object ID =" & strID & vbCr strNewID = strID & "NewID" objPspIDArg.SetID strNewID str2ID = objPspIDArg.GetID strMessage_g = strMessage_g & "New ID set =" & str2ID & vbCr '---------------------------------------------------------- ' Generate ID without regenerating sequence num '---------------------------------------------------------- strGenIDNoSeq = objPspIDArg.GenIDNoGenSeqNum '---------------------------------------------------------- ' Generate and Put ID on the object '---------------------------------------------------------- strGenAndPutID = objPspIDArg.GenAndPutID strMessage_g = strMessage_g & "Generated ID =" & strGenAndPutID & vbCr '---------------------------------------------------------- ' Is ID generated '---------------------------------------------------------- bIsIDGenerated = objPspIDArg.IsIDGenerated If ( bIsIDGenerated ) Then ... Get a PspAttribute ObjectIt then calls GetInterface method on PspWorkbench on the physical object to get a PspAttribute interface handle. ... If ( Not ( objPspWorkbench Is Nothing ) And _ Not ( objPspPhysical Is Nothing ) ) Then Set objPspAttribute = objPspWorkbench.GetInterface("CATIAPspAttribute",objPspPhysical ) ... Get List of AttributesThe macros calls ListAttributes on the PspAttribute object to get a list of attribute Piping domain. It then calls local private subroutine QueryPspAttribute to query information on each attribute. ... '---------------------------------------------------------------------- ' List Attributes for CATPIP domain '---------------------------------------------------------------------- Set objLStrAttrNames= objPspAttribute.ListAttributes (ePspIDLDomainID ) If ( Not ( objLStrAttrNames Is Nothing ) ) Then intNbAttr = objLStrAttrNames.Count If ( intNbAttr > 0 ) Then QueryPspAttribute objPspWorkbench, objPspAttribute, objLStrAttrNames ... Get Attribute InformationThe macro uses local private subroutine QueryPspAttribute to obtain additional information for each of the attribute
... Private Sub QueryPspAttribute (objPspWorkbenchArg As PspWorkbench, _ objPspAttributeArg As PspAttribute, _ objLStrAttrNamesArg As PspListOfBSTRs ) ... For intIdx = 1 To intNbAttr strAttrName = objLStrAttrNamesArg.Item (intIdx) '----------------------------------------------------- ' Getting type, Discrete, Derived status of the attribute '------------------------------------------------------- eAttrDataType = objPspAttributeArg.GetType (strAttrName) iDiscreteType = objPspAttributeArg.IsDiscrete (strAttrName, bIsDiscrete) bIsDerived = objPspAttributeArg.IsDerived (strAttrName) ... Get Attribute Values Depending on TypesTo get value of each attribute it calls method GetParameter to get CATIAParameter or its derived objects . To get value of an attribute in string format use method ValueAsString method on CATIAParameter object. To get attribute value that could be double integer, or boolean use derived objects like CATIAIntParam, CATIARealParam and CATIABoolParam respectively. ... If ( (eAttrDataType = catPspIDLInteger ) Or _ (eAttrDataType = catPspIDLString ) Or _ (eAttrDataType = catPspIDLBoolean ) ) Then Set objAttrParam = objPspAttributeArg.GetParameter (strAttrName) If ( Not( objAttrParam Is Nothing) ) Then strAttrValue = objAttrParam.ValueAsString ... For real type attribute that have a unit, use GetInterface method of PspWorkbench object on the Parameter object to get a handle on CATIADimension object. It calls property Unit on CATIADimension object to get CATIUnit interface object. ... '------------------------------------------------- ' Handling Real (Double) attribute ' Some attribute could be with magnitude and unit If( (eAttrDataType = catPspIDLDouble ) ) Then Set objAttrRealParam = objPspAttributeArg.GetParameter (strAttrName) If ( Not( objAttrRealParam Is Nothing) ) Then ' ------------------------------------- ' Checking if CATIADimension handle ' can be obtained from Real parameter Set objAttrDimensionParam = objPspWorkbenchArg.GetInterface( _ "CATIADimension",objAttrRealParam ) ... ' --------------------------------------------- ' Getting Unit handler from the Dimension object ' ---------------------------------------------- If ( Not( objAttrDimensionParam Is Nothing) ) Then Set objAttrUnit = objAttrDimensionParam.Unit ... It obtains symbol of the unit used call property Symbol on CATIUnit interface object. ... If ( Not( objAttrUnit Is Nothing) ) Then strMessage_g = strMessage_g & " , unit = " & objAttrUnit.Symbol End If ... |
[Top]
This use case shows how to obtain ID and properties information on a object in an existing document. A message logging the status of the critical steps is displayed at the end of the use case.
[Top]
[1] | Replaying a macro |
[Top] |
Copyright © 2004, Dassault Systèmes. All rights reserved.