Question
Web.Link demp "Replacing Components" replies BadContext
- June 10, 2020
- 4 replies
- 2815 views
I am trying Web.Link demo program comes with Creo 2 or Creo 5 at
". . . \Common Files\<DateCode>\weblink\weblinkexamples\html\pfcComponentFeatExamples.html"
I have resolved some trivial problems of PTC's demo program (so works fine on Windows 10 with Creo embedded IE browser). The attachment pfcComponentFeatExamples.zip contains all needed files to reproduce the problem.

The error message is as shown above. I have traced into the source code and I know the error is from this line:
/*--------------------------------------------------------------------*\
Carry out the replacements
\*--------------------------------------------------------------------*/
assembly.ExecuteFeatureOps (replaceOps, null);
But what's wrong with the demo program? that is listed below for your convenience
function replaceBoltsInAssembly ()
{
// var oldInstance = "PHILLIPS7_8";
var oldInstance = "BOLT";
var newInstance = "SLOT7_8";
if (pfcIsMozilla())
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
/*--------------------------------------------------------------------*\
Get the current assembly
\*--------------------------------------------------------------------*/
var session = pfcGetProESession ();
var assembly = session.CurrentModel;
if (assembly.Type != pfcCreate ("pfcModelType").MDL_ASSEMBLY)
throw new Error (0, "Current model is not an assembly");
/*--------------------------------------------------------------------*\
Get the new instance model for use in replacement
\*--------------------------------------------------------------------*/
var bolt = session.GetModel ("BOLT", pfcCreate ("pfcModelType").MDL_PART);
var row = bolt.GetRow (newInstance);
var newBolt = row.CreateInstance();
var replaceOps = pfcCreate ("pfcFeatureOperations");
/*--------------------------------------------------------------------*\
Visit the assembly components
\*--------------------------------------------------------------------*/
var components = assembly.ListFeaturesByType (false,
pfcCreate ("pfcFeatureType").FEATTYPE_COMPONENT);
for (ii = 0; ii < components.Count; ii++)
{
var component = components.Item(ii);
var desc = component.ModelDescr;
if (desc.InstanceName == oldInstance)
{
var replace = component.CreateReplaceOp (newBolt);
replaceOps.Append (replace);
}
}
/*--------------------------------------------------------------------*\
Carry out the replacements
\*--------------------------------------------------------------------*/
assembly.ExecuteFeatureOps (replaceOps, null);
return;
}
