Models
This section describes how to program on the model level using Web.Link.
Overview of Model Objects
Models can be any Creo Parametric file type, including parts, assemblies, drawings, sections, and notebook. The classes in the module pfcModel provide generic access to models, regardless of their type. The available methods enable you to do the following:
•  Access information about a model.
•  Open, copy, rename, and save a model.
Getting a Model Object
Methods and Properties Introduced:
  • pfcFamilyTableRow.CreateInstance()
  • pfcSelection.SelModel
  • pfcBaseSession.GetModel()
  • pfcBaseSession.CurrentModel
  • pfcBaseSession.GetActiveModel()
  • pfcBaseSession.ListModels()
  • pfcBaseSession.GetByRelationId()
  • pfcWindow.Model
  • These methods get a model object that is already in session.
    The property pfcSelection.SelModel returns the model that was interactively selected.
    The method pfcBaseSession.GetModel() returns a model based on its name and type, whereas pfcBaseSession.GetByRelationId() returns a model in an assembly that has the specified integer identifier.
    The property pfcBaseSession.CurrentModel returns the current active model.
    The method pfcBaseSession.GetActiveModel() returns the active Creo Parametric model.
    Use the method pfcBaseSession.ListModels() to return a sequence of all the models in session.
    For more methods that return solid models, refer to the section Solid.
    Model Descriptors
    Methods and Properties Introduced:
  • pfcModelDescriptor.Create()
  • pfcModelDescriptor.CreateFromFileName()
  • pfcModelDescriptor.GenericName
  • pfcModelDescriptor.InstanceName
  • pfcModelDescriptor.Type
  • pfcModelDescriptor.Device
  • pfcModelDescriptor.Path
  • pfcModelDescriptor.FileVersion
  • pfcModelDescriptor.GetFullName()
  • pfcModel.FullName
  • Model descriptors are data objects used to describe a model file and its location in the system. The methods in the model descriptor enable you to set specific information that enables Creo Parametric to find the specific model you want.
    The static utility method pfcModelDescriptor.Create() allows you to specify as data to be entered a model type, an instance name, and a generic name. The model descriptor constructs the full name of the model as a string, as follows:
    String FullName = InstanceName+"<"+GenericName+">"; 
                                        // As long as the
                                        // generic name is
                                        // not an empty 
                                        // string ("")
    If you want to load a model that is not a family table instance, pass an empty string as the generic name argument so that the full name of the model is constructed correctly. If the model is a family table interface, you should specify both the instance and generic names.
    Note
    You are allowed to set other fields in the model descriptor object, but they may be ignored by some methods.
    The static utility method pfcModelDescriptor.CreateFromFileName() allows you to create a new model descriptor from a given a file name. The file name is a string in the form <name>.<extension>.
    Retrieving Models
    Methods Introduced:
  • pfcBaseSession.RetrieveModel()
  • pfcBaseSession.RetrieveModelWithOpts()
  • pfcBaseSession.OpenFile()
  • pfcSolid.HasRetrievalErrors()
  • These methods cause Creo Parametric to retrieve the model that corresponds to the pfcModelDescriptor argument.
    The method pfcBaseSession.RetrieveModel() retrieves the specified model into the Creo Parametric session given its model descriptor from a standard directory. This method ignores the path argument specified in the model descriptor. But this method does not create a window for it, nor does it display the model anywhere.
    The method pfcBaseSession.RetrieveModelWithOpts() retrieves the specified model into the Creo Parametric session based on the path specified by the model descriptor. The path can be a disk path, a workspace path, or a commonspace path. The Opts argument (given by the pfcRetrieveModelOptions object) provides the user with the option to specify simplified representations.
    The method pfcBaseSession.OpenFile() brings the model into memory, opens a new window for it (or uses the base window, if it is empty), and displays the model.
    Note
    pfcBaseSession.OpenFile() actually returns a handle to the window it has created.
    The file version set by the pfcModelDescriptor.FileVersion property is ignored by the pfcBaseSession.RetrieveModelWithOpts() and pfcBaseSession.OpenFile() methods. Instead, the latest file version of the model is used by these two methods.
    To get a handle to the model you need, use the property pfcWindow.Model.
    The method pfcSolid.HasRetrievalErrors() returns a true value if the features in the solid model were suppressed during the RetrieveModel or OpenFile operations. This method must be called immediately after the pfcBaseSession.RetrieveModel() method or an equivalent retrieval method.
    Model Information
    Methods and Properties Introduced:
  • pfcModel.FileName
  • pfcModel.CommonName
  • pfcModel.IsCommonNameModifiable()
  • pfcModel.FullName
  • pfcModel.GenericName
  • pfcModel.InstanceName
  • pfcModel.Origin
  • pfcModel.RelationId
  • pfcModel.Descr
  • pfcModel.Type
  • pfcModel.IsModified
  • pfcModel.Version
  • pfcModel.Revision
  • pfcModel.Branch
  • pfcModel.ReleaseLevel
  • pfcModel.VersionStamp
  • pfcModel.ListDependencies()
  • pfcModel.CleanupDependencies()
  • pfcModel.ListDeclaredModels()
  • pfcModel.CheckIsModifiable()
  • pfcModel.CheckIsSaveAllowed()
  • The property pfcModel.FileName retrieves the model file name in the "name"."type" format.
    The property pfcModel.CommonName retrieves the common name for the model. This name is displayed for the model in Windchill PDMLink.
    Use the method pfcModel.IsCommonNameModifiable() to identify if the common name of the model can be modified. You can modify the name for models that are not yet owned by Windchill PDMLink, or in certain situations if the configuration option let_proe_rename_pdm_objects is set to yes.
    The property pfcModel.FullName retrieves the full name of the model in the instance <generic> format.
    The property pfcModel.GenericName retrieves the name of the generic model. If the model is not an instance, this name must be NULL or an empty string.
    The property pfcModel.InstanceName retrieves the name of the model. If the model is an instance, this method retrieves the instance name.
    The property pfcModel.Origin returns the complete path to the file from which the model was opened. This path can be a location on disk from a Windchill workspace, or from a downloaded URL.
    The property pfcModel.RelationId retrieves the relation identifier of the specified model. It can be NULL.
    The property pfcModel.Descr returns the descriptor for the specified model. Model descriptors can be used to represent models not currently in session.
    Note
    From Pro/ENGINEER Wildfire 4.0 onwards, the properties pfcModel.DescrpfcModel.Descr, pfcModel.Descr, and pfcModel.Descr throw an exception pfcXtoolkitCantOpen if called on a model instance whose immediate generic is not in session. Handle this exception and typecast the model as pfcSolid, which in turn can be typecast as pfcFamilyMember, and use the method pfcFamilyMember.GetImmediateGenericInfo() to get the model descriptor of the immediate generic model. The model descriptor can be used to derive the full name or generic name of the model. If you wish to switch off this behavior and continue to run legacy applications in the pre-Wildfire 4.0 mode, set the configuration option retrieve_instance_dependencies to instance_and_generic_deps.
    The property pfcModel.Type returns the type of model in the form of the pfcModelType object. The types of models are as follows:
    •  MDL_ASSEMBLY—Specifies an assembly.
    •  MDL_PART—Specifies a part.
    •  MDL_DRAWING—Specifies a drawing.
    •  MDL_2D_SECTION—Specifies a 2D section.
    •  MDL_LAYOUT—Specifies a notebook.
    •  MDL_DWG_FORMAT—Specifies a drawing format.
    •  MDL_MFG—Specifies a manufacturing model.
    •  MDL_REPORT—Specifies a report.
    •  MDL_MARKUP—Specifies a drawing markup.
    •  MDL_DIAGRAM—Specifies a diagram
    •  MDL_CE_SOLID—Specifies a Layout model.
    Note
    Web.Link methods will only be able to read models of type Layout, but will not be able to pass Layout models as input to other methods. PTC recommends that you review all Web.Link applications that use the object pfcModelType and modify the code as appropriate to ensure that the applications work correctly.
    The property pfcModel.IsModified identifies whether the model has been modified since it was last saved.
    The property pfcModel.Version returns the version of the specified model from the PDM system. It can be NULL, if not set.
    The property pfcModel.Revision returns the revision number of the specified model from the PDM system. It can be NULL, if not set.
    The property pfcModel.Branch returns the branch of the specified model from the PDM system. It can be NULL, if not set.
    The property pfcModel.ReleaseLevel returns the release level of the specified model from the PDM system. It can be NULL, if not set.
    The property pfcModel.VersionStamp returns the version stamp of the specified model. The version stamp is a Creo Parametric specific identifier that changes with each change made to the model.
    The method pfcModel.ListDependencies() returns a list of the first-level dependencies for the specified model in the Creo Parametric workspace in the form of the pfcDependencies object.
    Use the method pfcModel.CleanupDependencies() to clean the dependencies for an object in the Creo Parametric workspace.
    Note
    Do not call the method pfcModel.CleanupDependencies() during operations that alter the dependencies, such as, restructuring components and creating or redefining features.
    The method pfcModel.ListDeclaredModels() returns a list of all the first-level objects declared for the specified model.
    The method pfcModel.CheckIsModifiable() identifies if a given model can be modified without checking for any subordinate models. This method takes a boolean argument ShowUI that determines whether the Creo Parametric conflict resolution dialog box should be displayed to resolve conflicts, if detected. If this argument is false, then the conflict resolution dialog box is not displayed, and the model can be modified only if there are no conflicts that cannot be overridden, or are resolved by default resolution actions. For a generic model, if ShowUI is true, then all instances of the model are also checked.
    The method pfcModel.CheckIsSaveAllowed() identifies if a given model can be saved along with all of its subordinate models. The subordinate models can be saved based on their modification status and the value of the configuration option save_objects. This method also checks the current user interface context to identify if it is currently safe to save the model. Thus, calling this method at different times might return different results. This method takes a boolean argument ShowUI. Refer to the previous method for more information on this argument.
    Model Operations
    Methods and Property Introduced:
  • pfcModel.Backup()
  • pfcModel.Copy()
  • pfcModel.CopyAndRetrieve()
  • pfcModel.Rename()
  • pfcModel.Save()
  • pfcModel.Erase()
  • pfcModel.EraseWithDependencies()
  • pfcModel.Delete()
  • pfcModel.Display()
  • pfcModel.CommonName
  • These model operations duplicate most of the commands available in the Creo Parametric File menu.
    The method pfcModel.Backup() makes a backup of an object in memory to a disk in a specified directory.
    The method pfcModel.Copy() copies the specified model to another file.
    The method pfcModel.CopyAndRetrieve() copies the model to another name, and retrieves that new model into session.
    The method pfcModel.Rename() renames a specified model.
    The method pfcModel.Save() stores the specified model to a disk.
    The method pfcModel.Erase() erases the specified model from the session. Models used by other models cannot be erased until the models dependent upon them are erased.
    The method pfcModel.EraseWithDependencies() erases the specified model from the session and all the models on which the specified model depends from disk, if the dependencies are not needed by other items in session.
    Note
    However, while erasing an active model, pfcModel.Erase() and pfcModel.EraseWithDependencies() only clear the graphic display immediately, they do not clear the data in the memory until the control returns to Creo Parametric from the Web.Link application. Therefore, after calling them the control must be returned to Creo Parametric before calling any other function, otherwise the behavior of Creo Parametric may be unpredictable.
    The method pfcModel.Delete() removes the specified model from memory and disk.
    The method pfcModel.Display() displays the specified model. You must call this method if you create a new window for a model because the model will not be displayed in the window until you call pfcDisplay.
    The property pfcModel.CommonName modifies the common name of the specified model. You can modify this name for models that are not yet owned by Windchill PDMLink, or in certain situations if the configuration option let_proe_rename_pdm_objects is set to yes.
    Running Creo ModelCHECK
    Creo ModelCHECK is an integrated application that runs transparently within Creo Parametric. Creo ModelCHECK uses a configurable list of company design standards and best modeling practices. You can configure Creo ModelCHECK to run interactively or automatically when you regenerate or save a model.
    Methods and Properties Introduced:
  • pfcBaseSession.ExecuteModelCheck()
  • pfcModelCheckInstructions.Create()
  • pfcModelCheckInstructions.ConfigDir
  • pfcModelCheckInstructions.Mode
  • pfcModelCheckInstructions.OutputDir
  • pfcModelCheckInstructions.ShowInBrowser
  • pfcModelCheckResults.NumberOfErrors
  • pfcModelCheckResults.NumberOfWarnings
  • pfcModelCheckResults.WasModelSaved
  • You can run Creo ModelCHECK from an external application using the method pfcBaseSession.ExecuteModelCheck(). This method takes the model Model on which you want to run Creo ModelCHECK and instructions in the form of the object pfcModelCheckInstructions as its input parameters. This object contains the following parameters:
    •  ConfigDir—Specifies the location of the configuration files. If this parameter is set to NULL, the default Creo ModelCHECK configuration files are used.
    •  Mode—Specifies the mode in which you want to run Creo ModelCHECK. The modes are:
      MODELCHECK_GRAPHICS—Interactive mode
      MODELCHECK_NO_GRAPHICS—Batch mode
    •  OutputDir—Specifies the location for the reports. If you set this parameter to NULL, the default Creo ModelCHECK directory, as per config_init.mc, will be used.
    •  ShowInBrowser—Specifies if the results report should be displayed in the Web browser.
    The method pfcModelCheckInstructions.Create() creates the pfcModelCheckInstructions object containing the Creo ModelCHECK instructions described above.
    Use the methods and properties pfcModelCheckInstructions.ConfigDir, pfcModelCheckInstructions.Mode, pfcModelCheckInstructions.OutputDir, and pfcModelCheckInstructions.ShowInBrowser to modify the Creo ModelCHECK instructions.
    The method pfcBaseSession.ExecuteModelCheck() returns the results of the Creo ModelCHECK run in the form of the pfcModelCheckResults object. This object contains the following parameters:
    •  NumberOfErrors—Specifies the number of errors detected.
    •  NumberOfWarnings—Specifies the number of warnings found.
    •  WasModelSaved—Specifies whether the model is saved with updates.
    Use the properties pfcModelCheckResults.NumberOfErrors, pfcModelCheckResults.NumberOfWarnings, and pfcModelCheckResults.WasModelSaved to access the results obtained.