Continue to Site

Welcome to MCAD Central

Join our MCAD Central community forums, the largest resource for MCAD (Mechanical Computer-Aided Design) professionals, including files, forums, jobs, articles, calendar, and more.

ProE Assembly using J-link

19Pilou81

New member
Hi,


I'm trying to assemble parts automatically using J-link. I found an example code in the ProEngineer User's Guide and tried to compile it. I always had the problem, that the pfc.Globalwhich is imported in this codecould not be found. Now I just read inthis forumthat this package can only be used in synchronus mode.


I don't know much about J-link and synchronus / asynchronus mode so I decided to replace the "pfcasync.jar" I had copied intomy program folderwith the "pfc.jar". Unfortunately I now have moch more errors than before, because all the other imported methods can't be found.


Does anybody know this problem?





Here is the exampe code from the User's Guide:


import com.ptc.cipjava.*;
import com.ptc.pfc.pfcGlobal.pfcGlobal;
import com.ptc.pfc.pfcSession.Session;
import com.ptc.pfc.pfcModel.*;
import com.ptc.pfc.pfcSolid.Solid;
import com.ptc.pfc.pfcFeature.*;
import com.ptc.pfc.pfcComponentFeat.*;
import com.ptc.pfc.pfcFamily.FamilyTableRow;
import com.ptc.pfc.pfcBase.*;
import com.ptc.pfc.pfcSelect.*;
import com.ptc.pfc.pfcModelItem.*;
import com.ptc.pfc.pfcAssembly.*;
public class pfcComponentFeatExamples {

/*========================================================== ===========*\
FUNCTION: UserAssembleByDatums
PURPOSE: Assemble a component by aligning named datums.
\*========================================================== ===========*/
public static void assembleByDatums (String componentFilename )
throws com.ptc.cipjava.jxthrowable
{
boolean interactFlag = false;
Matrix3D identityMatrix = Matrix3D.create ();
for (int x = 0; x < 4; x++)
for (int y = 0; y < 4; y++)
{
if (x == y)
identityMatrix.set (x, y, 1.0);
else
identityMatrix.set (x, y, 0.0);
}
Transform3D transf = pfcBase.Transform3D_Create (identityMatrix);
/*---------------------------------------------------------- -------*\
Get the current assembly
\*---------------------------------------------------------- -------*/
Session session = pfcGlobal.GetProESession ();
Model model = session.GetCurrentModel ();
if (model == null || model.GetType() != ModelType.MDL_ASSEMBLY)
throw new RuntimeException ("Current model is not an
assembly.");

Assembly assembly = (Assembly) model;
ModelDescriptor descr =
pfcModel.ModelDescriptor_CreateFromFileName

(componentFilename);
Solid componentModel = (Solid)session.GetModelFromDescr (descr);
if (componentModel == null)
{
componentModel = (Solid) session.RetrieveModel (descr);
}

/*---------------------------------------------------------- -------*\
Set up the arrays of datum names
\*---------------------------------------------------------- -------*/
String [] asmDatums = {"ASM_D_FRONT", "ASM_D_TOP", "ASM_D_RIGHT"};
String [] compDatums = {"COMP_D_FRONT",
"COMP_D_TOP",
"COMP_D_RIGHT"};
/*---------------------------------------------------------- -------*\
Package the component initially
\*---------------------------------------------------------- -------*/
ComponentFeat asmcomp =
(ComponentFeat) assembly.AssembleComponent (componentModel,
transf);
/*---------------------------------------------------------- -------*\
Prepare the constraints array
\*---------------------------------------------------------- -------*/
ComponentConstraints constrs = ComponentConstraints.create ();
for (int i = 0; i < 3; i++)
{
/*---------------------------------------------------------- -------*\
Find the assembly datum
\*---------------------------------------------------------- -------*/
ModelItem asmItem =
assembly.GetItemByName (ModelItemType.ITEM_SURFACE,
asmDatums );
if (asmItem == null)
{
interactFlag = true;
continue;
}
/*---------------------------------------------------------- -------*\
Find the component datum
\*---------------------------------------------------------- -------*/
ModelItem compItem =
componentModel.GetItemByName (ModelItemType.ITEM_SURFACE,
compDatums );
if (compItem == null)
{
interactFlag = true;
continue;
}

/*---------------------------------------------------------- -------*\
For the assembly reference, initialize a component path.
This is necessary even if the reference geometry is in the assembly.
\*---------------------------------------------------------- -------*/
intseq ids = intseq.create ();
ComponentPath path = pfcAssembly.CreateComponentPath (assembly,
ids);
/*---------------------------------------------------------- -------*\
Allocate the references
\*---------------------------------------------------------- -------*/
Selection asmSel =
pfcSelect.CreateModelItemSelection (asmItem, path);
Selection compSel =
pfcSelect.CreateModelItemSelection (compItem, null);
/*---------------------------------------------------------- -------*\
Allocate and fill the constraint.
\*---------------------------------------------------------- -------*/
ComponentConstraint constr =
pfcComponentFeat.ComponentConstraint_Create

(ComponentConstraintType.ASM_CONSTRAINT_ALIGN);
constr.SetAssemblyReference (asmSel);
constr.SetComponentReference (compSel);
constrs.insert (constrs.getarraysize(), constr);
}
/*---------------------------------------------------------- -------*\
Set the assembly component constraints and regenerate the assembly.
\*---------------------------------------------------------- -------*/
asmcomp.SetConstraints (constrs, null);
assembly.Regenerate (null);
session.GetModelWindow (assembly).Repaint();
/*---------------------------------------------------------- -------*\
If any of the expect datums was not found, prompt the user to constrain
the new component.
\*---------------------------------------------------------- -------*/
if (interactFlag)
{
session.UIDisplayMessage ("jlexamples.txt",
"JLEX Unable to locate all required datum references.
New component is packaged.", null);
asmcomp.RedefineThroughUI();
}
}
}
 

Sponsor

Articles From 3DCAD World

Back
Top